Hello Theodore,

Hall, Theodore wrote:
> Consider these lines from Examples/Simple/clusterserver.cpp:
> 
>     // Declared at file scope:
>     OSG::GLUTWindowRefPtr window;
>     OSG::ClusterServer    *server;
> 
>     // in main:
>     window = OSG::GLUTWindow::create();
>     server = new OSG::ClusterServer(window,name,connectionType,address);
>     // ...
>     delete server;
>     window = NULL;
> 
> The file scope holds a reference-counted pointer to the GLUTWindow.
> The main function creates the window, assigns the pointer, and passes
> it to the ClusterServer constructor.
> 
> The ClusterServer constructor accepts a naked pointer and wraps it in
> its own internal reference-counted pointer (WindowUnrecPtr _window).
> 
> Do we now have two uncoordinated reference counts to the underlying
> GLUTWindow object, with the threat of calling its destructor twice as
> these reference counts independently return to zero?

the reference count is stored in the pointed-to object (here: 
GLUTWindow), not the pointer. After the ClusterServer constructor the 
GLUTWindow object has a ref count of 2.

> Or is there
> something happening behind the scene to prevent that?

I'm not sure what you mean be "two uncoordinated reference counts", 
there is only one ref count, it is modified by the two pointers.

> The reason I ask is that my program is crashing in its exit routines,
> and I suspect it may be because a destructor is getting called twice,
> from two uncoordinated reference counted pointers.

hm, not sure what is causing this.

> My program follows essentially the same logic as the demo, except that
> I have no file scope variables: I hold the window and server in data
> members of a class.  Trouble ensues in the close() function for this
> class.  This happens before osgExit() :
> 
>     // Class data members:
>     OSG::PassiveWindowRecPtr   m_Window;
>     OSG::ClusterServer       * m_ClusterServer;
> 
>     // Creating the window and server:
>     m_Window        = OSG::PassiveWindow::create();
>     m_ClusterServer = new OSG::ClusterServer (m_Window, ...);
> 
>     // Closing:
>     delete m_ClusterServer;  // OK
>     m_Window = NULL;         // Crash -- uncaught exception
> 
> Unhandled exception ...
> Access violation reading location 0xffffffffffffffff.
> 
> OSG::RecordedRefCountPolicy::subRef(OSG::FieldContainer * const 
> objectP=0x00000000032a1800)  Line 66  C++

some ideas to debug this further:
- you can access the reference count of an object with 
FieldContainer::getRefCount()
- a way to check if a container is still 'alive' is to store its id 
(FieldContainer::getId()) at creation time and later when you want to 
check it ask the FieldContainterFactory::the()->getContainer(id). If you 
get a NULL pointer the container is not 'alive' any more.

        Cheers,
                Carsten


------------------------------------------------------------------------------
This SF.net email is sponsored by 

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev 
_______________________________________________
Opensg-users mailing list
Opensg-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensg-users

Reply via email to