Fix memory leak due to batchRayCast never deleting the btTaskScheduler.
(and issue with TaskScheduler/btTaskScheduler.cpp, add JobQueue::exit, call it first, since it uses the m_threadSupport which was deleted before the destrucor was called. Use a hashmap to store user timers, to avoid allocating many identical strings.
This commit is contained in:
@@ -49,7 +49,7 @@ struct PhysicsClientSharedMemoryInternalData {
|
||||
SharedMemoryBlock* m_testBlock1;
|
||||
|
||||
btAlignedObjectArray<CProfileSample* > m_profileTimings;
|
||||
btAlignedObjectArray<std::string* > m_profileTimingStrings;
|
||||
btHashMap<btHashString, std::string*> m_profileTimingStringArray;
|
||||
|
||||
btHashMap<btHashInt,BodyJointInfoCache*> m_bodyJointMap;
|
||||
btHashMap<btHashInt,b3UserConstraint> m_userConstraintInfoMap;
|
||||
@@ -221,6 +221,16 @@ PhysicsClientSharedMemory::~PhysicsClientSharedMemory() {
|
||||
}
|
||||
resetData();
|
||||
|
||||
for (int i=0;i<m_data->m_profileTimingStringArray.size();i++)
|
||||
{
|
||||
std::string** str = m_data->m_profileTimingStringArray.getAtIndex(i);
|
||||
if (str)
|
||||
{
|
||||
delete *str;
|
||||
}
|
||||
}
|
||||
m_data->m_profileTimingStringArray.clear();
|
||||
|
||||
if (m_data->m_ownsSharedMemory)
|
||||
{
|
||||
delete m_data->m_sharedMemory;
|
||||
@@ -239,6 +249,8 @@ void PhysicsClientSharedMemory::removeCachedBody(int bodyUniqueId)
|
||||
}
|
||||
void PhysicsClientSharedMemory::resetData()
|
||||
{
|
||||
|
||||
|
||||
m_data->m_debugLinesFrom.clear();
|
||||
m_data->m_debugLinesTo.clear();
|
||||
m_data->m_debugLinesColor.clear();
|
||||
@@ -1916,10 +1928,17 @@ void PhysicsClientSharedMemory::getUserDataInfo(int bodyUniqueId, int linkIndex,
|
||||
|
||||
void PhysicsClientSharedMemory::pushProfileTiming(const char* timingName)
|
||||
{
|
||||
std::string* str = new std::string(timingName);
|
||||
m_data->m_profileTimingStrings.push_back(str);
|
||||
std::string** strPtr = m_data->m_profileTimingStringArray[timingName];
|
||||
std::string* str = 0;
|
||||
if (strPtr)
|
||||
{
|
||||
str = *strPtr;
|
||||
} else
|
||||
{
|
||||
str = new std::string(timingName);
|
||||
m_data->m_profileTimingStringArray.insert(timingName,str);
|
||||
}
|
||||
m_data->m_profileTimings.push_back(new CProfileSample(str->c_str()));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ struct PhysicsDirectInternalData
|
||||
btHashMap<btHashInt,b3UserConstraint> m_userConstraintInfoMap;
|
||||
|
||||
btAlignedObjectArray<CProfileSample* > m_profileTimings;
|
||||
btAlignedObjectArray<std::string* > m_profileTimingStrings;
|
||||
btHashMap<btHashString, std::string*> m_profileTimingStringArray;
|
||||
|
||||
char m_bulletStreamDataServerToClient[SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE];
|
||||
btAlignedObjectArray<double> m_cachedMassMatrix;
|
||||
@@ -117,11 +117,15 @@ PhysicsDirect::PhysicsDirect(PhysicsCommandProcessorInterface* physSdk, bool pas
|
||||
|
||||
PhysicsDirect::~PhysicsDirect()
|
||||
{
|
||||
for (int i=0;i<m_data->m_profileTimingStrings.size();i++)
|
||||
for (int i=0;i<m_data->m_profileTimingStringArray.size();i++)
|
||||
{
|
||||
delete m_data->m_profileTimingStrings[i];
|
||||
std::string** str = m_data->m_profileTimingStringArray.getAtIndex(i);
|
||||
if (str)
|
||||
{
|
||||
delete *str;
|
||||
}
|
||||
}
|
||||
m_data->m_profileTimingStrings.clear();
|
||||
m_data->m_profileTimingStringArray.clear();
|
||||
|
||||
if (m_data->m_commandProcessor->isConnected())
|
||||
{
|
||||
@@ -1567,8 +1571,16 @@ void PhysicsDirect::getUserDataInfo(int bodyUniqueId, int linkIndex, int userDat
|
||||
|
||||
void PhysicsDirect::pushProfileTiming(const char* timingName)
|
||||
{
|
||||
std::string* str = new std::string(timingName);
|
||||
m_data->m_profileTimingStrings.push_back(str);
|
||||
std::string** strPtr = m_data->m_profileTimingStringArray[timingName];
|
||||
std::string* str = 0;
|
||||
if (strPtr)
|
||||
{
|
||||
str = *strPtr;
|
||||
} else
|
||||
{
|
||||
str = new std::string(timingName);
|
||||
m_data->m_profileTimingStringArray.insert(timingName,str);
|
||||
}
|
||||
m_data->m_profileTimings.push_back(new CProfileSample(str->c_str()));
|
||||
}
|
||||
|
||||
|
||||
@@ -247,3 +247,11 @@ void PhysicsLoopBack::getUserDataInfo(int bodyUniqueId, int linkIndex, int userD
|
||||
m_data->m_physicsClient->getUserDataInfo(bodyUniqueId, linkIndex, userDataIndex, keyOut, userDataIdOut);
|
||||
}
|
||||
|
||||
void PhysicsLoopBack::pushProfileTiming(const char* timingName)
|
||||
{
|
||||
m_data->m_physicsClient->pushProfileTiming(timingName);
|
||||
}
|
||||
void PhysicsLoopBack::popProfileTiming()
|
||||
{
|
||||
m_data->m_physicsClient->popProfileTiming();
|
||||
}
|
||||
@@ -93,6 +93,9 @@ public:
|
||||
virtual int getCachedUserDataId(int bodyUniqueId, int linkIndex, const char *key) const;
|
||||
virtual int getNumUserData(int bodyUniqueId, int linkIndex) const;
|
||||
virtual void getUserDataInfo(int bodyUniqueId, int linkIndex, int userDataIndex, const char **keyOut, int *userDataIdOut) const;
|
||||
|
||||
virtual void pushProfileTiming(const char* timingName);
|
||||
virtual void popProfileTiming();
|
||||
};
|
||||
|
||||
#endif //PHYSICS_LOOP_BACK_H
|
||||
|
||||
@@ -1659,6 +1659,8 @@ struct PhysicsServerCommandProcessorInternalData
|
||||
b3HashMap<b3HashString, char*> m_profileEvents;
|
||||
b3HashMap<b3HashString, UrdfVisualShapeCache> m_cachedVUrdfisualShapes;
|
||||
|
||||
btITaskScheduler* m_scheduler;
|
||||
|
||||
PhysicsServerCommandProcessorInternalData(PhysicsCommandProcessorInterface* proc)
|
||||
:m_pluginManager(proc),
|
||||
m_useRealTimeSimulation(false),
|
||||
@@ -1686,7 +1688,8 @@ struct PhysicsServerCommandProcessorInternalData
|
||||
m_pickedBody(0),
|
||||
m_pickedConstraint(0),
|
||||
m_pickingMultiBodyPoint2Point(0),
|
||||
m_pdControlPlugin(-1)
|
||||
m_pdControlPlugin(-1),
|
||||
m_scheduler(0)
|
||||
{
|
||||
|
||||
{
|
||||
@@ -1782,11 +1785,11 @@ PhysicsServerCommandProcessor::PhysicsServerCommandProcessor()
|
||||
|
||||
#ifdef BT_THREADSAFE
|
||||
if (btGetTaskScheduler() == 0) {
|
||||
btITaskScheduler *scheduler = btCreateDefaultTaskScheduler();
|
||||
if (scheduler == 0) {
|
||||
scheduler = btGetSequentialTaskScheduler();
|
||||
m_data->m_scheduler = btCreateDefaultTaskScheduler();
|
||||
if (m_data->m_scheduler == 0) {
|
||||
m_data->m_scheduler = btGetSequentialTaskScheduler();
|
||||
}
|
||||
btSetTaskScheduler(scheduler);
|
||||
btSetTaskScheduler(m_data->m_scheduler);
|
||||
}
|
||||
#endif //BT_THREADSAFE
|
||||
}
|
||||
@@ -1804,6 +1807,9 @@ PhysicsServerCommandProcessor::~PhysicsServerCommandProcessor()
|
||||
char* event = *m_data->m_profileEvents.getAtIndex(i);
|
||||
delete[] event;
|
||||
}
|
||||
if (m_data->m_scheduler)
|
||||
delete m_data->m_scheduler;
|
||||
|
||||
delete m_data;
|
||||
}
|
||||
|
||||
|
||||
@@ -209,13 +209,19 @@ public:
|
||||
}
|
||||
~JobQueue()
|
||||
{
|
||||
freeJobMem();
|
||||
exit();
|
||||
}
|
||||
void exit()
|
||||
{
|
||||
freeJobMem();
|
||||
if (m_queueLock && m_threadSupport)
|
||||
{
|
||||
m_threadSupport->deleteCriticalSection(m_queueLock);
|
||||
m_queueLock = NULL;
|
||||
m_threadSupport = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void init(btThreadSupportInterface* threadSup, btAlignedObjectArray<JobQueue>* contextArray)
|
||||
{
|
||||
m_threadSupport = threadSup;
|
||||
@@ -448,6 +454,12 @@ public:
|
||||
virtual ~btTaskSchedulerDefault()
|
||||
{
|
||||
waitForWorkersToSleep();
|
||||
|
||||
for ( int i = 0; i < m_jobQueues.size(); ++i )
|
||||
{
|
||||
m_jobQueues[i].exit();
|
||||
}
|
||||
|
||||
if (m_threadSupport)
|
||||
{
|
||||
delete m_threadSupport;
|
||||
|
||||
Reference in New Issue
Block a user