SanderMertens / flecs

A fast entity component system (ECS) for C & C++

Home Page:https://www.flecs.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Assert 'table_column_index >= 1' in find_smallest_column with cases from nothing

BHolman-LBI opened this issue · comments

Describe the bug
The following example triggers an assert

To Reproduce

struct Sw{ struct Cs1{}; };

int main()
{
    flecs::world ecs;
    ecs.type<Sw>().add<Sw::Cs1>();

    ecs.system()
        .term<Sw>().role(flecs::Switch)
        .term<Sw, Sw::Cs1>().role(flecs::Case).set(flecs::Nothing)
        .each([](flecs::entity e)
        {
            printf("matched %s\n", e.str().c_str());
        });
    ecs.entity().add_switch<Sw>().add_case<Sw::Cs1>();
    ecs.progress();
    
    return 0;
}

I am also tripping the value >= sw->min assert in

flecs_switch_header_t *get_header(
    const ecs_switch_t *sw,
    uint64_t value)

with a similar looking stacktrace, but I am unable to repro this exact assertion trip in isolation.

get_header(const ecs_switch_t *,unsigned long long) flecs.c:10834
flecs_switch_case_count(const ecs_switch_t *,unsigned long long) flecs.c:11131
find_smallest_column(ecs_table_t *,ecs_query_table_match_t *,ecs_vector_t *) flecs.c:42247
sparse_column_next(ecs_table_t *,ecs_query_table_match_t *,ecs_vector_t *,ecs_query_iter_t *,query_iter_cursor_t *,bool) flecs.c:42275
ecs_query_next_instanced(ecs_iter_t *) flecs.c:42668
ecs_query_next(ecs_iter_t *) flecs.c:42587
ecs_run_intern(ecs_world_t *,ecs_stage_t *,unsigned long long,EcsSystem *,int,int,float,int,int,void *) flecs.c:27979
ecs_run_pipeline(ecs_world_t *,unsigned long long,float) flecs.c:14933
ecs_workers_progress(ecs_world_t *,unsigned long long,float) flecs.c:14303
ecs_run_pipeline(ecs_world_t *,unsigned long long,float) flecs.c:14889
ecs_progress(ecs_world_t *,float) flecs.c:15122

System currently being iterated

	World.system<SomeDataStruct, const SomeOtherStruct, const AndAnotherDataStruct>("Periodic Trait Strength Update")
		.arg(1).obj(flecs::Wildcard)
		.arg(2).singleton()
		.term<SomeTag>()
		.term<SomeSwitch, SomeSwitch::SomeCase>()
			.role(flecs::Case)
		.iter(Handler);

In find_smallest_column the value of sparse_column->sw_column->data is null

Fixed! The second issue could be related, feel free to open a new issue if that one is still occurring.