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