tobihagemann / THLabel

UILabel subclass, which additionally allows shadow blur, inner shadow, stroke text and fill gradient.
https://tobiha.de
Other
665 stars 111 forks source link

Fix memory related crash. #6

Closed christophercotton closed 10 years ago

christophercotton commented 10 years ago

sizeof() returns 24 and the actual number of settings is 2.

tobihagemann commented 10 years ago

Are you sure? https://developer.apple.com/library/ios/documentation/Carbon/Reference/CTParagraphStyleRef/Reference/reference.html

The second parameter is "settingCount: The number of settings that you have specified in the settings parameter.", so "2" is actually correct. Do you really have a memory related crash? How can I reproduce it?

christophercotton commented 10 years ago

The change I made makes the parameter have the value 2. The current code uses sizeof() which returns the incorrect value of 24. You can see this if you run the code:

CTParagraphStyleSetting paragraphStyleSettings[] = {
    {kCTParagraphStyleSpecifierAlignment, sizeof(CTTextAlignment), &alignment},
    {kCTParagraphStyleSpecifierLineBreakMode, sizeof(CTLineBreakMode), &lineBreakMode}
};

NSUInteger size = sizeof(paragraphStyleSettings);
NSLog(@"Incorrect size: %u", size);

It definitely crashes, but since it is a strange memory related crash I don't have a reproducible case. It happened often enough that we were able to track it down to this call. The value definitely should be 2 and not 24 though.

tobihagemann commented 10 years ago

Oh, wow! My mistake! I thought I used the number "2", because I had that in an early implementation. But that's what you've corrected, haha! :D Thanks for the fix! :)