Skip to content

Commit bfffb31

Browse files
committed
Ensured that suspend/resume correctly handles the re-creation of a surface.
1 parent 485e6f1 commit bfffb31

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

cocos2d/Platforms/Android/CCActivity.m

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,8 @@ - (void)startGL:(JavaObject<AndroidSurfaceHolder> *)holder
226226

227227
_gameLoop = [NSRunLoop currentRunLoop];
228228

229+
[_gameLoop addPort:[NSPort port] forMode:NSDefaultRunLoopMode]; // Ensure that _gameLoop always has a source.
230+
229231
[self setupView:holder];
230232

231233
[self setupPaths];
@@ -310,12 +312,17 @@ - (void)surfaceCreated:(JavaObject<AndroidSurfaceHolder> *)holder
310312
- (void)surfaceDestroyed:(JavaObject<AndroidSurfaceHolder> *)holder
311313
{
312314
#if USE_MAIN_THREAD
313-
[self finish];
315+
[self handleDestroy];
314316
#else
315-
[self performSelector:@selector(finish) onThread:_thread withObject:nil waitUntilDone:NO modes:@[NSDefaultRunLoopMode]];
317+
[self performSelector:@selector(handleDestroy) onThread:_thread withObject:nil waitUntilDone:NO modes:@[NSDefaultRunLoopMode]];
316318
#endif
317319
}
318320

321+
- (void)handleDestroy
322+
{
323+
[[CCDirector sharedDirector] stopAnimation];
324+
}
325+
319326
- (BOOL)onKeyDown:(int32_t)keyCode keyEvent:(AndroidKeyEvent *)event
320327
{
321328
return NO;

cocos2d/Platforms/Android/CCGLView.m

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -491,10 +491,14 @@ - (BOOL)setupView:(ANativeWindow*)window
491491

492492
if(eglGetError() != EGL_SUCCESS) { NSLog(@"EGL ERROR: %i", eglGetError()); };
493493

494-
if(!(_eglContext = eglCreateContext(_eglDisplay, _eglConfiguration, 0, contextAttribs)))
494+
if(_eglContext == nil)
495495
{
496-
NSLog(@"eglCreateContext() returned error %d", eglGetError());
497-
return NO;
496+
if(!(_eglContext = eglCreateContext(_eglDisplay, _eglConfiguration, 0, contextAttribs)))
497+
{
498+
NSLog(@"eglCreateContext() returned error %d", eglGetError());
499+
return NO;
500+
501+
}
498502
}
499503

500504
if(eglGetError() != EGL_SUCCESS) { NSLog(@"EGL ERROR: %i", eglGetError()); };

0 commit comments

Comments
 (0)