BonMot icon indicating copy to clipboard operation
BonMot copied to clipboard

Wired!!! .track() attribute will lead app to crash in the situation when i call CFDictionaryGetValue for CTRun's runAttribute about kCTKernAttributedName

Open k3oirj2 opened this issue 6 years ago • 4 comments

Develope Enviroment: XCode 10.1 Mac: 10.14.1

// fail situation

let quote = "『In this situation app will crash, the console report: p_kern_val is null pointer』"
let baseStyle = StringStyle(.font(UIFont.systemFont(ofSize: 25)),
									.lineSpacing(15),
									.lineBreakMode(.byCharWrapping),
									.alignment(.natural))
let quoteStyle = baseStyle.byAdding(.tracking(.point(20)))	
let attrStr = quote.styled(with: quoteStyle)

// success situation

let quote = "『In this situation, i can get the right kern value』"
let baseStyle = StringStyle(.font(UIFont.systemFont(ofSize: 25)),
									.lineSpacing(15),
									.lineBreakMode(.byCharWrapping),
									.alignment(.natural))

let mStr = NSMutableAttributedString.init(attributedString: str)
mStr.addAttribute(.kern, value: 20, range: NSMakeRange(0, str.length))

// get kern value

let ctRunAttrs = CTRunGetAttributes(ctRun)
let p_kern_key = Unmanaged.passUnretained(kCTKernAttributeName).toOpaque()
let p_kern_val = CFDictionaryGetValue(ctRunAttrs, p_kern_key)
let p_kern = Unmanaged<CFNumber>.fromOpaque(p_kern_val!).takeUnretainedValue()
var kern: CGFloat = 0
CFNumberGetValue(p_kern, .cgFloatType, &kern)

k3oirj2 avatar Dec 04 '18 09:12 k3oirj2

@k3oirj2 thanks for this report! Your "success situation" code doesn't compile. There is no variable called str defined. Would you mind updating the code sample so I can reproduce the non-crashing case? And could you please also provide the value for ctRun that you're using?

ZevEisenberg avatar Dec 04 '18 22:12 ZevEisenberg

Actually, I'm not that familiar with Core Text. If you could provide a Playground or unit test case that demonstrates the crash, it would help me a ton with debugging this.

ZevEisenberg avatar Dec 04 '18 22:12 ZevEisenberg

@ZevEisenberg Thanks for your reply, @k3oirj2 is my another account, and i don't use it anymore. I will update my core text sample code into my repository. and i will inform you. thanks for your reply again.

LevineKwok avatar Dec 10 '18 09:12 LevineKwok

@LevineKwok 👋 were you ever able to reproduce this with code you can share?

ZevEisenberg avatar May 30 '19 21:05 ZevEisenberg