Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6101865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:32:55+00:00 2026-05-23T13:32:55+00:00

I have been using MacRuby and running through the book MacRuby:The Definitive Guide by

  • 0

I have been using MacRuby and running through the book MacRuby:The Definitive Guide by Matt Aimonetti.

On the Movies CoreData app example, I’ve got this code:

def add_image(sender)
    movie = movies.selectedObjects.lastObject
    return unless movie
    image_panel = NSOpenPanel.openPanel
    image_panel.canChooseDirectories = false
    image_panel.canCreateDirectories = false
    image_panel.allowsMultipleSelection = false

    image_panel.beginSheetModalForWindow(sender.window, completionHandler: Proc.new{|result|
        return if (result == NSCancelButton)
        path = image_panel.filename
        # use a GUID to avoid conflicts
        guid = NSProcessInfo.processInfo.globallyUniqueString
        # set the destination path in the support folder
        dest_path = applicationFilesDirectory.URLByAppendingPathComponent(guid)
        dest_path = dest_path.relativePath
        error = Pointer.new(:id)
        NSFileManager.defaultManager.copyItemAtPath(path, toPath:dest_path, error:error)
        NSApplication.sharedApplication.presentError(error[0]) if error[0]
        movie.setValue(dest_path, forKey:"imagePath")
    })
end

The app loads fine and runs without issue – I can create new movies in CoreData and delete them, etc. However, when I click the button which calls this function it opens the dialog window fine, but either the “cancel” or “open file” buttons cause a crash here:

#import <Cocoa/Cocoa.h>

#import <MacRuby/MacRuby.h>

int main(int argc, char *argv[])
{
    return macruby_main("rb_main.rb", argc, argv); << Thread 1: Program received signal EXC_BAD_ACCESS
}

Any help is appreciated. I thought it had something to do with BridgeSupport but either embedding isn’t working or my attempts to do so aren’t working. Either way, something else seems borked as the example provided with the book also crashes.

Thanks!

ADDED NOTE:

I went and tested out this code from macruby.org and it worked fine:

def browse(sender)
  # Create the File Open Dialog class.
  dialog = NSOpenPanel.openPanel
  # Disable the selection of files in the dialog.
  dialog.canChooseFiles = false
  # Enable the selection of directories in the dialog.
  dialog.canChooseDirectories = true
  # Disable the selection of multiple items in the dialog.
  dialog.allowsMultipleSelection = false

  # Display the dialog and process the selected folder
  if dialog.runModalForDirectory(nil, file:nil) == NSOKButton
  # if we had a allowed for the selection of multiple items
  # we would have want to loop through the selection
    destination_path.stringValue = dialog.filenames.first
  end
end

Seems either something is borked in the beginSheetModalForWindow call or I’m missing something, trying to track down what. I can make my modal dialog for file selection work with the above code, but it isn’t a sheet attached to the window.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T13:32:56+00:00Added an answer on May 23, 2026 at 1:32 pm

    NSOpenPanel is a subclass of NSSavePanel so you can use NSSavePanel’s beginSheetModalForWindow:completionHandler:. It is runModalForDirectory that is depreciated. However, “depreciated” doesn’t mean, “doesn’t work” it means “will stop working in the future.”

    The error you are getting is pointing to the C code that loads MacRuby itself. This indicates a severe crash that MacRuby could not trap. It just shows in Main.m because that is the only place the debugger manages to trap the stack in which the error occurred. Unfortunately, locating the error at the very top/bottom of the stack like this makes it useless for debugging.

    I don’t see any obvious problem with Matt Aimonetti’s code so I’m going to guess it’s a problem with MacRuby handling the block that is passed for the completion handler. That would also explain why the error is not trapped because the block will be in a different address space than the object that defines it.

    I would suggest contacting Matt Aimonetti directly via either the book site or the MacRuby mailing list (he’s very active there.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have been using a simple CSS only tooltip. Working Example css: .tip { position:relative;
We have been using BinarySerialization with our C# app, but the size and complexity
I have been using the Learning Java 2nd Edtion book to try make my
I have been using phonegap.js with jqm to built a mobile android app. I
We have been using CruiseControl for quite a while with NUnit and NAnt. For
I have been using PHP and JavaScript for building my dad's website. He wants
I have been using Eclipse as an IDE for a short amount of time
I have been using Castle MonoRail for the last two years, but in a
We have been using Scrum for around 9 months and it has largely been
I have been using C# for a while now, and going back to C++

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.