remove some memory leaks in example code.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
@@ -1030,12 +1037,14 @@ OpenGLExampleBrowser::~OpenGLExampleBrowser()
|
||||
|
||||
|
||||
|
||||
// delete m_internalData->m_profWindow;
|
||||
|
||||
|
||||
delete m_internalData;
|
||||
|
||||
gFileImporterByExtension.clear();
|
||||
gAllExamples = 0;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ UrdfParser::~UrdfParser()
|
||||
for (int i=0;i<m_tmpModels.size();i++)
|
||||
{
|
||||
cleanModel(m_tmpModels[i]);
|
||||
delete m_tmpModels[i];
|
||||
}
|
||||
m_sdfModels.clear();
|
||||
m_tmpModels.clear();
|
||||
@@ -540,13 +541,14 @@ bool UrdfParser::parseVisual(UrdfModel& model, UrdfVisual& visual, TiXmlElement*
|
||||
matPtr->m_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;
|
||||
}
|
||||
|
||||
@@ -311,6 +311,7 @@ void b3Win32ThreadSupport::stopThreads()
|
||||
WaitForSingleObject(threadStatus.m_eventCompletetHandle, INFINITE);
|
||||
}
|
||||
|
||||
delete threadStatus.m_lsMemory;
|
||||
|
||||
threadStatus.m_userPtr = 0;
|
||||
SetEvent(threadStatus.m_eventStartHandle);
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -34,6 +34,8 @@ template <typename T, typename U> 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 =
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
|
||||
PhysicsClientSharedMemory2::PhysicsClientSharedMemory2(SharedMemoryCommandProcessor* proc)
|
||||
:PhysicsDirect(proc)
|
||||
:PhysicsDirect(proc,false)
|
||||
{
|
||||
m_proc = proc;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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; i<m_data->m_bodyJointMap.size(); i++)
|
||||
{
|
||||
BodyJointInfoCache2** bodyJointsPtr = m_data->m_bodyJointMap.getAtIndex(i);
|
||||
if (bodyJointsPtr && *bodyJointsPtr)
|
||||
{
|
||||
BodyJointInfoCache2* bodyJoints = *bodyJointsPtr;
|
||||
for (int j = 0; j<bodyJoints->m_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; i<m_data->m_bodyJointMap.size(); i++)
|
||||
{
|
||||
BodyJointInfoCache2** bodyJointsPtr = m_data->m_bodyJointMap.getAtIndex(i);
|
||||
if (bodyJointsPtr && *bodyJointsPtr)
|
||||
{
|
||||
BodyJointInfoCache2* bodyJoints = *bodyJointsPtr;
|
||||
for (int j = 0; j<bodyJoints->m_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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -779,6 +779,7 @@ void PhysicsServerCommandProcessor::deleteDynamicsWorld()
|
||||
|
||||
for (int i=0;i<m_data->m_worldImporters.size();i++)
|
||||
{
|
||||
m_data->m_worldImporters[i]->deleteAllData();
|
||||
delete m_data->m_worldImporters[i];
|
||||
}
|
||||
m_data->m_worldImporters.clear();
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ public:
|
||||
newargv[argc+1] = t1;
|
||||
m_data = btCreateInProcessExampleBrowser(newargc,newargv);
|
||||
SharedMemoryInterface* shMem = btGetSharedMemoryInterface(m_data);
|
||||
|
||||
free(newargv);
|
||||
setSharedMemoryInterface(shMem);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;o<ptr->m_renderObjects.size();o++)
|
||||
{
|
||||
delete ptr->m_renderObjects[o];
|
||||
}
|
||||
}
|
||||
delete ptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user