Skip to content

Commit 0e68059

Browse files
committed
checking for empty in trivial system removes
1 parent 95ade0a commit 0e68059

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

ecsact/entt/trivial_system_impl.hh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,13 @@ void trivial_system_impl(
9292
if constexpr(!C::transient) {
9393
info.registry.template emplace<component_removed<C>>(entity);
9494

95-
auto& temp = info.registry.template storage<temp_storage<C>>();
96-
if(temp.contains(entity)) {
97-
temp.get(entity).value = info.registry.template get<C>(entity);
98-
} else {
99-
temp.emplace(entity, info.registry.template get<C>(entity));
95+
if constexpr(!std::is_empty_v<C>) {
96+
auto& temp = info.registry.template storage<temp_storage<C>>();
97+
if(temp.contains(entity)) {
98+
temp.get(entity).value = info.registry.template get<C>(entity);
99+
} else {
100+
temp.emplace(entity, info.registry.template get<C>(entity));
101+
}
100102
}
101103
}
102104
});

runtime/test/runtime_test.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ void runtime_test::TrivialRemove::impl(context& ctx) {
3737
std::abort();
3838
}
3939

40+
void runtime_test::AlwaysRemove::impl(context& ctx) {
41+
// This trivial remove should not even be required:
42+
// SEE: https://github.com/ecsact-dev/ecsact_lang_cpp/issues/80
43+
std::cerr << "AlwaysRemove impl called (SHOULD NOT HAPPEN)\n";
44+
std::cerr.flush();
45+
std::abort();
46+
}
47+
4048
TEST(Core, CreateRegistry) {
4149
auto reg_id = ecsact_create_registry("CreateRegistry");
4250
EXPECT_NE(reg_id, ecsact_invalid_registry_id);

runtime/test/runtime_test.ecsact

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ component OtherEntityComponent {
1111

1212
component EmptyComponent;
1313

14+
component AlwaysRemoveMe;
15+
1416
system SimpleSystem {
1517
readwrite ComponentA;
1618
}
@@ -28,6 +30,10 @@ system OtherEntitySystem {
2830
}
2931
}
3032

33+
system AlwaysRemove {
34+
removes AlwaysRemoveMe;
35+
}
36+
3137
action MakeAnother {
3238
readwrite ComponentA;
3339
generates {

0 commit comments

Comments
 (0)