Remove RenderThread::mSurface pointer before mWindow.Reset() 40/44940/6
authorPaul Wisbey <p.wisbey@samsung.com>
Wed, 29 Jul 2015 17:18:34 +0000 (18:18 +0100)
committerPaul Wisbey <p.wisbey@samsung.com>
Thu, 30 Jul 2015 09:25:06 +0000 (02:25 -0700)
+ more pointer validity checks in render-thread
+ remove unused bool in Application

Change-Id: Ica6a713bb91519d2d03025883135d4018e90640f

adaptors/base/render-thread.cpp
adaptors/common/application-impl.cpp
adaptors/common/application-impl.h

index c30add5..0c2962b 100644 (file)
@@ -123,19 +123,28 @@ void RenderThread::Start()
   int error = pthread_create( mThread, NULL, InternalThreadEntryFunc, this );
   DALI_ASSERT_ALWAYS( !error && "Return code from pthread_create() in RenderThread" );
 
-  mSurface->StartRender();
+  if( mSurface )
+  {
+    mSurface->StartRender();
+  }
 }
 
 void RenderThread::Stop()
 {
   DALI_LOG_INFO( gRenderLogFilter, Debug::Verbose, "RenderThread::Stop()\n");
 
-  // shutdown the render thread and destroy the opengl context
-  if( mThread )
+  if( mSurface )
   {
     // Tell surface we have stopped rendering
     mSurface->StopRender();
 
+    // The surface will be destroyed soon; this pointer will become invalid
+    mSurface = NULL;
+  }
+
+  // shutdown the render thread and destroy the opengl context
+  if( mThread )
+  {
     // wait for the thread to finish
     pthread_join(*mThread, NULL);
 
@@ -300,14 +309,16 @@ void RenderThread::ReplaceSurface( RenderSurface* newSurface )
   mSurfaceReplaced = true;
 }
 
-
 void RenderThread::ShutdownEgl()
 {
   // inform core of context destruction
   mCore.ContextDestroyed();
 
-  // give a chance to destroy the OpenGL surface that created externally
-  mSurface->DestroyEglSurface( *mEGL );
+  if( mSurface )
+  {
+    // give a chance to destroy the OpenGL surface that created externally
+    mSurface->DestroyEglSurface( *mEGL );
+  }
 
   // delete the GL context / egl surface
   mEGL->TerminateGles();
@@ -315,7 +326,12 @@ void RenderThread::ShutdownEgl()
 
 bool RenderThread::PreRender()
 {
-  bool success = mSurface->PreRender( *mEGL, mGLES );
+  bool success( false );
+  if( mSurface )
+  {
+    success = mSurface->PreRender( *mEGL, mGLES );
+  }
+
   if( success )
   {
     mGLES.PreRender();
@@ -328,12 +344,14 @@ void RenderThread::PostRender( unsigned int timeDelta )
   // Inform the gl implementation that rendering has finished before informing the surface
   mGLES.PostRender(timeDelta);
 
-  // Inform the surface that rendering this frame has finished.
-  mSurface->PostRender( *mEGL, mGLES, mDisplayConnection, timeDelta, mSurfaceReplaced );
+  if( mSurface )
+  {
+    // Inform the surface that rendering this frame has finished.
+    mSurface->PostRender( *mEGL, mGLES, mDisplayConnection, timeDelta, mSurfaceReplaced );
+  }
   mSurfaceReplaced = false;
 }
 
-
 } // namespace Adaptor
 
 } // namespace Internal
index 9e1efdd..fc4a035 100644 (file)
@@ -80,7 +80,6 @@ Application::Application( int* argc, char** argv[], const std::string& styleshee
   mName(),
   mStylesheet( stylesheet ),
   mEnvironmentOptions(),
-  mInitialized( false ),
   mSlotDelegate( this )
 {
   // Get mName from environment options
@@ -166,7 +165,6 @@ void Application::QuitFromMainLoop()
 
   mFramework->Quit();
   // This will trigger OnTerminate(), below, after the main loop has completed.
-  mInitialized = false;
 }
 
 void Application::OnInit()
@@ -201,8 +199,6 @@ void Application::OnInit()
     Dali::StyleMonitor::Get().SetTheme( mStylesheet );
   }
 
-  mInitialized = true;
-
   // Wire up the LifecycleController
   Dali::LifecycleController lifecycleController = Dali::LifecycleController::Get();
 
@@ -225,8 +221,13 @@ void Application::OnTerminate()
   // we've been told to quit by AppCore, ecore_x_destroy has been called, need to quit synchronously
   // delete the window as ecore_x has been destroyed by AppCore
 
+  if( mAdaptor )
+  {
+    // Ensure that the render-thread is not using the surface(window) after we delete it
+    mAdaptor->Stop();
+  }
+
   mWindow.Reset();
-  mInitialized = false;
 }
 
 void Application::OnPause()
index 1a8e612..e323b0e 100644 (file)
@@ -309,8 +309,6 @@ private:
   std::string                           mStylesheet;
   EnvironmentOptions                    mEnvironmentOptions;
 
-  bool                                  mInitialized;
-
   SlotDelegate< Application >           mSlotDelegate;
 };