avoid memory leaks, even if a the python interpreter exits without calling 'disconnect' on all physics servers
(register a Py_AtExit function that cleans all up), to avoid memory leaks
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
#include "vld.h"
|
||||||
#include "../SharedMemory/PhysicsClientC_API.h"
|
#include "../SharedMemory/PhysicsClientC_API.h"
|
||||||
#include "../SharedMemory/PhysicsDirectC_API.h"
|
#include "../SharedMemory/PhysicsDirectC_API.h"
|
||||||
#include "../SharedMemory/SharedMemoryInProcessPhysicsC_API.h"
|
#include "../SharedMemory/SharedMemoryInProcessPhysicsC_API.h"
|
||||||
@@ -398,6 +399,22 @@ static PyObject* pybullet_disconnectPhysicsServer(PyObject* self,
|
|||||||
return Py_None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void b3pybulletExitFunc()
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for (i=0;i<MAX_PHYSICS_CLIENTS;i++)
|
||||||
|
{
|
||||||
|
if (sPhysicsClients1[i])
|
||||||
|
{
|
||||||
|
b3DisconnectSharedMemory(sPhysicsClients1[i]);
|
||||||
|
sPhysicsClients1[i] = 0;
|
||||||
|
sNumPhysicsClients--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static PyObject* pybullet_saveWorld(PyObject* self, PyObject* args, PyObject* keywds)
|
static PyObject* pybullet_saveWorld(PyObject* self, PyObject* args, PyObject* keywds)
|
||||||
{
|
{
|
||||||
const char* worldFileName = "";
|
const char* worldFileName = "";
|
||||||
@@ -5453,6 +5470,10 @@ initpybullet(void)
|
|||||||
Py_INCREF(SpamError);
|
Py_INCREF(SpamError);
|
||||||
PyModule_AddObject(m, "error", SpamError);
|
PyModule_AddObject(m, "error", SpamError);
|
||||||
|
|
||||||
|
|
||||||
|
Py_AtExit( b3pybulletExitFunc );
|
||||||
|
|
||||||
|
|
||||||
#ifdef PYBULLET_USE_NUMPY
|
#ifdef PYBULLET_USE_NUMPY
|
||||||
// Initialize numpy array.
|
// Initialize numpy array.
|
||||||
import_array();
|
import_array();
|
||||||
|
|||||||
Reference in New Issue
Block a user