OpenSceneGraph icon indicating copy to clipboard operation
OpenSceneGraph copied to clipboard

Make sure GUIActionAdapter has a single vtable

Open pvalsecc opened this issue 2 years ago • 0 comments

With clang 10, a simple dynamic_cast<osgViewer::Viewer*>(&aa) with aa of type osgGA::GUIActionAdapter but actually referencing a osgViewer::Viewer was returning nullptr.

This is due to the fact that the compiler didn't know where to put the vtable implementation. By the way, clang has a nice warning for that:

Class has no out-of-line virtual method definitions; its vtable will be emitted in every translation unit [-Wweak-vtables]

Since the Viewer was instanciated in the code of the lib, I guess it used a different vtable than the dynamic_cast in my binary, making dynamic_cast think it was a different class and thus returning a nullptr.

I've made the GUIActionAdapter class visible, since it's used as base class of other visible classes.

pvalsecc avatar Apr 06 '22 05:04 pvalsecc