Skip to content

Commit

Permalink
[FIX] Fix SEGFAULT that occured when using multiple instances of vpAR…
Browse files Browse the repository at this point in the history
…Ogre
  • Loading branch information
LAGNEAU Romain committed Jan 8, 2025
1 parent 40eb360 commit 42fc48d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions modules/ar/include/visp3/ar/vpAROgre.h
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ class VISP_EXPORT vpAROgre : public Ogre::FrameListener,

protected:
static unsigned int sID;
static unsigned int sRTSSUsers;
// Attributes
Ogre::String name; /**Name of th Window*/
bool mInitialized; /** True once init(bool, bool) has been called.*/
Expand Down
11 changes: 9 additions & 2 deletions modules/ar/src/ogre-simulator/vpAROgre.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ typedef Ogre::WindowEventUtilities OgreWindowEventUtilities;

BEGIN_VISP_NAMESPACE
unsigned int vpAROgre::sID = 0;
unsigned int vpAROgre::sRTSSUsers = 0;

/*!
Constructor.
Expand Down Expand Up @@ -104,7 +105,8 @@ Initialize the RT Shader system.
bool vpAROgre::initialiseRTShaderSystem()
{
#if defined(OGRE_BUILD_COMPONENT_RTSHADERSYSTEM) & (VISP_HAVE_OGRE_VERSION >= (1<<16 | 10 <<8 | 0))
if (Ogre::RTShader::ShaderGenerator::initialize()) {
if (Ogre::RTShader::ShaderGenerator::initialize() || (sRTSSUsers > 0)) {
++sRTSSUsers;
mShaderGenerator = Ogre::RTShader::ShaderGenerator::getSingletonPtr();

// Create and register the material manager listener if it doesn't exist yet.
Expand Down Expand Up @@ -136,7 +138,12 @@ void vpAROgre::destroyRTShaderSystem()

// Destroy RTShader system.
if (mShaderGenerator != NULL) {
Ogre::RTShader::ShaderGenerator::destroy();
if (sRTSSUsers > 0) {
--sRTSSUsers;
}
if (sRTSSUsers == 0) {
Ogre::RTShader::ShaderGenerator::destroy();
}
mShaderGenerator = NULL;
}
#endif
Expand Down

0 comments on commit 42fc48d

Please sign in to comment.