From c913f00d21e59c77fc0d556e726eeae642b6444a Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 1 Jun 2007 21:28:18 +0000 Subject: [PATCH] From Michael Hartman, "CMakeLists.txt: Changed this back to setup_example since WIN32 flag is now supported. MFC_OSG.h: Added flag to indicate when the rendering thread has exited. MFC_OSG.cpp: Code modifications to support rendering flag thread exit. MFC_OSG_MDIView.cpp: Change to OnDestroy function to wait until we get render thread exit flag is true before we close the window. Main Exit Process: User presses escape button Viewer captures escape button and stops threading etc. Viewer sets Done when shutdown is complete MFC Render Thread monitors viewer->done for true MFC Render Thread exits while loop and sets MFC Done flag MFC View Window monitors MFC Done flag and then closes/destroys the window " --- examples/osgviewerMFC/CMakeLists.txt | 29 ++--------------------- examples/osgviewerMFC/MFC_OSG.cpp | 5 +++- examples/osgviewerMFC/MFC_OSG.h | 3 +++ examples/osgviewerMFC/MFC_OSG_MDIView.cpp | 8 +++---- 4 files changed, 12 insertions(+), 33 deletions(-) diff --git a/examples/osgviewerMFC/CMakeLists.txt b/examples/osgviewerMFC/CMakeLists.txt index 238f38a46..06e0b3dc7 100644 --- a/examples/osgviewerMFC/CMakeLists.txt +++ b/examples/osgviewerMFC/CMakeLists.txt @@ -2,32 +2,7 @@ SET(TARGET_SRC MFC_OSG_MDI.cpp MFC_OSG_MDI.rc MFC_OSG_MDIDoc.cpp MFC_OSG_MDIView SET(TARGET_H MFC_OSG_MDI.h MFC_OSG_MDIDoc.h MFC_OSG_MDIView.h stdafx.h MFC_OSG.h MainFrm.h ChildFrm.h Resource.h) ADD_DEFINITIONS(-D_AFXDLL) -SET(CMAKE_MFC_FLAG 2) +SET(REQUIRE_WINMAIN_FLAG 1) #### end var setup ### -#SETUP_EXAMPLE(osgviewerMFC) - -# -#Extracted from SETUP_EXAMPLES -# -SET(TARGET_NAME osgviewerMFC) - -# -#Extracted from SETUP_EXE -# -IF(NOT TARGET_TARGETNAME) - SET(TARGET_TARGETNAME "${TARGET_DEFAULT_PREFIX}${TARGET_NAME}") -ENDIF(NOT TARGET_TARGETNAME) -IF(NOT TARGET_LABEL) - SET(TARGET_LABEL "${TARGET_DEFAULT_LABEL_PREFIX} ${TARGET_NAME}") -ENDIF(NOT TARGET_LABEL) - -# This is the important line because it adds WIN32 which tells CMake that this is an MFC/Windows appliation -# and not a console application -ADD_EXECUTABLE(${TARGET_TARGETNAME} WIN32 ${TARGET_SRC} ${TARGET_H}) - -SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES PROJECT_LABEL "${TARGET_LABEL}") -SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX}) -SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES OUTPUT_NAME ${TARGET_NAME}) - -SETUP_LINK_LIBRARIES() +SETUP_EXAMPLE(osgviewerMFC) diff --git a/examples/osgviewerMFC/MFC_OSG.cpp b/examples/osgviewerMFC/MFC_OSG.cpp index e8111d9f5..f68b74464 100644 --- a/examples/osgviewerMFC/MFC_OSG.cpp +++ b/examples/osgviewerMFC/MFC_OSG.cpp @@ -5,7 +5,7 @@ cOSG::cOSG(HWND hWnd) : - m_hWnd(hWnd) + m_hWnd(hWnd), mDone(false) { // // We must set the pixelformat before we can create the OSG Rendering Surface @@ -182,4 +182,7 @@ void cOSG::Render(void* ptr) // if you have multiple OSG windows up // and you exit one then all stop rendering AfxMessageBox("Exit Rendering Thread"); + + // Set Done to indicate that thread has exited + osg->Done(true); } diff --git a/examples/osgviewerMFC/MFC_OSG.h b/examples/osgviewerMFC/MFC_OSG.h index cd7779cec..ead1a4bcf 100644 --- a/examples/osgviewerMFC/MFC_OSG.h +++ b/examples/osgviewerMFC/MFC_OSG.h @@ -25,11 +25,14 @@ public: void SetupCamera(void); void PreFrameUpdate(void); void PostFrameUpdate(void); + void Done(bool value) { mDone = value; } + bool Done(void) { return mDone; } static void Render(void* ptr); osgViewer::Viewer* getViewer() { return mViewer.get(); } private: + bool mDone; std::string m_ModelName; HWND m_hWnd; osg::ref_ptr mViewer; diff --git a/examples/osgviewerMFC/MFC_OSG_MDIView.cpp b/examples/osgviewerMFC/MFC_OSG_MDIView.cpp index de9b2b5d5..8810ef464 100644 --- a/examples/osgviewerMFC/MFC_OSG_MDIView.cpp +++ b/examples/osgviewerMFC/MFC_OSG_MDIView.cpp @@ -77,13 +77,11 @@ void CMFC_OSG_MDIView::OnDestroy() // Make sure OSG was created before we try to close it. if(mOSG) { - // Force osg Viewer to shut down - mOSG->getViewer()->setDone(true); - + // Wait while the Viewer closes - while(!mOSG->getViewer()->done()) + while(!mOSG->Done()) { - Sleep(0); // Allow others processor time + Sleep(10); // Allow others processor time } // Remove mOSG