From Michael Hartman, "Here is an update for the closing issue with the example osgviewerMFC where the MFC rendering thread would not exit before the application and the thread would be left running in the background and the user would have to use TaskManager to kill the process.
Changes:
MFC_OSG.cpp:
Removed pixelformatdesciptor from the class initialization.
Used setInheritedWindowPixelFormat to true so it will setup the pixelformat for the window.
Added class destructor code.
MFC_OSG.h:
Removed the ref_ptr on osgViewer::Viewer
MFC_OSG_MDIViewer.cpp:
Changed the OnDestroy function code.
Added WaitforSingleObject with thread handle for the MFC render handle.
MFC_OSG_MDIView.h:
Added class variable for MFC Render Thread Handle for use with the WaitforSingleObject.
"
This commit is contained in:
@@ -5,49 +5,17 @@
|
||||
|
||||
|
||||
cOSG::cOSG(HWND hWnd) :
|
||||
m_hWnd(hWnd), mDone(false)
|
||||
m_hWnd(hWnd)
|
||||
{
|
||||
//
|
||||
// We must set the pixelformat before we can create the OSG Rendering Surface
|
||||
//
|
||||
PIXELFORMATDESCRIPTOR pixelFormat =
|
||||
{
|
||||
sizeof(PIXELFORMATDESCRIPTOR),
|
||||
1,
|
||||
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
|
||||
PFD_TYPE_RGBA,
|
||||
24,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0,
|
||||
24,
|
||||
0,
|
||||
0,
|
||||
PFD_MAIN_PLANE,
|
||||
0,
|
||||
0, 0, 0
|
||||
};
|
||||
}
|
||||
|
||||
HDC hdc = ::GetDC(m_hWnd);
|
||||
if (hdc==0)
|
||||
{
|
||||
::DestroyWindow(m_hWnd);
|
||||
return;
|
||||
}
|
||||
cOSG::~cOSG()
|
||||
{
|
||||
mViewer->setDone(true);
|
||||
Sleep(1000);
|
||||
mViewer->stopThreading();
|
||||
|
||||
int pixelFormatIndex = ::ChoosePixelFormat(hdc, &pixelFormat);
|
||||
if (pixelFormatIndex==0)
|
||||
{
|
||||
::ReleaseDC(m_hWnd, hdc);
|
||||
::DestroyWindow(m_hWnd);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!::SetPixelFormat(hdc, pixelFormatIndex, &pixelFormat))
|
||||
{
|
||||
::ReleaseDC(m_hWnd, hdc);
|
||||
::DestroyWindow(m_hWnd);
|
||||
return;
|
||||
}
|
||||
delete mViewer;
|
||||
}
|
||||
|
||||
void cOSG::InitOSG(std::string modelname)
|
||||
@@ -100,7 +68,7 @@ void cOSG::InitCameraConfig(void)
|
||||
RECT rect;
|
||||
|
||||
// Create the viewer for this window
|
||||
mViewer = new osgViewer::Viewer;
|
||||
mViewer = new osgViewer::Viewer();
|
||||
|
||||
// Add a Stats Handler to the viewer
|
||||
mViewer->addEventHandler(new osgViewer::StatsHandler);
|
||||
@@ -122,6 +90,7 @@ void cOSG::InitCameraConfig(void)
|
||||
traits->windowDecoration = false;
|
||||
traits->doubleBuffer = true;
|
||||
traits->sharedContext = 0;
|
||||
traits->setInheritedWindowPixelFormat = true;
|
||||
traits->inheritedWindowData = windata;
|
||||
|
||||
// Create the Graphics Context
|
||||
@@ -183,6 +152,5 @@ void cOSG::Render(void* ptr)
|
||||
// and you exit one then all stop rendering
|
||||
AfxMessageBox("Exit Rendering Thread");
|
||||
|
||||
// Set Done to indicate that thread has exited
|
||||
osg->Done(true);
|
||||
_endthread();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user