Hi all,

I am porting my code to the iphone and I am experiencing crashes, as my
code uses osg::observer_ptr. My code works without problems on Mac and
Windows, so I suspect that the fault is not in my code.

To isolate the problem a little bit more, I coded the following simple
example:

class MyTest : public osg::Referenced {
public:
        MyTest(osg::Referenced* ref) : osg::Referenced(), _ref(ref) {}
        
        void check() {
                if (_ref.valid())
                {
                        std::cout << "ref is valid" << std::endl;
                } else {
                        std::cout << "ref is invalid" << std::endl;
                }
        }
        
private:
        osg::observer_ptr<osg::Referenced> _ref;
};


void test_observer()
{
        osg::ref_ptr<osg::Referenced> ref = new osg::Referenced();
        osg::ref_ptr<MyTest> mytest = new MyTest(ref);
                
        // shows "ref is valid"
        mytest->check();
        
        ref = NULL;
        
        // shows "ref is invalid"
        mytest->check();
        
        // crashes in the d'tor
        mytest = NULL;
}


wenn calling test_observer I get a crash at the line mytest = NULL,
here's the stack-trace:

#0      0x000540f7 in OpenThreads::ScopedLock<OpenThreads::Mutex>::ScopedLock
at ScopedLock:31
#1      0x0000ad0b in osg::Referenced::unref at Referenced:185
#2      0x00072634 in osg::ref_ptr<osg::ObserverSet>::~ref_ptr at ref_ptr:35
#3      0x00072651 in osg::observer_ptr<osg::Referenced>::~observer_ptr at
observer_ptr:70
#4      0x00072912 in MyTest::~MyTest at osgAppDelegate.mm:21
#5      0x00027fa5 in osg::Referenced::signalObserversAndDelete at
Referenced.cpp:319
#6      0x0000ad7d in osg::Referenced::unref at Referenced:198
#7      0x00072757 in osg::ref_ptr<MyTest>::operator= at ref_ptr:58
#8      0x00071915 in test_observer at osgAppDelegate.mm:53

inspecting the _refMutex it seems it points to a random memory address.

As I compiled osg for the iPhone there's a chance, that the defines are
not correctly, for reference here's

OpenThreads/Config

#ifndef _OPENTHREADS_CONFIG
#define _OPENTHREADS_CONFIG
#define OT_LIBRARY_STATIC
#include <AvailabilityMacros.h>

#define _OPENTHREADS_ATOMIC_USE_MUTEX

//static link required on IPhone
#define OT_LIBRARY_STATIC


/* #undef _OPENTHREADS_ATOMIC_USE_GCC_BUILTINS */
/* #undef _OPENTHREADS_ATOMIC_USE_MIPOSPRO_BUILTINS */
/* #undef _OPENTHREADS_ATOMIC_USE_SUN */
/* #undef _OPENTHREADS_ATOMIC_USE_WIN32_INTERLOCKED */
/* #undef _OPENTHREADS_ATOMIC_USE_MUTEX */

#endif


and osg/Config:

#ifndef OSG_CONFIG
#define OSG_CONFIG 1

//static link needed on IPhone
#define OSG_LIBRARY_STATIC

#define OSG_USE_FLOAT_MATRIX
/* #undef OSG_USE_FLOAT_PLANE */
#define OSG_USE_FLOAT_BOUNDINGSPHERE
#define OSG_USE_FLOAT_BOUNDINGBOX
#define OSG_USE_REF_PTR_IMPLICIT_OUTPUT_CONVERSION
/* #undef OSG_USE_UTF8_FILENAME */
#define OSG_DISABLE_MSVC_WARNINGS

/* #undef OSG_GLU_AVAILABLE */
/* #undef OSG_GL1_AVAILABLE */
/* #undef OSG_GL2_AVAILABLE */
/* #undef OSG_GL3_AVAILABLE */
#define OSG_GLES1_AVAILABLE
/* #undef OSG_GLES2_AVAILABLE */


/* #undef OSG_GL_DISPLAYLISTS_AVAILABLE */
#define OSG_GL_MATRICES_AVAILABLE
#define OSG_GL_VERTEX_FUNCS_AVAILABLE
#define OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
#define OSG_GL_FIXED_FUNCTION_AVAILABLE

#endif


Any help is greatly appreciated,

Stephan
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to