Hello Theodore, Hall, Theodore wrote: > Carsten Neumann wrote: >> some ideas to debug this further: >> - you can access the reference count of an object with >> FieldContainer::getRefCount() > > I've been having a similar issue with a MultiDisplayWindowRefPtr, so I > followed your advice: > > In my "open server" function: > > // local variable > OSG::MultiDisplayWindow * multi_display_window > = static_cast<OSG::MultiDisplayWindow *> ( > m_ClusterServer->getClusterWindow()); > > if (multi_display_window) std::cerr > << "multi_display_window->getRefCount() = " > << multi_display_window->getRefCount() << std::endl; > > That prints "2" already. A little surprising, but OK.
one reference is from ClusterServer::_clusterWindow, the second one is transmitted from the client side where the MultiDisplayWindow is held by a MultiDisplayWindowRefPtr. > // copy to class data variable > m_MultiDisplayWindow = multi_display_window; > if (m_MultiDisplayWindow) std::cerr > << "m_MultiDisplayWindow->getRefCount() = " > << m_MultiDisplayWindow->getRefCount() << std::endl; > > That prints "3". OK. ok. > In my "close" function: > > // test class data variable > if (m_MultiDisplayWindow) std::cerr > << "m_MultiDisplayWindow->getRefCount() = " > << m_MultiDisplayWindow->getRefCount() << std::endl; > > That still prints "3". OK. ok. > // delete the ClusterServer > if (m_ClusterServer) > { > m_ClusterServer->stop (); > delete m_ClusterServer; > m_ClusterServer = NULL; > } > > // test class data variable > if (m_MultiDisplayWindow) std::cerr > << "m_MultiDisplayWindow->getRefCount() = " > << m_MultiDisplayWindow->getRefCount() << std::endl; > > That already prints "0", even though I have not yet destroyed or reset > m_MultiDisplayWindow. I expected it to be "1". > > m_MultiDisplayWindow = NULL; > > The program crashes here -- I guess because the MultiDisplayWindow was > already destroyed when its reference count went to zero, and now it's > trying to destroy it again. > > My problem seems to be related to m_ClusterServer->stop (); I notice > that the demo program does not call that before deleting the server. > If I remove that call, my program exits cleanly. hm, yeah the server shutdown is a bit messy. The problem is that some objects that are only held by the client application (e.g. the ClusterWindow) are only destroyed because the RemoteAspect (contained in ClusterServer and deleted in ClusterServer::stop()), explicitly destroys all objects received over the network [1] An easy solution (workaround) for your problem would be to set m_MultiDisplayWindow = NULL before calling ClusterServer::stop(). I'm not sure if we can do much better here, the alternative not to destroy these objects is also not very appealing to me... Cheers, Carsten [1] most objects are destroyed when the client application has no reference to them any more (in that case a SubRef message is sent as part of the cluster sync), but the ClusterWindow must outlive the connection on the client side so the SubRef message for it can never make it over the net. ------------------------------------------------------------------------------ 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