Skip to content

Commit

Permalink
Store ObjectID instead of raw pointer for Shape Owners
Browse files Browse the repository at this point in the history
  • Loading branch information
timothyqiu committed Jan 25, 2022
1 parent cb9854d commit fa96505
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions scene/2d/collision_object_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ uint32_t CollisionObject2D::create_shape_owner(Object *p_owner) {
id = shapes.back()->key() + 1;
}

sd.owner = p_owner;
sd.owner_id = p_owner ? p_owner->get_instance_id() : 0;

shapes[id] = sd;

Expand Down Expand Up @@ -283,7 +283,7 @@ Transform2D CollisionObject2D::shape_owner_get_transform(uint32_t p_owner) const
Object *CollisionObject2D::shape_owner_get_owner(uint32_t p_owner) const {
ERR_FAIL_COND_V(!shapes.has(p_owner), nullptr);

return shapes[p_owner].owner;
return ObjectDB::get_instance(shapes[p_owner].owner_id);
}

void CollisionObject2D::shape_owner_add_shape(uint32_t p_owner, const Ref<Shape2D> &p_shape) {
Expand Down
4 changes: 2 additions & 2 deletions scene/2d/collision_object_2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class CollisionObject2D : public Node2D {
bool pickable;

struct ShapeData {
Object *owner;
ObjectID owner_id;
Transform2D xform;
struct Shape {
Ref<Shape2D> shape;
Expand All @@ -61,7 +61,7 @@ class CollisionObject2D : public Node2D {
disabled = false;
one_way_collision = false;
one_way_collision_margin = 0;
owner = nullptr;
owner_id = 0;
}
};

Expand Down
4 changes: 2 additions & 2 deletions scene/3d/collision_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ uint32_t CollisionObject::create_shape_owner(Object *p_owner) {
id = shapes.back()->key() + 1;
}

sd.owner = p_owner;
sd.owner_id = p_owner ? p_owner->get_instance_id() : 0;

shapes[id] = sd;

Expand Down Expand Up @@ -442,7 +442,7 @@ Transform CollisionObject::shape_owner_get_transform(uint32_t p_owner) const {
Object *CollisionObject::shape_owner_get_owner(uint32_t p_owner) const {
ERR_FAIL_COND_V(!shapes.has(p_owner), nullptr);

return shapes[p_owner].owner;
return ObjectDB::get_instance(shapes[p_owner].owner_id);
}

void CollisionObject::shape_owner_add_shape(uint32_t p_owner, const Ref<Shape> &p_shape) {
Expand Down
4 changes: 2 additions & 2 deletions scene/3d/collision_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class CollisionObject : public Spatial {
RID rid;

struct ShapeData {
Object *owner;
ObjectID owner_id;
Transform xform;
struct ShapeBase {
RID debug_shape;
Expand All @@ -58,7 +58,7 @@ class CollisionObject : public Spatial {

ShapeData() {
disabled = false;
owner = nullptr;
owner_id = 0;
}
};

Expand Down

0 comments on commit fa96505

Please sign in to comment.