Hello Pablo,

Pablo Carneiro Elias wrote:
I've recently updated our version of OpenSG to the current svn version and we're experiencing a problem when we try to re-open a project (destroy the whole scene
and the window and create a new one).

The problem occurs right when we call init() method of the PassiveWindow, immediately after re-creating it.

Tracking the error lead us to the following call stack:

     msvcr80d.dll!strlen(unsigned char * buf=0x0012f9d4)  Line 81    Asm
msvcp80d.dll!std::char_traits<char>::length(const char * _First=0x00000000) Line 559 + 0x9 bytes C++ msvcp80d.dll!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::assign(const char * _Ptr=0x00000000) Line 1080 + 0x9 bytes C++
     OSGSystemD.dll!OSG::Window::setupGL()  Line 1889 + 0x2d bytes    C++
OSGSystemD.dll!OSG::Window::init(boost::function<void __cdecl(void),std::allocator<void> > oFunc={...}) Line 2280 + 0x12 bytes C++

the backtrace shows that you get NULL back from glGetString(GL_VERSION) on line 1889 in OSGWindow.cpp, which most likely means you do not have an OpenGL context at that point.

The first time init() is called, everything works fine.. however the problem occurs if we try to re-create the window.

To assure ourselves we weren't doing anything wrong, we created a small program based on the simple example of yours (hello01.cpp) that creates a simple scene, and by pressing a key, destroys the window and re-creates it (along with the scene).

The exact same error occurs (as listed above by the call stack).
The folowing code are the modifications of the example ( hello01.cpp ) stated above:

[SNIP - code]

err, that codes uses GLUTWindow? Anyway, switching it to PassiveWindow reproduces the bug. The WIN32Window destroys the OpenGL context in its d'tor and since PassiveWindow derives from it on windows you not only destroy the window, but also the context. I've attached a patch that moves the context destruction to the terminate() function (should have been there in the first place I think) and overrides that function in PassiveWindow to allow the context to outlive the PassiveWindow.

@Gerrit: Can you please take a look at the patch if it makes sense? Thanks!

        Cheers,
                Carsten

Index: Source/System/Window/Passive/OSGPassiveWindow.cpp
===================================================================
--- Source/System/Window/Passive/OSGPassiveWindow.cpp	(revision 2164)
+++ Source/System/Window/Passive/OSGPassiveWindow.cpp	(working copy)
@@ -133,6 +133,12 @@
     Window::init(oFunc);
 }
 
+/*! Do nothing, GL context is managed by application
+ */
+void PassiveWindow::terminate(void)
+{
+}
+
 /* Do nothing, has to be setup when we come here.
  */
 void PassiveWindow::activate(void)
Index: Source/System/Window/Passive/OSGPassiveWindow.h
===================================================================
--- Source/System/Window/Passive/OSGPassiveWindow.h	(revision 2164)
+++ Source/System/Window/Passive/OSGPassiveWindow.h	(working copy)
@@ -79,7 +79,8 @@
     /*! \name                      Redefined                               */
     /*! \{                                                                 */
     
-    virtual void init(GLInitFunctor oFunc = GLInitFunctor());
+    virtual void init     (GLInitFunctor oFunc = GLInitFunctor());
+    virtual void terminate(void                                 );
 
     /*! \}                                                                 */
     /*---------------------------------------------------------------------*/
Index: Source/WindowSystem/WIN32/OSGWIN32Window.cpp
===================================================================
--- Source/WindowSystem/WIN32/OSGWIN32Window.cpp	(revision 2164)
+++ Source/WindowSystem/WIN32/OSGWIN32Window.cpp	(working copy)
@@ -77,8 +77,6 @@
 
 WIN32Window::~WIN32Window(void)
 {
-    if(getHglrc() != NULL)
-        wglDeleteContext(getHglrc());
 }
 
 /*----------------------------- class specific ----------------------------*/
@@ -137,6 +135,18 @@
     }
 }
 
+void WIN32Window::terminate(void)
+{
+    Inherited::doTerminate();
+
+     if(getHglrc() != NULL)
+     {
+         this->doDeactivate();
+
+         wglDeleteContext(getHglrc());
+     }
+}
+
 void WIN32Window::activate  (void)
 {
     if((_sfDrawMode.getValue() & PartitionDrawMask) == SequentialPartitionDraw)
Index: Source/WindowSystem/WIN32/OSGWIN32Window.h
===================================================================
--- Source/WindowSystem/WIN32/OSGWIN32Window.h	(revision 2164)
+++ Source/WindowSystem/WIN32/OSGWIN32Window.h	(working copy)
@@ -79,7 +79,8 @@
     /*! \name                Window functions                              */
     /*! \{                                                                 */
     
-    virtual void init(GLInitFunctor oFunc = GLInitFunctor());
+    virtual void init     (GLInitFunctor oFunc = GLInitFunctor());
+    virtual void terminate(void                                 );
 
     /*! \}                                                                 */
     /*---------------------------------------------------------------------*/
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Opensg-users mailing list
Opensg-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensg-users

Reply via email to