fix posix memory release issues

fix compile problems on Mac OSX
reduce shared memory size on Mac (>512*1024 fails to allocate)
This commit is contained in:
Erwin Coumans
2018-05-02 15:39:16 -07:00
parent 1f6afcda30
commit 4a8ad1a54e
9 changed files with 45 additions and 9 deletions

View File

@@ -309,7 +309,7 @@ void* ExampleBrowserMemoryFunc()
void ExampleBrowserMemoryReleaseFunc(void* ptr) void ExampleBrowserMemoryReleaseFunc(void* ptr)
{ {
ExampleBrowserThreadLocalStorage* p = (ExampleBrowserThreadLocalStorage*) ptr; ExampleBrowserThreadLocalStorage* p = (ExampleBrowserThreadLocalStorage*) ptr;
delete ptr; delete p;
} }

View File

@@ -1032,6 +1032,11 @@ struct BulletMJCFImporterInternalData
//todo //todo
break; break;
} }
case URDF_GEOM_CDF:
{
//todo
break;
}
case URDF_GEOM_CYLINDER: case URDF_GEOM_CYLINDER:
case URDF_GEOM_CAPSULE: case URDF_GEOM_CAPSULE:
{ {
@@ -2541,6 +2546,11 @@ class btCompoundShape* BulletMJCFImporter::convertLinkCollisionShapes( int linkI
} }
break; break;
} }
case URDF_GEOM_CDF:
{
//todo
break;
}
case URDF_GEOM_UNKNOWN: case URDF_GEOM_UNKNOWN:
{ {
break; break;

View File

@@ -2,7 +2,8 @@
#include "../../OpenGLWindow/GLInstancingRenderer.h" #include "../../OpenGLWindow/GLInstancingRenderer.h"
#include "../../OpenGLWindow/GLInstanceGraphicsShape.h" #include "../../OpenGLWindow/GLInstanceGraphicsShape.h"
#include "btBulletDynamicsCommon.h" //#include "btBulletDynamicsCommon.h"
#include "LinearMath/btVector3.h"
#include "../../OpenGLWindow/SimpleOpenGL3App.h" #include "../../OpenGLWindow/SimpleOpenGL3App.h"
#include "Wavefront2GLInstanceGraphicsShape.h" #include "Wavefront2GLInstanceGraphicsShape.h"
#include "../../OpenGLWindow/GLInstancingRenderer.h" #include "../../OpenGLWindow/GLInstancingRenderer.h"

View File

@@ -21,7 +21,7 @@
void SampleThreadFunc(void* userPtr,void* lsMemory); void SampleThreadFunc(void* userPtr,void* lsMemory);
void* SamplelsMemoryFunc(); void* SamplelsMemoryFunc();
void SamplelsMemoryReleaseFunc(void* ptr);
#include <stdio.h> #include <stdio.h>
//#include "BulletMultiThreaded/PlatformDefinitions.h" //#include "BulletMultiThreaded/PlatformDefinitions.h"
@@ -34,6 +34,7 @@ b3ThreadSupportInterface* createThreadSupport(int numThreads)
b3PosixThreadSupport::ThreadConstructionInfo constructionInfo("testThreads", b3PosixThreadSupport::ThreadConstructionInfo constructionInfo("testThreads",
SampleThreadFunc, SampleThreadFunc,
SamplelsMemoryFunc, SamplelsMemoryFunc,
SamplelsMemoryReleaseFunc,
numThreads); numThreads);
b3ThreadSupportInterface* threadSupport = new b3PosixThreadSupport(constructionInfo); b3ThreadSupportInterface* threadSupport = new b3PosixThreadSupport(constructionInfo);
@@ -47,7 +48,7 @@ b3ThreadSupportInterface* createThreadSupport(int numThreads)
b3ThreadSupportInterface* createThreadSupport(int numThreads) b3ThreadSupportInterface* createThreadSupport(int numThreads)
{ {
b3Win32ThreadSupport::Win32ThreadConstructionInfo threadConstructionInfo("testThreads",SampleThreadFunc,SamplelsMemoryFunc,numThreads); b3Win32ThreadSupport::Win32ThreadConstructionInfo threadConstructionInfo("testThreads",SampleThreadFunc,SamplelsMemoryFunc,SamplelsMemoryReleaseFunc,numThreads);
b3Win32ThreadSupport* threadSupport = new b3Win32ThreadSupport(threadConstructionInfo); b3Win32ThreadSupport* threadSupport = new b3Win32ThreadSupport(threadConstructionInfo);
return threadSupport; return threadSupport;
@@ -155,7 +156,11 @@ void* SamplelsMemoryFunc()
return new SampleThreadLocalStorage; return new SampleThreadLocalStorage;
} }
void SamplelsMemoryReleaseFunc(void* ptr)
{
SampleThreadLocalStorage* p = (SampleThreadLocalStorage*) ptr;
delete p;
}

View File

@@ -251,7 +251,8 @@ void b3PosixThreadSupport::startThreads(ThreadConstructionInfo& threadConstructi
spuStatus.m_mainSemaphore = m_mainSemaphore; spuStatus.m_mainSemaphore = m_mainSemaphore;
spuStatus.m_lsMemory = threadConstructionInfo.m_lsMemoryFunc(); spuStatus.m_lsMemory = threadConstructionInfo.m_lsMemoryFunc();
spuStatus.m_userThreadFunc = threadConstructionInfo.m_userThreadFunc; spuStatus.m_userThreadFunc = threadConstructionInfo.m_userThreadFunc;
spuStatus.threadUsed = 0; spuStatus.m_lsMemoryReleaseFunc = threadConstructionInfo.m_lsMemoryReleaseFunc;
spuStatus.threadUsed = 0;
printf("started thread %d \n",i); printf("started thread %d \n",i);
@@ -277,7 +278,12 @@ void b3PosixThreadSupport::stopThreads()
destroySem(spuStatus.startSemaphore); destroySem(spuStatus.startSemaphore);
printf("semaphore destroyed\n"); printf("semaphore destroyed\n");
checkPThreadFunction(pthread_join(spuStatus.thread,0)); checkPThreadFunction(pthread_join(spuStatus.thread,0));
delete spuStatus.m_lsMemory;
if (spuStatus.m_lsMemoryReleaseFunc)
{
spuStatus.m_lsMemoryReleaseFunc( spuStatus.m_lsMemory);
}
} }
printf("destroy main semaphore\n"); printf("destroy main semaphore\n");
destroySem(m_mainSemaphore); destroySem(m_mainSemaphore);

View File

@@ -35,6 +35,7 @@ subject to the following restrictions:
typedef void (*b3PosixThreadFunc)(void* userPtr,void* lsMemory); typedef void (*b3PosixThreadFunc)(void* userPtr,void* lsMemory);
typedef void* (*b3PosixlsMemorySetupFunc)(); typedef void* (*b3PosixlsMemorySetupFunc)();
typedef void (*b3PosixlsMemoryReleaseFunc)(void* ptr);
// b3PosixThreadSupport helps to initialize/shutdown libspe2, start/stop SPU tasks and communication // b3PosixThreadSupport helps to initialize/shutdown libspe2, start/stop SPU tasks and communication
class b3PosixThreadSupport : public b3ThreadSupportInterface class b3PosixThreadSupport : public b3ThreadSupportInterface
@@ -55,6 +56,8 @@ public:
b3PosixThreadFunc m_userThreadFunc; b3PosixThreadFunc m_userThreadFunc;
void* m_userPtr; //for taskDesc etc void* m_userPtr; //for taskDesc etc
b3PosixlsMemoryReleaseFunc m_lsMemoryReleaseFunc;
void* m_lsMemory; //initialized using PosixLocalStoreMemorySetupFunc void* m_lsMemory; //initialized using PosixLocalStoreMemorySetupFunc
pthread_t thread; pthread_t thread;
@@ -83,12 +86,14 @@ public:
ThreadConstructionInfo(const char* uniqueName, ThreadConstructionInfo(const char* uniqueName,
b3PosixThreadFunc userThreadFunc, b3PosixThreadFunc userThreadFunc,
b3PosixlsMemorySetupFunc lsMemoryFunc, b3PosixlsMemorySetupFunc lsMemoryFunc,
b3PosixlsMemoryReleaseFunc lsMemoryReleaseFunc,
int numThreads=1, int numThreads=1,
int threadStackSize=65535 int threadStackSize=65535
) )
:m_uniqueName(uniqueName), :m_uniqueName(uniqueName),
m_userThreadFunc(userThreadFunc), m_userThreadFunc(userThreadFunc),
m_lsMemoryFunc(lsMemoryFunc), m_lsMemoryFunc(lsMemoryFunc),
m_lsMemoryReleaseFunc(lsMemoryReleaseFunc),
m_numThreads(numThreads), m_numThreads(numThreads),
m_threadStackSize(threadStackSize) m_threadStackSize(threadStackSize)
{ {
@@ -98,6 +103,8 @@ public:
const char* m_uniqueName; const char* m_uniqueName;
b3PosixThreadFunc m_userThreadFunc; b3PosixThreadFunc m_userThreadFunc;
b3PosixlsMemorySetupFunc m_lsMemoryFunc; b3PosixlsMemorySetupFunc m_lsMemoryFunc;
b3PosixlsMemoryReleaseFunc m_lsMemoryReleaseFunc;
int m_numThreads; int m_numThreads;
int m_threadStackSize; int m_threadStackSize;

View File

@@ -9693,10 +9693,13 @@ void PhysicsServerCommandProcessor::stepSimulationRealTime(double dtInSec,const
void PhysicsServerCommandProcessor::resetSimulation() void PhysicsServerCommandProcessor::resetSimulation()
{ {
//clean up all data //clean up all data
#ifndef SKIP_SOFT_BODY_MULTI_BODY_DYNAMICS_WORLD
if (m_data && m_data->m_dynamicsWorld) if (m_data && m_data->m_dynamicsWorld)
{ {
m_data->m_dynamicsWorld->getWorldInfo().m_sparsesdf.Reset(); m_data->m_dynamicsWorld->getWorldInfo().m_sparsesdf.Reset();
} }
#endif
if (m_data && m_data->m_guiHelper) if (m_data && m_data->m_guiHelper)
{ {
m_data->m_guiHelper->removeAllGraphicsInstances(); m_data->m_guiHelper->removeAllGraphicsInstances();

View File

@@ -170,7 +170,7 @@ bool PhysicsServerSharedMemory::connectSharedMemory( struct GUIHelperInterface*
} }
} else } else
{ {
b3Error("Cannot connect to shared memory"); //b3Error("Cannot connect to shared memory");
m_data->m_areConnected[block] = false; m_data->m_areConnected[block] = false;
} }
} while (counter++ < 10 && !m_data->m_areConnected[block]); } while (counter++ < 10 && !m_data->m_areConnected[block]);

View File

@@ -23,7 +23,11 @@
typedef unsigned long long int smUint64_t; typedef unsigned long long int smUint64_t;
#endif #endif
#define SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE (8*1024*1024) #ifdef __APPLE__
#define SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE (512*1024)
#else
#define SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE (8*1024*1024)
#endif
#define SHARED_MEMORY_SERVER_TEST_C #define SHARED_MEMORY_SERVER_TEST_C
#define MAX_DEGREE_OF_FREEDOM 128 #define MAX_DEGREE_OF_FREEDOM 128