PyBullet setup.py: only enable BT_USE_EGL on Linux, but allow to run the eglPlugin on Windows and Mac as well (using their default opengl window).
postpone the 'loadPlugin' for static eglPlugin, so that the init and exit happen in the same thread. When you don't call unloadPlugin, the program may crash when exiting in SHARED_MEMORY_SERVER mode.
This commit is contained in:
@@ -1715,16 +1715,18 @@ struct PhysicsServerCommandProcessorInternalData
|
|||||||
#endif //ENABLE_STATIC_GRPC_PLUGIN
|
#endif //ENABLE_STATIC_GRPC_PLUGIN
|
||||||
|
|
||||||
#ifdef STATIC_EGLRENDERER_PLUGIN
|
#ifdef STATIC_EGLRENDERER_PLUGIN
|
||||||
{
|
{
|
||||||
int renderPluginId = m_pluginManager.registerStaticLinkedPlugin("eglRendererPlugin", initPlugin_eglRendererPlugin, exitPlugin_eglRendererPlugin, executePluginCommand_eglRendererPlugin,0,0,getRenderInterface_eglRendererPlugin,0);
|
bool initPlugin = false;
|
||||||
|
int renderPluginId = m_pluginManager.registerStaticLinkedPlugin("eglRendererPlugin", initPlugin_eglRendererPlugin, exitPlugin_eglRendererPlugin, executePluginCommand_eglRendererPlugin,0,0,getRenderInterface_eglRendererPlugin,0, initPlugin);
|
||||||
m_pluginManager.selectPluginRenderer(renderPluginId);
|
m_pluginManager.selectPluginRenderer(renderPluginId);
|
||||||
}
|
}
|
||||||
#endif//STATIC_EGLRENDERER_PLUGIN
|
#endif//STATIC_EGLRENDERER_PLUGIN
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef SKIP_STATIC_TINYRENDERER_PLUGIN
|
#ifndef SKIP_STATIC_TINYRENDERER_PLUGIN
|
||||||
{
|
{
|
||||||
|
|
||||||
int renderPluginId = m_pluginManager.registerStaticLinkedPlugin("tinyRendererPlugin", initPlugin_tinyRendererPlugin, exitPlugin_tinyRendererPlugin, executePluginCommand_tinyRendererPlugin,0,0,getRenderInterface_tinyRendererPlugin,0);
|
int renderPluginId = m_pluginManager.registerStaticLinkedPlugin("tinyRendererPlugin", initPlugin_tinyRendererPlugin, exitPlugin_tinyRendererPlugin, executePluginCommand_tinyRendererPlugin,0,0,getRenderInterface_tinyRendererPlugin,0);
|
||||||
m_pluginManager.selectPluginRenderer(renderPluginId);
|
m_pluginManager.selectPluginRenderer(renderPluginId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ struct b3Plugin
|
|||||||
{
|
{
|
||||||
B3_DYNLIB_HANDLE m_pluginHandle;
|
B3_DYNLIB_HANDLE m_pluginHandle;
|
||||||
bool m_ownsPluginHandle;
|
bool m_ownsPluginHandle;
|
||||||
|
bool m_isInitialized;
|
||||||
std::string m_pluginPath;
|
std::string m_pluginPath;
|
||||||
int m_pluginUniqueId;
|
int m_pluginUniqueId;
|
||||||
PFN_INIT m_initFunc;
|
PFN_INIT m_initFunc;
|
||||||
@@ -52,6 +53,7 @@ struct b3Plugin
|
|||||||
b3Plugin()
|
b3Plugin()
|
||||||
:m_pluginHandle(0),
|
:m_pluginHandle(0),
|
||||||
m_ownsPluginHandle(false),
|
m_ownsPluginHandle(false),
|
||||||
|
m_isInitialized(false),
|
||||||
m_pluginUniqueId(-1),
|
m_pluginUniqueId(-1),
|
||||||
m_initFunc(0),
|
m_initFunc(0),
|
||||||
m_exitFunc(0),
|
m_exitFunc(0),
|
||||||
@@ -80,6 +82,7 @@ struct b3Plugin
|
|||||||
m_processClientCommandsFunc = 0;
|
m_processClientCommandsFunc = 0;
|
||||||
m_getRendererFunc = 0;
|
m_getRendererFunc = 0;
|
||||||
m_userPointer = 0;
|
m_userPointer = 0;
|
||||||
|
m_isInitialized = false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -171,8 +174,20 @@ int b3PluginManager::loadPlugin(const char* pluginPath, const char* postFixStr)
|
|||||||
int* pluginUidPtr = m_data->m_pluginMap.find(pluginPath);
|
int* pluginUidPtr = m_data->m_pluginMap.find(pluginPath);
|
||||||
if (pluginUidPtr)
|
if (pluginUidPtr)
|
||||||
{
|
{
|
||||||
|
|
||||||
//already loaded
|
//already loaded
|
||||||
pluginUniqueId = *pluginUidPtr;
|
pluginUniqueId = *pluginUidPtr;
|
||||||
|
b3PluginHandle* plugin = m_data->m_plugins.getHandle(pluginUniqueId);
|
||||||
|
if (!plugin->m_isInitialized)
|
||||||
|
{
|
||||||
|
b3PluginContext context = {0};
|
||||||
|
context.m_userPointer = 0;
|
||||||
|
context.m_physClient = (b3PhysicsClientHandle) m_data->m_physicsDirect;
|
||||||
|
context.m_rpcCommandProcessorInterface = m_data->m_rpcCommandProcessorInterface;
|
||||||
|
int result = plugin->m_initFunc(&context);
|
||||||
|
plugin->m_isInitialized = true;
|
||||||
|
plugin->m_userPointer = context.m_userPointer;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -217,10 +232,12 @@ int b3PluginManager::loadPlugin(const char* pluginPath, const char* postFixStr)
|
|||||||
context.m_physClient = (b3PhysicsClientHandle) m_data->m_physicsDirect;
|
context.m_physClient = (b3PhysicsClientHandle) m_data->m_physicsDirect;
|
||||||
context.m_rpcCommandProcessorInterface = m_data->m_rpcCommandProcessorInterface;
|
context.m_rpcCommandProcessorInterface = m_data->m_rpcCommandProcessorInterface;
|
||||||
int version = plugin->m_initFunc(&context);
|
int version = plugin->m_initFunc(&context);
|
||||||
|
plugin->m_isInitialized = true;
|
||||||
//keep the user pointer persistent
|
//keep the user pointer persistent
|
||||||
plugin->m_userPointer = context.m_userPointer;
|
plugin->m_userPointer = context.m_userPointer;
|
||||||
if (version == SHARED_MEMORY_MAGIC_NUMBER)
|
if (version == SHARED_MEMORY_MAGIC_NUMBER)
|
||||||
{
|
{
|
||||||
|
|
||||||
ok = true;
|
ok = true;
|
||||||
plugin->m_ownsPluginHandle = true;
|
plugin->m_ownsPluginHandle = true;
|
||||||
plugin->m_pluginHandle = pluginHandle;
|
plugin->m_pluginHandle = pluginHandle;
|
||||||
@@ -286,7 +303,12 @@ void b3PluginManager::unloadPlugin(int pluginUniqueId)
|
|||||||
context.m_userPointer = plugin->m_userPointer;
|
context.m_userPointer = plugin->m_userPointer;
|
||||||
context.m_physClient = (b3PhysicsClientHandle) m_data->m_physicsDirect;
|
context.m_physClient = (b3PhysicsClientHandle) m_data->m_physicsDirect;
|
||||||
|
|
||||||
|
if (plugin->m_isInitialized)
|
||||||
|
{
|
||||||
plugin->m_exitFunc(&context);
|
plugin->m_exitFunc(&context);
|
||||||
|
plugin->m_userPointer = 0;
|
||||||
|
plugin->m_isInitialized = false;
|
||||||
|
}
|
||||||
m_data->m_pluginMap.remove(plugin->m_pluginPath.c_str());
|
m_data->m_pluginMap.remove(plugin->m_pluginPath.c_str());
|
||||||
m_data->m_plugins.freeHandle(pluginUniqueId);
|
m_data->m_plugins.freeHandle(pluginUniqueId);
|
||||||
}
|
}
|
||||||
@@ -411,7 +433,7 @@ int b3PluginManager::executePluginCommand(int pluginUniqueId, const b3PluginArgu
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int b3PluginManager::registerStaticLinkedPlugin(const char* pluginPath, PFN_INIT initFunc,PFN_EXIT exitFunc, PFN_EXECUTE executeCommandFunc, PFN_TICK preTickFunc, PFN_TICK postTickFunc, PFN_GET_RENDER_INTERFACE getRendererFunc, PFN_TICK processClientCommandsFunc)
|
int b3PluginManager::registerStaticLinkedPlugin(const char* pluginPath, PFN_INIT initFunc,PFN_EXIT exitFunc, PFN_EXECUTE executeCommandFunc, PFN_TICK preTickFunc, PFN_TICK postTickFunc, PFN_GET_RENDER_INTERFACE getRendererFunc, PFN_TICK processClientCommandsFunc, bool initPlugin)
|
||||||
{
|
{
|
||||||
|
|
||||||
b3Plugin orgPlugin;
|
b3Plugin orgPlugin;
|
||||||
@@ -440,12 +462,14 @@ int b3PluginManager::registerStaticLinkedPlugin(const char* pluginPath, PFN_INIT
|
|||||||
|
|
||||||
m_data->m_pluginMap.insert(pluginPath, pluginUniqueId);
|
m_data->m_pluginMap.insert(pluginPath, pluginUniqueId);
|
||||||
|
|
||||||
|
if (initPlugin)
|
||||||
{
|
{
|
||||||
b3PluginContext context = {0};
|
b3PluginContext context = {0};
|
||||||
context.m_userPointer = 0;
|
context.m_userPointer = 0;
|
||||||
context.m_physClient = (b3PhysicsClientHandle) m_data->m_physicsDirect;
|
context.m_physClient = (b3PhysicsClientHandle) m_data->m_physicsDirect;
|
||||||
context.m_rpcCommandProcessorInterface = m_data->m_rpcCommandProcessorInterface;
|
context.m_rpcCommandProcessorInterface = m_data->m_rpcCommandProcessorInterface;
|
||||||
int result = pluginHandle->m_initFunc(&context);
|
int result = pluginHandle->m_initFunc(&context);
|
||||||
|
pluginHandle->m_isInitialized = true;
|
||||||
pluginHandle->m_userPointer = context.m_userPointer;
|
pluginHandle->m_userPointer = context.m_userPointer;
|
||||||
}
|
}
|
||||||
return pluginUniqueId;
|
return pluginUniqueId;
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ class b3PluginManager
|
|||||||
|
|
||||||
void tickPlugins(double timeStep, b3PluginManagerTickMode tickMode);
|
void tickPlugins(double timeStep, b3PluginManagerTickMode tickMode);
|
||||||
|
|
||||||
int registerStaticLinkedPlugin(const char* pluginPath, PFN_INIT initFunc, PFN_EXIT exitFunc, PFN_EXECUTE executeCommandFunc, PFN_TICK preTickFunc, PFN_TICK postTickFunc, PFN_GET_RENDER_INTERFACE getRendererFunc, PFN_TICK processClientCommandsFunc);
|
int registerStaticLinkedPlugin(const char* pluginPath, PFN_INIT initFunc, PFN_EXIT exitFunc, PFN_EXECUTE executeCommandFunc, PFN_TICK preTickFunc, PFN_TICK postTickFunc, PFN_GET_RENDER_INTERFACE getRendererFunc, PFN_TICK processClientCommandsFunc, bool initPlugin=true);
|
||||||
void selectPluginRenderer(int pluginUniqueId);
|
void selectPluginRenderer(int pluginUniqueId);
|
||||||
UrdfRenderingInterface* getRenderInterface();
|
UrdfRenderingInterface* getRenderInterface();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -162,6 +162,8 @@ struct EGLRendererVisualShapeConverterInternalData
|
|||||||
|
|
||||||
m_window->startRendering();
|
m_window->startRendering();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
b3Assert(glGetError() ==GL_NO_ERROR);
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
|
|
||||||
|
|
||||||
@@ -170,12 +172,25 @@ struct EGLRendererVisualShapeConverterInternalData
|
|||||||
int maxNumObjectCapacity = 128 * 1024;
|
int maxNumObjectCapacity = 128 * 1024;
|
||||||
int maxShapeCapacityInBytes = 128 * 1024 * 1024;
|
int maxShapeCapacityInBytes = 128 * 1024 * 1024;
|
||||||
m_instancingRenderer = new GLInstancingRenderer(maxNumObjectCapacity, maxShapeCapacityInBytes);
|
m_instancingRenderer = new GLInstancingRenderer(maxNumObjectCapacity, maxShapeCapacityInBytes);
|
||||||
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
m_instancingRenderer->init();
|
m_instancingRenderer->init();
|
||||||
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
m_instancingRenderer->resize(m_swWidth,m_swHeight);
|
m_instancingRenderer->resize(m_swWidth,m_swHeight);
|
||||||
m_instancingRenderer->InitShaders();
|
m_instancingRenderer->InitShaders();
|
||||||
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
m_instancingRenderer->setActiveCamera(&m_camera);
|
m_instancingRenderer->setActiveCamera(&m_camera);
|
||||||
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
m_instancingRenderer->updateCamera();
|
m_instancingRenderer->updateCamera();
|
||||||
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
m_instancingRenderer->setLightPosition(m_lightDirection);
|
m_instancingRenderer->setLightPosition(m_lightDirection);
|
||||||
|
m_window->endRendering();
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual ~EGLRendererVisualShapeConverterInternalData()
|
||||||
|
{
|
||||||
|
delete m_instancingRenderer;
|
||||||
|
m_window->closeWindow();
|
||||||
|
delete m_window;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -120,6 +120,10 @@ struct TinyRendererVisualShapeConverterInternalData
|
|||||||
m_segmentationMaskBuffer.resize(m_swWidth*m_swHeight,-1);
|
m_segmentationMaskBuffer.resize(m_swWidth*m_swHeight,-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual ~TinyRendererVisualShapeConverterInternalData()
|
||||||
|
{
|
||||||
|
printf("~TinyRendererVisualShapeConverterInternalData()\n");
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
11
setup.py
11
setup.py
@@ -43,7 +43,7 @@ CXX_FLAGS += '-DBT_ENABLE_ENET '
|
|||||||
CXX_FLAGS += '-DBT_ENABLE_CLSOCKET '
|
CXX_FLAGS += '-DBT_ENABLE_CLSOCKET '
|
||||||
CXX_FLAGS += '-DB3_DUMP_PYTHON_VERSION '
|
CXX_FLAGS += '-DB3_DUMP_PYTHON_VERSION '
|
||||||
CXX_FLAGS += '-DSTATIC_EGLRENDERER_PLUGIN ' #comment to disable static egl plugin
|
CXX_FLAGS += '-DSTATIC_EGLRENDERER_PLUGIN ' #comment to disable static egl plugin
|
||||||
CXX_FLAGS += '-DBT_USE_EGL ' # uncomment for EGL (old EGL versions fail)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -412,9 +412,10 @@ if 'STATIC_EGLRENDERER_PLUGIN' in CXX_FLAGS:
|
|||||||
sources += ['examples/SharedMemory/plugins/eglPlugin/eglRendererPlugin.cpp']\
|
sources += ['examples/SharedMemory/plugins/eglPlugin/eglRendererPlugin.cpp']\
|
||||||
+ ['examples/SharedMemory/plugins/eglPlugin/eglRendererVisualShapeConverter.cpp']
|
+ ['examples/SharedMemory/plugins/eglPlugin/eglRendererVisualShapeConverter.cpp']
|
||||||
|
|
||||||
|
|
||||||
if _platform == "linux" or _platform == "linux2":
|
if _platform == "linux" or _platform == "linux2":
|
||||||
|
print("linux!")
|
||||||
libraries += ['dl','pthread']
|
libraries += ['dl','pthread']
|
||||||
|
CXX_FLAGS += '-DBT_USE_EGL '
|
||||||
CXX_FLAGS += '-D_LINUX '
|
CXX_FLAGS += '-D_LINUX '
|
||||||
CXX_FLAGS += '-DGLEW_STATIC '
|
CXX_FLAGS += '-DGLEW_STATIC '
|
||||||
CXX_FLAGS += '-DGLEW_INIT_OPENGL11_FUNCTIONS=1 '
|
CXX_FLAGS += '-DGLEW_INIT_OPENGL11_FUNCTIONS=1 '
|
||||||
@@ -430,8 +431,8 @@ if _platform == "linux" or _platform == "linux2":
|
|||||||
if 'BT_USE_EGL' in CXX_FLAGS:
|
if 'BT_USE_EGL' in CXX_FLAGS:
|
||||||
# linking with bullet's Glew libraries causes segfault
|
# linking with bullet's Glew libraries causes segfault
|
||||||
# for some reason.
|
# for some reason.
|
||||||
sources += ['examples/ThirdPartyLibs/glad/egl.c']
|
sources += ['examples/ThirdPartyLibs/glad/egl.c']\
|
||||||
sources += ['examples/OpenGLWindow/EGLOpenGLWindow.cpp']
|
+ ['examples/OpenGLWindow/EGLOpenGLWindow.cpp']
|
||||||
|
|
||||||
elif _platform == "win32":
|
elif _platform == "win32":
|
||||||
print("win32!")
|
print("win32!")
|
||||||
@@ -503,7 +504,7 @@ setup(
|
|||||||
sources = sources,
|
sources = sources,
|
||||||
libraries = libraries,
|
libraries = libraries,
|
||||||
extra_compile_args=CXX_FLAGS.split(),
|
extra_compile_args=CXX_FLAGS.split(),
|
||||||
include_dirs = include_dirs + ["src","examples/ThirdPartyLibs","examples/ThirdPartyLibs/glad", "examples/ThirdPartyLibs/enet/include","examples/ThirdPartyLibs/clsocket/src"]
|
include_dirs = include_dirs + ["src","examples", "examples/ThirdPartyLibs","examples/ThirdPartyLibs/glad", "examples/ThirdPartyLibs/enet/include","examples/ThirdPartyLibs/clsocket/src"]
|
||||||
) ],
|
) ],
|
||||||
classifiers=['Development Status :: 5 - Production/Stable',
|
classifiers=['Development Status :: 5 - Production/Stable',
|
||||||
'License :: OSI Approved :: zlib/libpng License',
|
'License :: OSI Approved :: zlib/libpng License',
|
||||||
|
|||||||
Reference in New Issue
Block a user