Last Updated: February 25, 2016
·
921
· tmilewski

BubbleWrap::HTTP randomly crashes with KERN_INVALID_ADDRESS

I was running into an issue where, every-so-often, BubbleWrap::HTTP would fail with the following error message:

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0xc07eac99

Here's an extremely stripped-down example of the code that I was using:

api = Foo::Apps.new
api.list do |apps|
  # Use apps result
end

module Foo
  class Apps
    # ...

    def list(&block)
      BW::HTTP.get('http://bar.com/apps') do |response|
        if response.ok?
          json = BW::JSON.parse(response.body.to_s)
          block.call(json)
        else
          App.alert 'An error has occurred.'
        end
      end
    end

    # ...
  end
end

The error would occur at the BW::HTTP.get() call and, as it turns out, this is an issue with RubyMotion itself.

The fix is simple:

Convert the assigned objects to @instance_variables as the way RubyMotion currently works you sometimes need to do this in order to retain the callbacks.

@api = Foo::Apps.new
@api.list do |apps|
  # Use apps result
end

GH Issue
BW Docs