質問

I have a Cocos2D project that does a lot of data loading via ASIHTTPRequest. The request often has a completion block attached, which could trigger Cocos2D to do something like load up a texture for displaying a game element.

My problem is that it seems the completion block can be called when the application is moved to the background. That triggers an OpenGL call resulting in application termination with the error: gpus_ReturnNotPermittedKillClient

The Cocos2D director is being told to pause and stopAnimation before moving to the background. So it seems that those functions have no effect on a block that is yet to run (I wouldn't expect it to), nor does this seem to prevent calls to other Cocos2D functions, like [CCRenderTexture renderTextureWitWidth:andHeight:] to load up a texture.

Given this situation, is there a recommended way to safely pause a game as described?

役に立ちましたか?

解決

What you need to do is to prevent any calls that use the OpenGL context while the app is in the background, because during that time there simply is no OpenGL context.

What you could do is to store the current background state (yes or no) and if the game is in the background while an async block runs, the block should instead queue itself to a "Post-Background-Scheduler" class which will then run the block again and dequeue it when the game comes back to the foreground.

Or, if this is only concerning textures, you could simply add each texture to an array and queue them for caching. Then when the game goes into background the queue simply stops dequeuing and resumes dequeuing when the game is in the foreground.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top