Merge default into minor

--HG--
branch : minor
This commit is contained in:
Alex Szpakowski
2017-04-30 00:37:26 -03:00
11 changed files with 124 additions and 37 deletions
+26 -11
View File
@@ -43,11 +43,11 @@ Fixture::Fixture(Body *body, Shape *shape, float density)
: body(body)
, fixture(nullptr)
{
data = new fixtureudata();
data->ref = nullptr;
udata = new fixtureudata();
udata->ref = nullptr;
b2FixtureDef def;
def.shape = shape->shape;
def.userData = (void *)data;
def.userData = (void *)udata;
def.density = density;
fixture = body->body->CreateFixture(&def);
this->retain();
@@ -57,7 +57,7 @@ Fixture::Fixture(Body *body, Shape *shape, float density)
Fixture::Fixture(b2Fixture *f)
: fixture(f)
{
data = (fixtureudata *)f->GetUserData();
udata = (fixtureudata *)f->GetUserData();
body = (Body *)Memoizer::find(f->GetBody());
if (!body)
body = new Body(f->GetBody());
@@ -67,10 +67,13 @@ Fixture::Fixture(b2Fixture *f)
Fixture::~Fixture()
{
if (data != nullptr)
delete data->ref;
if (!udata)
return;
delete data;
if (udata->ref)
delete udata->ref;
delete udata;
}
Shape::Type Fixture::getType() const
@@ -241,16 +244,24 @@ int Fixture::setUserData(lua_State *L)
{
love::luax_assert_argc(L, 1, 1);
delete data->ref;
data->ref = new Reference(L);
if (udata == nullptr)
{
udata = new fixtureudata();
fixture->SetUserData((void *) udata);
}
if(!udata->ref)
udata->ref = new Reference();
udata->ref->ref(L);
return 0;
}
int Fixture::getUserData(lua_State *L)
{
if (data->ref != nullptr)
data->ref->push(L);
if (udata->ref != nullptr)
udata->ref->push(L);
else
lua_pushnil(L);
@@ -323,6 +334,10 @@ void Fixture::destroy(bool implicit)
Memoizer::remove(fixture);
fixture = nullptr;
// Remove userdata reference to avoid it sticking around after GC
if (udata && udata->ref)
udata->ref->unref();
// Box2D fixture destroyed. Release its reference to the love Fixture.
this->release();
}