Closed christophercotton closed 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?
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.
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! :)
sizeof() returns 24 and the actual number of settings is 2.