Fixed objects which store Lua callback functions to avoid attempting to use dead coroutines when deleting the reference to the callback function. Should fix crashes when coroutines are mixed with those objects.

Also improved the performance of World:rayCast and World:queryBoundingBox.
This commit is contained in:
Alex Szpakowski
2015-07-18 03:26:07 -03:00
parent 64b9d40f00
commit 2cce18946d
14 changed files with 139 additions and 122 deletions
+17 -6
View File
@@ -70,6 +70,7 @@ public:
{
public:
Reference *ref;
lua_State *L;
ContactCallback();
~ContactCallback();
void process(b2Contact *contact, const b2ContactImpulse *impulse = NULL);
@@ -79,6 +80,7 @@ public:
{
public:
Reference *ref;
lua_State *L;
ContactFilter();
~ContactFilter();
bool process(Fixture *a, Fixture *b);
@@ -87,19 +89,23 @@ public:
class QueryCallback : public b2QueryCallback
{
public:
Reference *ref;
QueryCallback();
QueryCallback(lua_State *L, int idx);
~QueryCallback();
virtual bool ReportFixture(b2Fixture *fixture);
private:
lua_State *L;
int funcidx;
};
class RayCastCallback : public b2RayCastCallback
{
public:
Reference *ref;
RayCastCallback();
RayCastCallback(lua_State *L, int idx);
~RayCastCallback();
virtual float32 ReportFixture(b2Fixture *fixture, const b2Vec2 &point, const b2Vec2 &normal, float32 fraction);
private:
lua_State *L;
int funcidx;
};
/**
@@ -157,6 +163,13 @@ public:
**/
int getCallbacks(lua_State *L);
/**
* Updates the Lua thread/coroutine used when callbacks are executed in
* the update method. This should be called in the same Lua function which
* calls update().
**/
void setCallbacksL(lua_State *L);
/**
* Sets the ContactFilter callback.
**/
@@ -281,8 +294,6 @@ private:
// Contact callbacks.
ContactCallback begin, end, presolve, postsolve;
ContactFilter filter;
QueryCallback query;
RayCastCallback raycast;
};
} // box2d