diff --git a/src/api/l_physics_shapes.c b/src/api/l_physics_shapes.c index d133291f..2d9f49a8 100644 --- a/src/api/l_physics_shapes.c +++ b/src/api/l_physics_shapes.c @@ -402,7 +402,7 @@ static int l_lovrCompoundShapeAddShape(lua_State* L) { static int l_lovrCompoundShapeReplaceShape(lua_State* L) { CompoundShape* shape = luax_checktype(L, 1, CompoundShape); - uint32_t index = luax_checku32(L, 2); + uint32_t index = luax_checku32(L, 2) - 1; Shape* child = luax_checkshape(L, 3); float position[3], orientation[4]; int i = 4; diff --git a/src/modules/physics/physics_jolt.c b/src/modules/physics/physics_jolt.c index 7b778dca..2f2aa1cb 100644 --- a/src/modules/physics/physics_jolt.c +++ b/src/modules/physics/physics_jolt.c @@ -1041,6 +1041,7 @@ void lovrCompoundShapeReplaceShape(CompoundShape* shape, uint32_t index, Shape* lovrCheck(child != shape, "Don't put a CompoundShape inside itself! lol"); JPH_Vec3 pos = { position[0], position[1], position[2] }; JPH_Quat rot = { orientation[0], orientation[1], orientation[2], orientation[3] }; + lovrRelease(lovrCompoundShapeGetShape(shape, index), lovrShapeDestroy); JPH_MutableCompoundShape_ModifyShape2((JPH_MutableCompoundShape*) shape->shape, index, &pos, &rot, child->shape); lovrRetain(child); }