[MacRuby-devel] NSInvocationOperation usage Segmentation fault

Mateus Armando seanlilmateus at googlemail.com
Tue Oct 11 11:03:12 PDT 2011


Hi Alex, this works for me!

1. Alternativ
framework 'Foundation'

class Foo
  def bar
    puts "hallo"
  end
end

queue = NSOperationQueue.alloc.init
#queue.addOperation operation
queue.addOperationWithBlock ->{
   Foo.new.bar
} 
NSRunLoop.currentRunLoop.runUntilDate(NSDate.dateWithTimeIntervalSinceNow(2.0))
_____________________________________________________________________
2. Alternativ
class Foo < NSOperation
  def main
    p :hallo
  end
end

queue = NSOperationQueue.alloc.init
operation = Foo.new
queue.addOperation operation

NSRunLoop.currentRunLoop.runUntilDate(NSDate.dateWithTimeIntervalSinceNow(2.0))
_____________________________________________________________________
3. Alternativ
framework 'Foundation'

class Foo
  def bar
    p :hallo
  end
end

queue = NSOperationQueue.alloc.init
operation = NSInvocationOperation.alloc.initWithTarget Foo.new, selector: :bar, object: nil
queue.addOperation operation

NSRunLoop.currentRunLoop.runUntilDate(NSDate.dateWithTimeIntervalSinceNow(2.0))


Mateus

> The following code crashes with a segmentation fault.
> Any idea whether I misunderstood the usage or it is a macruby bug?
> 
> thanks,
> ALex.
> 
> ---code-------------------------------------------
> framework 'Foundation'
> 
> class Foo
>   def bar
>     puts 'bar'
>   end
> end
> 
> operation = NSInvocationOperation.alloc.initWithTarget Foo.new, selector:
> 'bar', object: nil
> 
> queue = NSOperationQueue.alloc.init
> queue.addOperation(operation)
> 
> # run the main loop for 2 seconds
> NSRunLoop.currentRunLoop.runUntilDate(NSDate.dateWithTimeIntervalSinceNow(2.0))


More information about the MacRuby-devel mailing list