Skip to content

Commit

Permalink
Fixed: Possible crash when copying an entity with entities attached t…
Browse files Browse the repository at this point in the history
…o it
  • Loading branch information
richardbiely committed Dec 12, 2023
1 parent 59b6a11 commit 12757c7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion include/gaia/ecs/chunk.h
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@ namespace gaia {
const auto& rec = recs[i];

const auto* pDesc = rec.pDesc;
if (pDesc->func_ctor == nullptr)
if (pDesc == nullptr || pDesc->func_ctor == nullptr)
continue;

auto* pSrc = (void*)comp_ptr_mut(i, entIdx);
Expand Down
2 changes: 1 addition & 1 deletion single_include/gaia.h
Original file line number Diff line number Diff line change
Expand Up @@ -16715,7 +16715,7 @@ namespace gaia {
const auto& rec = recs[i];

const auto* pDesc = rec.pDesc;
if (pDesc->func_ctor == nullptr)
if (pDesc == nullptr || pDesc->func_ctor == nullptr)
continue;

auto* pSrc = (void*)comp_ptr_mut(i, entIdx);
Expand Down
11 changes: 11 additions & 0 deletions src/test/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3393,6 +3393,17 @@ TEST_CASE("Usage 1 - simple query, 0 component") {
}
}

TEST_CASE("entity copy") {
ecs::World w;

auto e1 = w.add();
auto e2 = w.add();
w.add(e1, e2);
auto e3 = w.copy(e1);

REQUIRE(w.has(e3, e2));
}

TEST_CASE("Usage 1 - simple query, 1 component") {
ecs::World w;

Expand Down

0 comments on commit 12757c7

Please sign in to comment.