Explorar o código

Fixes crash on hitting esc on Mac OS X

- Adds a 'signalShutdown' to the platform object so that the OS X
platform has an oppertunity to stop rendering which potentially occurs on a seperate thread.
- Schedules terminate in mac os x on a call to the signal shutdown (emphasis on schedules)
Brandon Slack %!s(int64=13) %!d(string=hai) anos
pai
achega
a58358f42e

+ 1 - 0
gameplay/src/Game.cpp

@@ -116,6 +116,7 @@ void Game::shutdown()
     // Call user finalization.
     if (_state != UNINITIALIZED)
     {
+        Platform::signalShutdown();
         finalize();
 
         _animationController->finalize();

+ 7 - 0
gameplay/src/Platform.h

@@ -40,6 +40,13 @@ public:
      */
     int enterMessagePump();
     
+    /**
+     * This method informs the platform that the game is shutting down 
+     * and anything platform specific should be shutdown as well or halted
+     * This function is called automatically when the game shutdown function is called
+     */
+    static void signalShutdown();
+    
     /**
      * Gets the display width.
      * 

+ 5 - 0
gameplay/src/PlatformAndroid.cpp

@@ -766,6 +766,11 @@ int Platform::enterMessagePump()
         gameplay::displayKeyboard(__state, __displayKeyboard);
     }
 }
+
+void Platform::signalShutdown() 
+{
+    // nothing to do  
+}
    
 unsigned int Platform::getDisplayWidth()
 {

+ 20 - 0
gameplay/src/PlatformMacOS.mm

@@ -182,6 +182,17 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTime
     [super dealloc];
 }
 
+- (void)resumeDisplayRenderer {
+    [lock lock];
+    CVDisplayLinkStop(displayLink);
+    [lock unlock]; 
+}
+
+- (void)haltDisplayRenderer {
+    [lock lock];
+    CVDisplayLinkStop(displayLink);
+    [lock unlock];
+}
 
 - (void) mouse: (Mouse::MouseEvent) mouseEvent orTouchEvent: (Touch::TouchEvent) touchEvent atX: (int) x y: (int) y s: (int) s 
 {
@@ -627,6 +638,15 @@ int Platform::enterMessagePump()
     return EXIT_SUCCESS;
 }
 
+void Platform::signalShutdown() {
+    [__view haltDisplayRenderer];
+
+    // Don't perform terminate right away, enqueue to give game object
+    // a chance to cleanup
+    NSApplication* app = [NSApplication sharedApplication];
+    [app performSelectorOnMainThread:@selector(terminate:) withObject:nil waitUntilDone:NO];
+}
+    
 unsigned int Platform::getDisplayWidth()
 {
     return WINDOW_WIDTH;

+ 5 - 0
gameplay/src/PlatformQNX.cpp

@@ -1003,6 +1003,11 @@ int Platform::enterMessagePump()
     return 0;
 }
     
+void Platform::signalShutdown() 
+{
+    // nothing to do  
+}
+    
 unsigned int Platform::getDisplayWidth()
 {
     return __screenWindowSize[0];

+ 5 - 0
gameplay/src/PlatformWin32.cpp

@@ -602,6 +602,11 @@ int Platform::enterMessagePump()
     return msg.wParam;
 }
 
+void Platform::signalShutdown() 
+{
+    // nothing to do  
+}
+
 unsigned int Platform::getDisplayWidth()
 {
     return WINDOW_WIDTH;

+ 10 - 3
gameplay/src/PlatformiOS.mm

@@ -790,6 +790,13 @@ int Platform::enterMessagePump()
     return EXIT_SUCCESS;
 }
     
+void Platform::signalShutdown() {
+    // Cannot 'exit' an iOS Application
+    assert(false);
+    [__view stopUpdating];
+    exit(0);
+}
+    
 unsigned int Platform::getDisplayWidth()
 {
     return WINDOW_WIDTH;
@@ -856,9 +863,9 @@ void Platform::displayKeyboard(bool display)
     }
 }
 
-void Platform::sleep(long ms)
-{
-    usleep(ms * 1000);
+void Platform::sleep(long ms)
+{
+    usleep(ms * 1000);
 }
     
 }