Sean,
Don't know conclusively, but I have had problems like this in the past when
using dynamic_cast on a polymorphic object and it failed to give a non-NULL
value even when I knew it should. As you said, using a static_cast or C-style
cast works. In my case it had to do with how objects were defined in different
compilation units. What worked for me was specifying the following linker flag
to ensure that everybody had the same RTTI data.
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}
-Wl,-flat_namespace")
This link gives a more detailed description of the problem.
http://lists.apple.com/archives/xcode-users/2006/Feb/msg00234.html
The link only talks about passing the RTLD_GLOBAL flag to dlopen, but in my
case I needed to use the -flat_namespace flag. My particular case happened
from linking certain libraries statically causing multiple (different) copies
of the same object to be generated. Putting them all in a flat namespace made
them resolve the same, fixing my dynamic_cast problem.
So, not a conclusive answer, but at least it gives you something to investigate.
Hope that helps,
Chuck
On Jan 27, 2012, at 10:11 AM, Sean Sullivan wrote:
> Hey guys,
>
> I'm trying to pass an osgViewer::GraphicsWindowCocoa::WindowData to my traits
> object with CreateOnlyView specified. For some reason whenever my WindowData
> is dynamic_cast in GraphicsWindowCocoa.mm it just returns 0. If I switch them
> to static_cast they work.
>
> Here's my code:
>
>
> Code:
> // OSGWindow.h
> osgViewer::GraphicsWindowCocoa::WindowData* windowData;
>
> // OSGWindow.cpp
> windowData = new osgViewer::GraphicsWindowCocoa::WindowData
> (osgViewer::GraphicsWindowCocoa::WindowData::CreateOnlyView);
>
> osg::ref_ptr<osg::GraphicsContext::Traits> traits = new
> osg::GraphicsContext::Traits();
>
> traits->x = 100;
> traits->y = 100;
> traits->width = 1280;
> traits->height = 720;
> traits->red = 8;
> traits->blue = 8;
> traits->green = 8;
> traits->alpha = 8;
> traits->depth = 24;
> traits->windowDecoration = false;
> traits->doubleBuffer = true;
> traits->vsync = false;
> traits->stencil = 1;
> traits->samples = 8;
> traits->sampleBuffers = 1;
> traits->inheritedWindowData = windowData;
>
> osg::ref_ptr<osg::GraphicsContext> context =
> osg::GraphicsContext::createGraphicsContext (traits.get());
>
>
>
> This is what's in GraphicsWindowCocoa.mm that returns 0:
>
>
> Code:
> GraphicsWindowCocoa::WindowData* windowData = traits->inheritedWindowData ?
> dynamic_cast<GraphicsWindowCocoa::WindowData*>(traits->inheritedWindowData.get())
> : NULL;
>
>
>
> I tried expanding it into if statements and the traits->inheritedWindowData
> returns true. I also tried copying and pasting this line into my file where I
> create my traits object and it returns properly.
>
> Any ideas?
>
> Cheers,
> Sean
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=45082#45082
>
>
>
>
>
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org