Skip to content

Instantly share code, notes, and snippets.

@christos
Created June 15, 2012 13:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christos/2936457 to your computer and use it in GitHub Desktop.
Save christos/2936457 to your computer and use it in GitHub Desktop.
RubyMotion runtime freeze on syntax error in an `each` block, when called from a callback

Hello everyone,

I've already asked on IRC and no one seemed to have an idea why the following is happening:

I can consistently get the RubyMotion runtime and the device to freeze when running this simple code (https://gist.github.com/2936457) with rake device and then hitting the Cancel button on the UIImagePicker. I am guessing this is related to callbacks in general, but I couldn't come up with a simpler example.

As you can see, the UIImagePicker callback method simply uses each to iterate over an array of strings, but as soon as it hits the syntax error on line 28 (putd) it stops. No exception in the logs, nothing. The process has to be killed to exit it.

Any ideas? Am I supposed to release/retain something? I know blocks are a bit tricky but I can't figure out what could possibly be causing the freeze, even if it was a NULL pointer or a missing reference

class AppDelegate
def application(application, didFinishLaunchingWithOptions:launchOptions)
@window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
@window.rootViewController = UINavigationController.alloc.initWithRootViewController(HelloViewController.alloc.init)
@window.rootViewController.wantsFullScreenLayout = true
@window.makeKeyAndVisible
true
end
end
class HelloViewController < UIViewController
def loadView
self.view = UIView.alloc.init
end
def viewDidLoad
imagePicker = UIImagePickerController.alloc.init
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary
imagePicker.delegate = self
presentViewController(imagePicker, animated:true, completion:nil)
end
def imagePickerControllerDidCancel(picker)
puts "imagePickerControllerDidCancel #{picker.inspect}"
['item1','item2'].each do |item|
puts "item is #{item}"
putd "This line will throw a syntax error, as expected"
puts "This line is never reached (nor does the application exit)"
end
picker.presentingViewController.dismissModalViewControllerAnimated(true)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment