@@ -42669,16 +42669,33 @@ void flecs_tables_resize_column_locks(
42669
42669
int32_t new_stage_count)
42670
42670
{
42671
42671
flecs_poly_assert(world, ecs_world_t);
42672
- //no need to resize, or world not initialized yet, or being destroyed, or the same stage count
42673
- if (world->flags & ( EcsWorldInit|EcsWorldFini) || previous_stage_count == new_stage_count) {
42672
+ //no need to resize when is world not initialized yet or changing to the same stage count
42673
+ if (world->flags & EcsWorldInit || previous_stage_count == new_stage_count) {
42674
42674
return;
42675
42675
}
42676
42676
42677
- int32_t i, count = flecs_sparse_count(&world->store.tables);
42678
- for (i = 1; i < count; i ++) {
42679
- ecs_table_t *table = flecs_sparse_get_dense_t(&world->store.tables,
42680
- ecs_table_t, i);
42681
- flecs_table_resize_column_locks(world, table, previous_stage_count, new_stage_count);
42677
+ if (!(world->flags & EcsWorldFini)) {
42678
+ int32_t i, count = flecs_sparse_count(&world->store.tables);
42679
+ for (i = 1; i < count; i ++) {
42680
+ ecs_table_t *table = flecs_sparse_get_dense_t(&world->store.tables,
42681
+ ecs_table_t, i);
42682
+ flecs_table_resize_column_locks(world, table, previous_stage_count, new_stage_count);
42683
+ }
42684
+ // at world fini, we instead want to free the table locks, not resize.
42685
+ // at world fini, the world returns to single threaded mode and sets the stage, this is where we clear the tables
42686
+ // at the end of world fini, it sets the stage count to 0, we don't want to clean up here as it's already done so.
42687
+ } else if (new_stage_count != 0) {
42688
+ int32_t i, count = flecs_sparse_count(&world->store.tables);
42689
+ for (i = 1; i < count; i ++) {
42690
+ ecs_table_t *table = flecs_sparse_get_dense_t(&world->store.tables,
42691
+ ecs_table_t, i);
42692
+
42693
+ if(table->column_lock)
42694
+ {
42695
+ flecs_wfree_n(world, int32_t, previous_stage_count * table->column_count, table->column_lock);
42696
+ table->column_lock = NULL;
42697
+ }
42698
+ }
42682
42699
}
42683
42700
}
42684
42701
0 commit comments