diff --git a/examples/ExampleBrowser/GwenGUISupport/GwenProfileWindow.cpp b/examples/ExampleBrowser/GwenGUISupport/GwenProfileWindow.cpp index cce4ebacf..4cc6e63a6 100644 --- a/examples/ExampleBrowser/GwenGUISupport/GwenProfileWindow.cpp +++ b/examples/ExampleBrowser/GwenGUISupport/GwenProfileWindow.cpp @@ -312,7 +312,10 @@ void profileWindowSetVisible(MyProfileWindow* window, bool visible) void destroyProfileWindow(MyProfileWindow* window) { CProfileManager::Release_Iterator(window->profIter); + delete window->m_menuItems; delete window; + CProfileManager::CleanupMemory(); + } #endif //BT_NO_PROFILE diff --git a/examples/ExampleBrowser/InProcessExampleBrowser.cpp b/examples/ExampleBrowser/InProcessExampleBrowser.cpp index 5dde14f30..3060eaaee 100644 --- a/examples/ExampleBrowser/InProcessExampleBrowser.cpp +++ b/examples/ExampleBrowser/InProcessExampleBrowser.cpp @@ -389,6 +389,8 @@ void btShutDownExampleBrowser(btInProcessExampleBrowserInternalData* data) }; printf("btShutDownExampleBrowser stopping threads\n"); + data->m_threadSupport->deleteCriticalSection(data->m_args.m_cs); + delete data->m_threadSupport; delete data->m_sharedMem; delete data; diff --git a/examples/ExampleBrowser/OpenGLExampleBrowser.cpp b/examples/ExampleBrowser/OpenGLExampleBrowser.cpp index 6842e03c2..ee27e72e7 100644 --- a/examples/ExampleBrowser/OpenGLExampleBrowser.cpp +++ b/examples/ExampleBrowser/OpenGLExampleBrowser.cpp @@ -379,6 +379,7 @@ void deleteDemo() sCurrentDemo=0; delete s_guiHelper; s_guiHelper = 0; + // CProfileManager::CleanupMemory(); } } @@ -1014,9 +1015,15 @@ OpenGLExampleBrowser::~OpenGLExampleBrowser() delete s_app->m_2dCanvasInterface; s_app->m_2dCanvasInterface = 0; +#ifndef BT_NO_PROFILE + destroyProfileWindow(m_internalData->m_profWindow); +#endif + m_internalData->m_gui->exit(); + + delete m_internalData->m_gui; delete m_internalData->m_gwenRenderer; delete m_internalData->m_myTexLoader; @@ -1029,13 +1036,15 @@ OpenGLExampleBrowser::~OpenGLExampleBrowser() s_app = 0; - -// delete m_internalData->m_profWindow; - + + + delete m_internalData; gFileImporterByExtension.clear(); gAllExamples = 0; + + } diff --git a/examples/Importers/ImportURDFDemo/UrdfParser.cpp b/examples/Importers/ImportURDFDemo/UrdfParser.cpp index bcac5eec7..9f06dbfa0 100644 --- a/examples/Importers/ImportURDFDemo/UrdfParser.cpp +++ b/examples/Importers/ImportURDFDemo/UrdfParser.cpp @@ -18,6 +18,7 @@ UrdfParser::~UrdfParser() for (int i=0;im_name = "mat"; if (name_char) matPtr->m_name = name_char; + model.m_materials.insert(matPtr->m_name.c_str(),matPtr); TiXmlElement *diffuse = mat->FirstChildElement("diffuse"); if (diffuse) { std::string diffuseText = diffuse->GetText(); btVector4 rgba(1,0,0,1); parseVector4(rgba,diffuseText); matPtr->m_rgbaColor = rgba; - model.m_materials.insert(matPtr->m_name.c_str(),matPtr); + visual.m_materialName = matPtr->m_name; visual.m_hasLocalMaterial = true; } diff --git a/examples/MultiThreading/b3Win32ThreadSupport.cpp b/examples/MultiThreading/b3Win32ThreadSupport.cpp index 199533b1b..e8625be06 100644 --- a/examples/MultiThreading/b3Win32ThreadSupport.cpp +++ b/examples/MultiThreading/b3Win32ThreadSupport.cpp @@ -311,6 +311,7 @@ void b3Win32ThreadSupport::stopThreads() WaitForSingleObject(threadStatus.m_eventCompletetHandle, INFINITE); } + delete threadStatus.m_lsMemory; threadStatus.m_userPtr = 0; SetEvent(threadStatus.m_eventStartHandle); diff --git a/examples/RoboticsLearning/b3RobotSimAPI.cpp b/examples/RoboticsLearning/b3RobotSimAPI.cpp index f4ad1fcb5..a2ab15632 100644 --- a/examples/RoboticsLearning/b3RobotSimAPI.cpp +++ b/examples/RoboticsLearning/b3RobotSimAPI.cpp @@ -911,7 +911,7 @@ bool b3RobotSimAPI::connect(GUIHelperInterface* guiHelper) else { PhysicsServerCommandProcessor* sdk = new PhysicsServerCommandProcessor; - m_data->m_clientServerDirect = new PhysicsDirect(sdk); + m_data->m_clientServerDirect = new PhysicsDirect(sdk,true); bool connected = m_data->m_clientServerDirect->connect(guiHelper); m_data->m_physicsClient = (b3PhysicsClientHandle)m_data->m_clientServerDirect; diff --git a/examples/SharedMemory/BodyJointInfoUtility.h b/examples/SharedMemory/BodyJointInfoUtility.h index 4488d68fc..a959b40dd 100644 --- a/examples/SharedMemory/BodyJointInfoUtility.h +++ b/examples/SharedMemory/BodyJointInfoUtility.h @@ -34,6 +34,8 @@ template void addJointInfoFromMultiBodyData(const T* mb { { b3JointInfo info; + info.m_jointName = 0; + info.m_linkName = 0; info.m_flags = 0; info.m_jointIndex = link; info.m_qIndex = diff --git a/examples/SharedMemory/PhysicsClientSharedMemory2.cpp b/examples/SharedMemory/PhysicsClientSharedMemory2.cpp index 7eea2298d..3e4c6cf73 100644 --- a/examples/SharedMemory/PhysicsClientSharedMemory2.cpp +++ b/examples/SharedMemory/PhysicsClientSharedMemory2.cpp @@ -9,7 +9,7 @@ PhysicsClientSharedMemory2::PhysicsClientSharedMemory2(SharedMemoryCommandProcessor* proc) - :PhysicsDirect(proc) + :PhysicsDirect(proc,false) { m_proc = proc; } diff --git a/examples/SharedMemory/PhysicsClientSharedMemory2_C_API.cpp b/examples/SharedMemory/PhysicsClientSharedMemory2_C_API.cpp index 7323205d0..0645795e8 100644 --- a/examples/SharedMemory/PhysicsClientSharedMemory2_C_API.cpp +++ b/examples/SharedMemory/PhysicsClientSharedMemory2_C_API.cpp @@ -8,7 +8,7 @@ b3PhysicsClientHandle b3ConnectSharedMemory2(int key) SharedMemoryCommandProcessor* cmdProc = new SharedMemoryCommandProcessor(); cmdProc->setSharedMemoryKey(key); - PhysicsDirect* cl = new PhysicsDirect(cmdProc); + PhysicsDirect* cl = new PhysicsDirect(cmdProc,true); cl->setSharedMemoryKey(key); diff --git a/examples/SharedMemory/PhysicsClientUDP_C_API.cpp b/examples/SharedMemory/PhysicsClientUDP_C_API.cpp index f48fdedb8..824c77f33 100644 --- a/examples/SharedMemory/PhysicsClientUDP_C_API.cpp +++ b/examples/SharedMemory/PhysicsClientUDP_C_API.cpp @@ -10,7 +10,7 @@ b3PhysicsClientHandle b3ConnectPhysicsUDP(const char* hostName, int port) UdpNetworkedPhysicsProcessor* udp = new UdpNetworkedPhysicsProcessor(hostName, port); - PhysicsDirect* direct = new PhysicsDirect(udp); + PhysicsDirect* direct = new PhysicsDirect(udp,true); bool connected = direct->connect(); printf("direct!\n"); diff --git a/examples/SharedMemory/PhysicsDirect.cpp b/examples/SharedMemory/PhysicsDirect.cpp index 2dd96b161..1fc760482 100644 --- a/examples/SharedMemory/PhysicsDirect.cpp +++ b/examples/SharedMemory/PhysicsDirect.cpp @@ -62,11 +62,11 @@ struct PhysicsDirectInternalData } }; -PhysicsDirect::PhysicsDirect(PhysicsCommandProcessorInterface* physSdk) +PhysicsDirect::PhysicsDirect(PhysicsCommandProcessorInterface* physSdk, bool passSdkOwnership) { m_data = new PhysicsDirectInternalData; m_data->m_commandProcessor = physSdk; - m_data->m_ownsCommandProcessor = false; + m_data->m_ownsCommandProcessor = passSdkOwnership; } PhysicsDirect::~PhysicsDirect() @@ -79,9 +79,40 @@ PhysicsDirect::~PhysicsDirect() { delete m_data->m_commandProcessor; } + + resetData(); + + + delete m_data; } +void PhysicsDirect::resetData() +{ + m_data->m_debugLinesFrom.clear(); + m_data->m_debugLinesTo.clear(); + m_data->m_debugLinesColor.clear(); + for (int i = 0; im_bodyJointMap.size(); i++) + { + BodyJointInfoCache2** bodyJointsPtr = m_data->m_bodyJointMap.getAtIndex(i); + if (bodyJointsPtr && *bodyJointsPtr) + { + BodyJointInfoCache2* bodyJoints = *bodyJointsPtr; + for (int j = 0; jm_jointInfo.size(); j++) { + if (bodyJoints->m_jointInfo[j].m_jointName) + { + free(bodyJoints->m_jointInfo[j].m_jointName); + } + if (bodyJoints->m_jointInfo[j].m_linkName) + { + free(bodyJoints->m_jointInfo[j].m_linkName); + } + } + delete (*bodyJointsPtr); + } + } + m_data->m_bodyJointMap.clear(); +} // return true if connection succesfull, can also check 'isConnected' bool PhysicsDirect::connect() @@ -525,6 +556,14 @@ bool PhysicsDirect::processCamera(const struct SharedMemoryCommand& orgCommand) void PhysicsDirect::processBodyJointInfo(int bodyUniqueId, const SharedMemoryStatus& serverCmd) { + + BodyJointInfoCache2** cachePtr = m_data->m_bodyJointMap[bodyUniqueId]; + //don't process same bodyUniqueId multiple times + if (cachePtr) + { + return; + } + bParse::btBulletFile bf( &m_data->m_bulletStreamDataServerToClient[0], serverCmd.m_numDataStreamBytes); @@ -627,30 +666,7 @@ void PhysicsDirect::postProcessStatus(const struct SharedMemoryStatus& serverCmd } case CMD_RESET_SIMULATION_COMPLETED: { - m_data->m_debugLinesFrom.clear(); - m_data->m_debugLinesTo.clear(); - m_data->m_debugLinesColor.clear(); - for (int i = 0; im_bodyJointMap.size(); i++) - { - BodyJointInfoCache2** bodyJointsPtr = m_data->m_bodyJointMap.getAtIndex(i); - if (bodyJointsPtr && *bodyJointsPtr) - { - BodyJointInfoCache2* bodyJoints = *bodyJointsPtr; - for (int j = 0; jm_jointInfo.size(); j++) { - if (bodyJoints->m_jointInfo[j].m_jointName) - { - free(bodyJoints->m_jointInfo[j].m_jointName); - } - if (bodyJoints->m_jointInfo[j].m_linkName) - { - free(bodyJoints->m_jointInfo[j].m_linkName); - } - } - delete (*bodyJointsPtr); - } - } - m_data->m_bodyJointMap.clear(); - + resetData(); break; } diff --git a/examples/SharedMemory/PhysicsDirect.h b/examples/SharedMemory/PhysicsDirect.h index 6b6b526be..bdaced974 100644 --- a/examples/SharedMemory/PhysicsDirect.h +++ b/examples/SharedMemory/PhysicsDirect.h @@ -28,9 +28,10 @@ protected: void postProcessStatus(const struct SharedMemoryStatus& serverCmd); + void resetData(); public: - PhysicsDirect(class PhysicsCommandProcessorInterface* physSdk); + PhysicsDirect(class PhysicsCommandProcessorInterface* physSdk, bool passSdkOwnership); virtual ~PhysicsDirect(); diff --git a/examples/SharedMemory/PhysicsDirectC_API.cpp b/examples/SharedMemory/PhysicsDirectC_API.cpp index 61ceef26f..ded3b81f2 100644 --- a/examples/SharedMemory/PhysicsDirectC_API.cpp +++ b/examples/SharedMemory/PhysicsDirectC_API.cpp @@ -11,7 +11,7 @@ b3PhysicsClientHandle b3ConnectPhysicsDirect() { PhysicsServerCommandProcessor* sdk = new PhysicsServerCommandProcessor; - PhysicsDirect* direct = new PhysicsDirect(sdk); + PhysicsDirect* direct = new PhysicsDirect(sdk,true); bool connected = direct->connect(); return (b3PhysicsClientHandle )direct; } diff --git a/examples/SharedMemory/PhysicsServerCommandProcessor.cpp b/examples/SharedMemory/PhysicsServerCommandProcessor.cpp index 7f98b8dfb..1e0844b51 100644 --- a/examples/SharedMemory/PhysicsServerCommandProcessor.cpp +++ b/examples/SharedMemory/PhysicsServerCommandProcessor.cpp @@ -779,6 +779,7 @@ void PhysicsServerCommandProcessor::deleteDynamicsWorld() for (int i=0;im_worldImporters.size();i++) { + m_data->m_worldImporters[i]->deleteAllData(); delete m_data->m_worldImporters[i]; } m_data->m_worldImporters.clear(); diff --git a/examples/SharedMemory/PhysicsServerExample.cpp b/examples/SharedMemory/PhysicsServerExample.cpp index 6eee8dad3..5b6588daf 100644 --- a/examples/SharedMemory/PhysicsServerExample.cpp +++ b/examples/SharedMemory/PhysicsServerExample.cpp @@ -573,7 +573,7 @@ public: virtual ~MultiThreadedOpenGLGuiHelper() { - delete m_childGuiHelper; + //delete m_childGuiHelper; } void setCriticalSection(b3CriticalSection* cs) @@ -1152,9 +1152,12 @@ PhysicsServerExample::~PhysicsServerExample() #ifdef BT_ENABLE_VR delete m_tinyVrGui; #endif + + bool deInitializeSharedMemory = true; m_physicsServer.disconnectSharedMemory(deInitializeSharedMemory); m_isConnected = false; + delete m_multiThreadedHelper; } bool PhysicsServerExample::isConnected() @@ -1247,6 +1250,11 @@ void PhysicsServerExample::exitPhysics() printf("stopping threads\n"); + m_threadSupport->deleteCriticalSection(m_args[0].m_cs); + m_threadSupport->deleteCriticalSection(m_args[0].m_cs2); + m_threadSupport->deleteCriticalSection(m_args[0].m_cs3); + m_threadSupport->deleteCriticalSection(m_args[0].m_csGUI); + delete m_threadSupport; m_threadSupport = 0; diff --git a/examples/SharedMemory/SharedMemoryInProcessPhysicsC_API.cpp b/examples/SharedMemory/SharedMemoryInProcessPhysicsC_API.cpp index deb8349cf..1bd307b4e 100644 --- a/examples/SharedMemory/SharedMemoryInProcessPhysicsC_API.cpp +++ b/examples/SharedMemory/SharedMemoryInProcessPhysicsC_API.cpp @@ -82,7 +82,7 @@ public: newargv[argc+1] = t1; m_data = btCreateInProcessExampleBrowser(newargc,newargv); SharedMemoryInterface* shMem = btGetSharedMemoryInterface(m_data); - + free(newargv); setSharedMemoryInterface(shMem); } diff --git a/examples/SharedMemory/TinyRendererVisualShapeConverter.cpp b/examples/SharedMemory/TinyRendererVisualShapeConverter.cpp index 830e629e8..0b3c59703 100644 --- a/examples/SharedMemory/TinyRendererVisualShapeConverter.cpp +++ b/examples/SharedMemory/TinyRendererVisualShapeConverter.cpp @@ -122,6 +122,7 @@ TinyRendererVisualShapeConverter::TinyRendererVisualShapeConverter() } TinyRendererVisualShapeConverter::~TinyRendererVisualShapeConverter() { + resetAll(); delete m_data; } @@ -972,6 +973,13 @@ void TinyRendererVisualShapeConverter::resetAll() if (ptrptr && *ptrptr) { TinyRendererObjectArray* ptr = *ptrptr; + if (ptr) + { + for (int o=0;om_renderObjects.size();o++) + { + delete ptr->m_renderObjects[o]; + } + } delete ptr; } } diff --git a/test/SharedMemory/test.c b/test/SharedMemory/test.c index 6037b693e..f7eeb18ad 100644 --- a/test/SharedMemory/test.c +++ b/test/SharedMemory/test.c @@ -1,3 +1,4 @@ + //#include "SharedMemoryCommands.h" #ifdef PHYSICS_SHARED_MEMORY #include "SharedMemory/PhysicsClientC_API.h" @@ -244,6 +245,17 @@ void testSharedMemory(b3PhysicsClientHandle sm) } } + { + b3SharedMemoryCommandHandle command; + b3SharedMemoryStatusHandle statusHandle; + int width = 1024; + int height = 1024; + + command = b3InitRequestCameraImage(sm); + + b3RequestCameraImageSetPixelResolution(command, width, height); + statusHandle = b3SubmitClientCommandAndWaitStatus(sm, command); + } if (b3CanSubmitCommand(sm)) { b3SharedMemoryStatusHandle state = b3SubmitClientCommandAndWaitStatus(sm, b3RequestActualStateCommandInit(sm,bodyIndex));