OGRECave / ogre-audiovideo

plugins for theora video playback and openAL audio
https://ogrecave.github.io/ogre-audiovideo/
BSD 3-Clause "New" or "Revised" License
14 stars 11 forks source link

Possible bug introduced by new SceneManager handling #15

Closed sercero closed 3 years ago

sercero commented 3 years ago

Hey @paroj, I believe there where some changes introduced in Ogre 1.12 that relate to Scene Managers (because this wasn't an issue in OGRE 1.11 or earlier versions of OgreOggSound).

It seems that it produced a bug in OgreOggSound, because I am observing this behaviour:

mRoot->destroySceneManager(mSceneMgr);
mRoot->shutdown();

Produces a Segmentation fault. with the following backtrace:

Thread 1 received signal SIGSEGV, Segmentation fault.
0x000000006fc6e7a6 in libstdc++-6!_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE7compareERKS4_ () from D:\OGRE2\CodeBlocks\MinGW\bin\libstdc++-6.dll
(gdb) bt
#0  0x000000006fc6e7a6 in libstdc++-6!_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE7compareERKS4_ () from D:\OGRE2\CodeBlocks\MinGW\bin\libstdc++-6.dll
#1  0x0000000001fd8960 in std::operator< <char, std::char_traits<char>, std::allocator<char> > (__lhs=<error reading variable: Cannot access memory at address 0xfeeefeeefeeeff16>, __rhs="OgreOggISound")
    at D:/OGRE2/CodeBlocks/MinGW/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/basic_string.h:6097
#2  0x0000000001e43534 in std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::operator() (this=0x17ad93b8, __x=<error reading variable: Cannot access memory at address 0xfeeefeeefeeeff16>,
    __y="OgreOggISound") at D:/OGRE2/CodeBlocks/MinGW/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/stl_function.h:386
#3  0x0000000001f39ca7 in std::_Rb_tree<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, Ogre::SceneManager::MovableObjectCollection*>, std::_Select1st<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, Ogre::SceneManager::MovableObjectCollection*> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, Ogre::SceneManager::MovableObjectCollection*> > >::_M_lower_bound (
    this=0x17ad93b8, __x=0xfeeefeeefeeefeee, __y=0x17ad93c0, __k="OgreOggISound") at D:/OGRE2/CodeBlocks/MinGW/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/stl_tree.h:1888
#4  0x0000000001f3a481 in std::_Rb_tree<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, Ogre::SceneManager::MovableObjectCollection*>, std::_Select1st<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, Ogre::SceneManager::MovableObjectCollection*> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, Ogre::SceneManager::MovableObjectCollection*> > >::find (this=0x17ad93b8,
    __k="OgreOggISound") at D:/OGRE2/CodeBlocks/MinGW/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/stl_tree.h:2539
#5  0x0000000001ebf600 in std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, Ogre::SceneManager::MovableObjectCollection*, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, Ogre::SceneManager::MovableObjectCollection*> > >::find (this=0x17ad93b8, __x="OgreOggISound")
    at D:/OGRE2/CodeBlocks/MinGW/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/stl_map.h:1170
#6  0x0000000001d029e8 in Ogre::SceneManager::getMovableObjectCollection (this=0x17ad9020, typeName="OgreOggISound") at D:\OGRE2\Sources\ogre-1.12.12\OgreMain\src\OgreSceneManager.cpp:3615
#7  0x0000000001d03012 in Ogre::SceneManager::destroyAllMovableObjectsByType (this=0x17ad9020, typeName="OgreOggISound") at D:\OGRE2\Sources\ogre-1.12.12\OgreMain\src\OgreSceneManager.cpp:3718
#8  0x0000000070b04f6e in OgreOggSound::OgreOggSoundManager::~OgreOggSoundManager (this=0x17ad8b90, __in_chrg=<optimized out>) at D:\OGRE2\Sources\ogre-audiovideo\oggsound\src\OgreOggSoundManager.cpp:223
#9  0x0000000070b0adf6 in OgreOggSound::OgreOggSoundPlugin::shutdown (this=0x17abc8b0) at D:\OGRE2\Sources\ogre-audiovideo\oggsound\src\OgreOggSoundPlugin.cpp:77
#10 0x0000000001cf178c in Ogre::Root::shutdownPlugins (this=0x17b86f50) at D:\OGRE2\Sources\ogre-1.12.12\OgreMain\src\OgreRoot.cpp:972
#11 0x0000000001cf0efd in Ogre::Root::shutdown (this=0x17b86f50) at D:\OGRE2\Sources\ogre-1.12.12\OgreMain\src\OgreRoot.cpp:896
#12 0x0000000000403473 in SoundTest::~SoundTest (this=0x82fd40, __in_chrg=<optimized out>) at D:\OGRE2\Dev\SoundTest\SoundTest.cpp:53
#13 0x0000000000404dc2 in WinMain (hInst=0x400000, strCmdLine=0x8e3d71 "") at D:\OGRE2\Dev\SoundTest\SoundTest.cpp:404
#14 0x00000000004013c7 in __tmainCRTStartup ()
#15 0x00000000004014fb in mainCRTStartup ()

It seems that the OgreOggSoundPlugin is being shutdown before the SceneManager.

Can you help me with this?

Thanks

sercero commented 3 years ago

Update: Now I see that the culprit is OgreOggSoundManager::~OgreOggSoundManager()

        if ( mListener )
        {
            Ogre::SceneManager* s = mListener->getSceneManager();
            s->destroyAllMovableObjectsByType("OgreOggISound");
            _destroyListener();
        }

Do you think that this could be safely removed?

paroj commented 3 years ago

probably. The SceneManager will destroy all movable objects if it goes down anyway.

However this will leak if OgreOggSoundManager is destroyed, but the SceneManager is not.

sercero commented 3 years ago

I managed to solve it this way:

    mSceneMgr->clearScene();
    mRoot->destroySceneManager(mSceneMgr);

    mSoundManager->setSceneManager(nullptr);

    mRoot->shutdown();

    delete mRoot;

So, I will probably make a guide on how to use OgreOggSound with all the pitfalls I know...