rubymotion-community / sugarcube

Some sugar for your cocoa. RubyMotion helpers.
Other
422 stars 66 forks source link

Rubymotion app using 3rd-party pod crashes in uilabel.rb #172

Closed cotsog closed 9 years ago

cotsog commented 9 years ago

Hi,

I'm a developer from SupportKit (an iOS framework: http://supportkit.io) and one of our client is trying to integrate us along with sugarcube in Rubymotion. Unfortunately, his app crashes. I investigated and it seems like the crash occurs when we do [UiLabel new] but only while being in applicationDidFinishLaunching: in the SupportKit framework. I have a sample project here that reproduces the crash:

https://github.com/cotsog/motionkit

When I change all [UILabel new] in SupportKit for [[UILabel alloc] init] the crash does not happen anymore.

Do you think you can have a look?

Let me know if you need more information.

Thanks!

colinta commented 9 years ago

The obvious candidate is this method:

https://github.com/rubymotion/sugarcube/blob/master/lib/ios/sugarcube-factories/uilabel.rb https://github.com/rubymotion/sugarcube/blob/master/lib/ios/sugarcube-factories/uilabel.rb

I wonder if calling UILabel.new from objc causes an issue. I thought I was writing this in such a way that it would support [UILabel new]. I would first try removing this file from the sugarcube gem, if that fixes it then I'll have to remove it from sugarcube, I don't want it to cause crashes when it's called from objc.

On Oct 29, 2014, at 1:57 PM, Dominic Jodoin notifications@github.com wrote:

Hi,

I'm a developer from SupportKit (an iOS framework: http://supportkit.io http://supportkit.io/) and one of our client is trying to integrate us along with sugarcube in Rubymotion. Unfortunately, his app crashes. I investigated and it seems like the crash occurs when we do [UiLabel new] but only while being in applicationDidFinishLaunching: in the SupportKit framework. I have a sample project here that reproduces the crash:

https://github.com/cotsog/motionkit https://github.com/cotsog/motionkit When I change all [UILabel new] in SupportKit for [[UILabel alloc] init] the crash does not happen anymore.

Do you think you can have a look?

Let me know if you need more information.

Thanks!

— Reply to this email directly or view it on GitHub https://github.com/rubymotion/sugarcube/issues/172.

cotsog commented 9 years ago

Hi @colinta!

Thanks for the quick reply.

I tried using UILabel.new in Objective-C code in SupportKit but got the same crash.

I removed ./ios/sugarcube-factories/uilabel.rb from the gem and it worked.

From what I understand it seems to crash on the super() call on line 8 of uilabel.rb. Here is the call stack I get:

frame #0: 0x00562d80 libobjc.A.dylib`class_getSuperclass + 12
frame #1: 0x002d6908 awstest`rb_objc_convert_immediate + 88
frame #2: 0x001949e6 awstest`vm_ocval_to_rval + 118
frame #3: 0x001977a5 awstest`__unnamed_5 + 69

My client also got a crash on line 21 of uilabel.rb which is a call to sizeToFit:

0 CoreFoundation 0x22482f82 __exceptionPreprocess + 122 
1 libobjc.A.dylib 0x2fff1c72 objc_exception_throw + 34 
2 CoreFoundation 0x22488378 -[NSObject(NSObject) doesNotRecognizeSelector:] + 184 
3 CoreFoundation 0x22486254 ___forwarding___ + 708 
4 CoreFoundation 0x223b7d64 _CF_forwarding_prep_0 + 20 
5 UIKit 0x2590aac0 -[UILabel _textRectForBounds:limitedToNumberOfLines:includingShadow:] + 64 
6 UIKit 0x2590aa68 -[UILabel textRectForBounds:limitedToNumberOfLines:] + 52 
7 UIKit 0x2590a99a -[UILabel _intrinsicSizeWithinSize:] + 138 
8 UIKit 0x2590a8f8 -[UILabel sizeThatFits:] + 28 
9 UIKit 0x2590a7e6 -[UIView(Geometry) sizeToFit] + 122 
10 TradeGecko 0x0020f242 __unnamed_438 + 30 
11 TradeGecko 0x017fa2ca rb_vm_dispatch + 5110 
12 TradeGecko 0x008604e4 vm_dispatch + 704 
13 TradeGecko 0x00867b4c rb_scope__new:__ (uilabel.rb:21) 

Again, I can only repro when I'm in the applicationDidFinishLaunching: selector. Before or after, [UILabel new] works well.

Hope this helps!

Thanks!

colinta commented 9 years ago

Wow that's really strange that it causes that crash, and ONLY in the app delegate. I'll rename this method, though - better to play it safe.

colinta commented 9 years ago

Trying to figure out another way to remedy this problem; I'm not a huge fan of introducing this breaking change...

Instead, can you just remove this offending file from your app.files list?

app.files.delete_if { |f| f.include? 'sugarcube-factories/uilabel.rb' }
otzy007 commented 9 years ago

Hi,

The app is crashing for me too while trying to use sugarcube with RWDropdownMenu. But if I do app.files.delete_if { |f| f.include? 'sugarcube-factories/uilabel.rb' } it's no longer crashing. RWDropDownMenu it's using UILabel.new.

Here's an example app: https://github.com/otzy007/RWDRopDown-sugarcube-bug

colinta commented 9 years ago

OK, well I think it would be appropriate to just remove these new wrappers, they are too volatile. I hate breaking changes, but I think it's appropriate here.

colinta commented 9 years ago

Removed in 3.3.0. I'll email the list about this change! I renamed the methods to UILabel.label and NSError.error. From now on, we'll avoid overwriting new. Thanks!

colinta commented 9 years ago

Shoot, kinda screwed that one up, pushed fixes in 3.3.1 (UILabel.label was calling super() instead of new())

otzy007 commented 9 years ago

Great. Now everything it's fine. Thank you :+1: