take-cheeze / mruby-marshal

mruby implementation of cruby marshaling.
12 stars 9 forks source link

Uncaught exception when using this gem on iOS #20

Closed WaveformDelta closed 7 years ago

WaveformDelta commented 7 years ago

I am using this gem with the ios-embedded-ruby project and including it in the MRubyiOSExample app. However, including this (or any C++ gem) into the project causes a problem with exception handling when I run it on the device. I can cause an unrecoverable crash with code as simple as:

begin
  raise StandardError, "This is an example error"
rescue => ex
  p "Caught error: #{ex.class}, #{ex.message}"
end

On a device, the raise statement will crash with a SIGABRT on the call to MRB_THROW in the mrb_exc_raise() method in the error.c source file with the message:

libc++abi.dylib: terminating with uncaught exception of type int

Additional information

take-cheeze commented 7 years ago

I don't know what version of mruby you are using and full Rakefile that cause this issue, so I can't say much about it. Customization isn't bad though makes things hard to verify so I need more information.

As I see, conf.cxx and conf.linker should be clang++ or -x c++(force compiler to treat source as C++ code) should be added. Add -fexceptions to your C compiler flags. I prefer enable_cxx_exception since most C project aren't for C++ compilers.

WaveformDelta commented 7 years ago

Adding -fexceptions was the piece I was missing: with that added, all code now works as expected.

I created a Gist with my modified Rakefile; I included the -x c++ argument to clang even though I found in testing I don't need it. For now, I'm not using the enable_cxx_exception.

I accept this issue as closed. Thank you for your help!!

take-cheeze commented 7 years ago

@WaveformDelta Glad to hear you solved it!