Skip to content

Commit b471d83

Browse files
committed
Fix issue with cloning entity symbols
1 parent bb07a08 commit b471d83

File tree

5 files changed

+111
-8
lines changed

5 files changed

+111
-8
lines changed

distr/flecs.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9674,6 +9674,8 @@ ecs_entity_t ecs_clone(
96749674
if (src_table->flags & EcsTableHasName) {
96759675
dst_table = ecs_table_remove_id(world, src_table,
96769676
ecs_pair_t(EcsIdentifier, EcsName));
9677+
dst_table = ecs_table_remove_id(world, dst_table,
9678+
ecs_pair_t(EcsIdentifier, EcsSymbol));
96779679
}
96789680

96799681
ecs_type_t dst_type = dst_table->type;
@@ -9690,10 +9692,10 @@ ecs_entity_t ecs_clone(
96909692

96919693
if (copy_value) {
96929694
int32_t row = ECS_RECORD_TO_ROW(dst_r->row);
9693-
int32_t i, count = src_table->column_count;
9695+
int32_t i, count = dst_table->column_count;
96949696
for (i = 0; i < count; i ++) {
9695-
int32_t type_id = ecs_table_column_to_type_index(src_table, i);
9696-
ecs_id_t component = src_table->type.array[type_id];
9697+
int32_t index = ecs_table_column_to_type_index(dst_table, i);
9698+
ecs_id_t component = dst_table->type.array[index];
96979699

96989700
void *dst_ptr = ecs_get_mut_id(world, dst, component);
96999701
if (!dst_ptr) {

src/entity.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1806,6 +1806,8 @@ ecs_entity_t ecs_clone(
18061806
if (src_table->flags & EcsTableHasName) {
18071807
dst_table = ecs_table_remove_id(world, src_table,
18081808
ecs_pair_t(EcsIdentifier, EcsName));
1809+
dst_table = ecs_table_remove_id(world, dst_table,
1810+
ecs_pair_t(EcsIdentifier, EcsSymbol));
18091811
}
18101812

18111813
ecs_type_t dst_type = dst_table->type;
@@ -1822,10 +1824,10 @@ ecs_entity_t ecs_clone(
18221824

18231825
if (copy_value) {
18241826
int32_t row = ECS_RECORD_TO_ROW(dst_r->row);
1825-
int32_t i, count = src_table->column_count;
1827+
int32_t i, count = dst_table->column_count;
18261828
for (i = 0; i < count; i ++) {
1827-
int32_t type_id = ecs_table_column_to_type_index(src_table, i);
1828-
ecs_id_t component = src_table->type.array[type_id];
1829+
int32_t index = ecs_table_column_to_type_index(dst_table, i);
1830+
ecs_id_t component = dst_table->type.array[index];
18291831

18301832
void *dst_ptr = ecs_get_mut_id(world, dst, component);
18311833
if (!dst_ptr) {

test/core/project.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1562,7 +1562,11 @@
15621562
"tag_w_value",
15631563
"1_tag_1_component",
15641564
"1_tag_1_component_w_value",
1565-
"clone_w_name"
1565+
"clone_w_name",
1566+
"clone_component",
1567+
"clone_component_w_value",
1568+
"clone_component_w_entity",
1569+
"clone_component_w_entity_w_value"
15661570
]
15671571
}, {
15681572
"id": "ComponentLifecycle",

test/core/src/Clone.c

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,3 +460,78 @@ void Clone_clone_w_name(void) {
460460

461461
ecs_fini(world);
462462
}
463+
464+
void Clone_clone_component(void) {
465+
ecs_world_t *world = ecs_mini();
466+
467+
ECS_COMPONENT(world, Position);
468+
469+
ecs_entity_t clone = ecs_clone(world, 0, ecs_id(Position), false);
470+
471+
test_assert(ecs_has(world, clone, EcsComponent));
472+
test_assert(!ecs_has_id(world, clone, ecs_pair_t(EcsIdentifier, EcsName)));
473+
test_assert(!ecs_has_id(world, clone, ecs_pair_t(EcsIdentifier, EcsSymbol)));
474+
475+
ecs_fini(world);
476+
}
477+
478+
479+
void Clone_clone_component_w_value(void) {
480+
ecs_world_t *world = ecs_mini();
481+
482+
ECS_COMPONENT(world, Position);
483+
484+
ecs_entity_t clone = ecs_clone(world, 0, ecs_id(Position), true);
485+
486+
test_assert(ecs_has(world, clone, EcsComponent));
487+
test_assert(!ecs_has_id(world, clone, ecs_pair_t(EcsIdentifier, EcsName)));
488+
test_assert(!ecs_has_id(world, clone, ecs_pair_t(EcsIdentifier, EcsSymbol)));
489+
490+
{
491+
const EcsComponent *ptr = ecs_get(world, clone, EcsComponent);
492+
test_assert(ptr != NULL);
493+
test_int(ptr->size, sizeof(Position));
494+
test_int(ptr->alignment, ECS_ALIGNOF(Position));
495+
}
496+
497+
ecs_fini(world);
498+
}
499+
500+
501+
void Clone_clone_component_w_entity(void) {
502+
ecs_world_t *world = ecs_mini();
503+
504+
ECS_COMPONENT(world, Position);
505+
506+
ecs_entity_t new = ecs_new(world);
507+
ecs_entity_t clone = ecs_clone(world, new, ecs_id(Position), false);
508+
509+
test_assert(ecs_has(world, clone, EcsComponent));
510+
test_assert(!ecs_has_id(world, clone, ecs_pair_t(EcsIdentifier, EcsName)));
511+
test_assert(!ecs_has_id(world, clone, ecs_pair_t(EcsIdentifier, EcsSymbol)));
512+
513+
ecs_fini(world);
514+
}
515+
516+
void Clone_clone_component_w_entity_w_value(void) {
517+
ecs_world_t *world = ecs_mini();
518+
519+
ECS_COMPONENT(world, Position);
520+
521+
ecs_entity_t new = ecs_new(world);
522+
ecs_entity_t clone = ecs_clone(world, new, ecs_id(Position), true);
523+
524+
test_assert(ecs_has(world, clone, EcsComponent));
525+
test_assert(!ecs_has_id(world, clone, ecs_pair_t(EcsIdentifier, EcsName)));
526+
test_assert(!ecs_has_id(world, clone, ecs_pair_t(EcsIdentifier, EcsSymbol)));
527+
528+
{
529+
const EcsComponent *ptr = ecs_get(world, clone, EcsComponent);
530+
test_assert(ptr != NULL);
531+
test_int(ptr->size, sizeof(Position));
532+
test_int(ptr->alignment, ECS_ALIGNOF(Position));
533+
}
534+
535+
ecs_fini(world);
536+
}
537+

test/core/src/main.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1504,6 +1504,10 @@ void Clone_tag_w_value(void);
15041504
void Clone_1_tag_1_component(void);
15051505
void Clone_1_tag_1_component_w_value(void);
15061506
void Clone_clone_w_name(void);
1507+
void Clone_clone_component(void);
1508+
void Clone_clone_component_w_value(void);
1509+
void Clone_clone_component_w_entity(void);
1510+
void Clone_clone_component_w_entity_w_value(void);
15071511

15081512
// Testsuite 'ComponentLifecycle'
15091513
void ComponentLifecycle_setup(void);
@@ -9053,6 +9057,22 @@ bake_test_case Clone_testcases[] = {
90539057
{
90549058
"clone_w_name",
90559059
Clone_clone_w_name
9060+
},
9061+
{
9062+
"clone_component",
9063+
Clone_clone_component
9064+
},
9065+
{
9066+
"clone_component_w_value",
9067+
Clone_clone_component_w_value
9068+
},
9069+
{
9070+
"clone_component_w_entity",
9071+
Clone_clone_component_w_entity
9072+
},
9073+
{
9074+
"clone_component_w_entity_w_value",
9075+
Clone_clone_component_w_entity_w_value
90569076
}
90579077
};
90589078

@@ -15981,7 +16001,7 @@ static bake_test_suite suites[] = {
1598116001
"Clone",
1598216002
NULL,
1598316003
NULL,
15984-
16,
16004+
20,
1598516005
Clone_testcases
1598616006
},
1598716007
{

0 commit comments

Comments
 (0)