Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
k3oirj2 opened this issue Dec 4, 2018 · 4 comments

Comments

@k3oirj2
Copy link

k3oirj2 commented Dec 4, 2018

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 k3oirj2 changed the title Wired!!! app will crash, .track() attribute will crash in the situation when i call CFDictionaryGetValue for CTRun's runAttribute about kCTKernAttributedName Wired!!! .track() attribute will lead app to crash in the situation when i call CFDictionaryGetValue for CTRun's runAttribute about kCTKernAttributedName Dec 4, 2018
@ZevEisenberg
Copy link
Collaborator

@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
Copy link
Collaborator

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.

@LevineKwok
Copy link

@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.

@ZevEisenberg
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants