1

I draw some image in background. Sometimes my app crashes with strange error:

function signature specialization < Arg[0] = Owned To Guaranteed> of MyApp.

I checked all crashes, and I get all of them on methods that do not use context. One of them draw text. How can I specify context to draw text?

UIGraphicsBeginImageContextWithOptions(size, false, 1.0)
let ctx = UIGraphicsGetCurrentContext()
// some code
str.drawInRect(CGRectMake(floor(10 * scaleFactor), yOffset, size.width, floor(60 * scaleFactor)), withAttributes: textFontAttributes)
// code
let img = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()

Edit

I do not found any method to draw text in specific context. I use UIGraphicsPushContext(ctx) before draw text and UIGraphicsPopContext() after. https://stackoverflow.com/a/10402637/820795

Community
  • 1
  • 1
Gralex
  • 4,285
  • 7
  • 26
  • 47
  • 1
    Do you use this drawing algorithm in background (thread other than main thread )? – Sandeep Jun 30 '15 at 14:19
  • @GeneratorOfOne Yes. It works in background. And I expect that system generate own context while I drawing on it. So when new context created it push in stack. I think I can use `UIGraphicsPushContext`, but anyway no guaranty that it not crash. Also it can crash before I use pop context. So it will be great to draw text in specific context. – Gralex Jun 30 '15 at 14:22
  • @GeneratorOfOne why? Documentation says that "This function may be called from any thread of your app." – Azat Jun 30 '15 at 14:28
  • Ok yeah it seems like you can call it from aby thread. So, what is the error or crash log that you get ? – Sandeep Jun 30 '15 at 14:30
  • This is `CGContext`. `CGBItmapContext` subtype of `CGContext` as I know. – Gralex Jun 30 '15 at 14:36
  • I do not have normal logs with Swift :( You can see in question the only error that I get. Other info does not have any sense. – Gralex Jun 30 '15 at 14:38
  • Drawing in a background thread is thread-safe. But that doesn't mean that _your_ code is thread-safe. You are saying things like `str.drawInRect(CGRectMake(floor(10 * scaleFactor), yOffset, size.width, floor(60 * scaleFactor)), withAttributes: textFontAttributes)`. How do we know that you have obtained those variables in a thread-safe way? – matt Jun 30 '15 at 15:00
  • @matt this is local variables – Gralex Jun 30 '15 at 15:04

1 Answers1

1

I'm not convinced that this has anything to do with drawing. The "function signature specialization" arises when there's a mistake in the Swift APIs where Objective-C needs to pass a nil parameter value to Swift, but the Swift version of this parameter is not typed as an Optional.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • This error happens really seldom. I can't get it on my device, I only see crashes in Crashlytics. – Gralex Jun 30 '15 at 15:08
  • I didn't say it happened often, I said that this was the sort of thing that caused it. – matt Jun 30 '15 at 15:46
  • @matt I'm curious where you read that information about "function signature specialization." Is that documented somewhere in the Swift library docs? Maybe part of llvm? I can't seem to find anything about it. – JAL Jul 29 '15 at 21:04
  • @JAL Could alternatively be a threading issue, not sure. Solution might be to surround everything with a GCD block so can't run simultaneously on two thread. – matt Jul 29 '15 at 21:17
  • @matt Sorry, I wasn't clear. Unrelated to the question, how did you know that "'function signature specialization' arises when there's a mistake in the Swift APIs where Objective-C needs to pass a nil parameter value to Swift, but the Swift version of this parameter is not typed as an Optional." – JAL Jul 29 '15 at 21:21