Top Shelf Extension Runs on Simulator is Killed on Device

I am currently building a top-shelf extension that pulls information from an API, including 1720x720 sized images and then needs to manipulate the images via core graphics to draw text on them, before storing the image in the caches directory and passing that image to the TVContentItem as the image URL. This all works beautifully on the simulator and everything runs fine. Unfortunately, when I run on the device I get a force close of "Program ended with exit code: 0".


It appears that the kill is done in the middle of my code that's resizing my images, but from the memory profiler I only see my extension take around 5-6 MB and a previous thread indicated that extensions should be alllowed 16MB. I am also serializing the image downloads so I should only be pulling and manipulating one at a time. I didn't see anyting in the tvOS device log that indicated why the extension was killed.


Are there any limitations here that I am unaware of or other things that I could try in this case?


Thanks!

To add some additional information here. It is most definitely occuring on the image.drawInRect call. All of the rest of my CG calls including filling rects / drawing custom strings works fine. It's only that one line being there that causes the system to exit. Unfortunately that's the important line in the context of the carousel as the image is the primary portion. The image I'm trying to draw is only 396KB and like I said works fine on the simulator.


Are there any more efficient ways of drawing the image? RIght now my draw calls are


1. UIGraphicsBeginImageContextWithOptions(topShelfImageSize, true, UIScreen.mainScreen().scale)

2. Fill gray rect with CGContextSetFillColorWithColor and CGContextFillRect

3. Draw image with image.drawInRect()

4. Change fill color and draw some text with NSString.drawInRect

5. Get image with UIGraphicsGetImageFromCurrentImageContext

We are having the same issues on our app. We are also trying to dynamically render an image - similar to the approach above.


Our approach also works on the simulator but crashes with "Program ended with exit code: 0" right when we try to drawInRect(). We've also trying to fallback to the CGContextDrawImage() method using the underlying CGImage, but we get the same result.


Any updates on this?

I had this issue too the key for me was to free up memory along the way by using an autoreleasepool.


See this discussion


https://forums.developer.apple.com/message/162839#162839


In Swift


autoreleasepool {


UIGraphicsBeginImageContext(shapeSize)

// .. more code as needed

UIGraphicsGetImageFromCurrentImageContext()


}


For Objective-C


@autoreleasepool {

// code

}

Top Shelf Extension Runs on Simulator is Killed on Device
 
 
Q