SanderMertens / flecs

A fast entity component system (ECS) for C & C++
https://www.flecs.dev
Other
6.47k stars 454 forks source link

I get exception errors in ms visual studio 2019 before the main function #1197

Closed GeorKous closed 6 months ago

GeorKous commented 6 months ago

I have two programs one is for testing the other is the main application. I run both in x64 the main program gets exceptions errors, the test program runs on release, but gives linker errors on debug mode:

I have the flecs::world ecs; as a global variable in a .h and .cpp file

//MainProgram.exe

On release mode: ecs_stage_t *stage = flecs_stage_from_world(&world); //line 5279 read access violation. world was nullptr

On Debug mode: result = (char *) ecs_os_malloc(size + 1); //line 57888 Exception thrown at 0x00... in app.exe: 0xC0000005: Access violation executing location 0x00...

//TestProgram.exe

On Debug mode:
1) Severity Code Description Project File Line Suppression State Error LNK2019 unresolved external symbol _ecs_abort referenced in function "public: __cdecl flecs::query_base::query_base(struct ecs_world_t ,struct ecs_query_desc_t )" (??0query_base@flecs@@QEAA@PEAUecs_world_t@@PEAUecs_query_desc_t@@@Z) Flecs_Basic_Testing C:\Users\User\source\repos\Flecs_Basic_Testing\Flecs_Basic_Testing\Systems.obj 1

2) Severity Code Description Project File Line Suppression State Error LNK2019 unresolved external symbol _ecs_assert referenced in function "private: static void cdecl flecs::_::each_invoker<class `public: cdecl ::operator()(struct flecs::entity,struct syscomp)const '::2'::<lambda_1>,struct querycomp>::invoke_callback<struct flecs::_::each_column,struct flecs::_::term_ptr,0>(struct ecs_iter_t *,classpublic: cdecl ::operator()(struct flecs::entity,struct syscomp)const '::`2':: const &,unsigned int64,struct flecs::array<struct flecs::_::termptr,1,void> &,struct flecs::::term_ptr)" (??$invoke_callback@Ueachcolumn@@flecs@@Uterm_ptr@23@$0A@@?$each_invoker@Vlambda_1>@?1???R1@QEBA@Uentity@flecs@@Usyscomp@@@Z@Uquerycomp@@@_@flecs@@CAXPEAUecs_iter_t@@AEBV<lambda_1@?1???R4@QEBA@Uentity@2@Usyscomp@@@Z@_KAEAU?$array@Utermptr@@flecs@@$00X@2@Uterm_ptr@12@@Z) Flecs_Basic_Testing C:\Users\User\source\repos\Flecs_Basic_Testing\Flecs_Basic_Testing\Systems.obj 1

3-18) Severity Code Description Project File Line Suppression State Error LNK2001 unresolved external symbol FLECS__EEcsPipeline Flecs_Basic_Testing C:\Users\User\source\repos\Flecs_Basic_Testing\Flecs_Basic_Testing\Systems.obj 1
3-18 are all LNK2001 errors

Any help would be appreciated

copygirl commented 6 months ago

Friendly reminder: The error messages contain Markdown formatting characters so they aren't showing up as intended. You can surround them with backticks, in this case two, since the message itself contains backticks:

Error LNK2019 unresolved external symbol _ecs_abort referenced in function "public: __cdecl flecs::query_base::query_base(struct ecs_world_t *,struct ecs_query_desc_t *)" (??0query_base@flecs@@qeaa@PEAUecs_world_t@@PEAUecs_query_desc_t@@@z)

Error LNK2019 unresolved external symbol _ecs_assert referenced in function "private: static void __cdecl flecs::_::each_invoker<class `public: __cdecl <lambda_1>::operator()(struct flecs::entity,struct syscomp)const '::`2'::<lambda_1>,struct querycomp>::invoke_callback<struct flecs::_::each_column,struct flecs::_::term_ptr,0>(struct ecs_iter_t *,class `public: __cdecl <lambda_1>::operator()(struct flecs::entity,struct syscomp)const '::`2'::<lambda_1> const &,unsigned __int64,struct flecs::array<struct flecs::_::term_ptr,1,void> &,struct flecs::_::term_ptr)" (??$invoke_callback@Ueach_column@_@flecs@@Uterm_ptr@23@$0A@@?$each_invoker@V<lambda_1>@?1???R1@QEBA@Uentity@flecs@@Usyscomp@@@z@Uquerycomp@@@_@flecs@@CAXPEAUecs_iter_t@@aebv<lambda_1>@?1???R4@QEBA@Uentity@2@Usyscomp@@@z@_KAEAU?$array@Uterm_ptr@_@flecs@@$00X@2@Uterm_ptr@12@@z)

SanderMertens commented 6 months ago

I have the flecs::world ecs; as a global variable in a .h and .cpp file

Are you also compiling the flecs.c file? That could explain why you're getting missing symbols.

GeorKous commented 6 months ago

I changed both program's Properties->Configuration Properties->General->C language standard to ISO C11 standard from Default (legacy MSVC) and now the test program runs on both release and debug. However i still get the exception error in my main program at line 5279 ecs_stage_t *stage = flecs_stage_from_world(&world);

Are you also compiling the flecs.c file? That could explain why you're getting missing symbols.

If you mean if i have the flecs.c file in my project together with the flecs.h file then yes they are together in the same directory

GeorKous commented 6 months ago

This line of code causes an exception result = (char *) ecs_os_malloc(size + 1); inside the function ecs_vasprintf the size variable in my project is a valid 46. Should i ask in discord for help?

SanderMertens commented 6 months ago

Hm, that typically would mean that the OS API hasn't been initialized yet. Are you by any chance trying to call Flecs functions before creating the world? Can you share the stack trace of that crash?

GeorKous commented 6 months ago
0000000000000000()  Unknown
>   MagiCube-Infinity.exe!ecs_vasprintf(const char * fmt, char * args) Line 14578   C
    MagiCube-Infinity.exe!ecs_printv_(int level, const char * file, int line, const char * fmt, char * args) Line 28402 C
    MagiCube-Infinity.exe!ecs_log_(int level, const char * file, int line, const char * fmt, ...) Line 28458    C
    MagiCube-Infinity.exe!ecs_assert_log_(int err, const char * cond_str, const char * file, int line, const char * fmt, ...) Line 28599    C
    MagiCube-Infinity.exe!ecs_entity_init(ecs_world_t * world, const ecs_entity_desc_t * desc) Line 5275    C
    MagiCube-Infinity.exe!flecs::_::node_builder<flecs::system,ecs_system_desc_t,flecs::system_builder<ShaderProgram>,flecs::system_builder_i,ShaderProgram>::node_builder<flecs::system,ecs_system_desc_t,flecs::system_builder<ShaderProgram>,flecs::system_builder_i,ShaderProgram>(ecs_world_t * world, const char * name) Line 29707   C++
    MagiCube-Infinity.exe!flecs::system_builder<ShaderProgram>::system_builder<ShaderProgram>(ecs_world_t * world, const char * name) Line 30325    C++
    MagiCube-Infinity.exe!flecs::world::system<ShaderProgram>() Line 30520  C++
    MagiCube-Infinity.exe!`dynamic initializer for 'ShaderProg''() Line 4   C++
    MagiCube-Infinity.exe!_initterm(void(*)() * first, void(*)() * last) Line 22    C++
    [External Code] 

This is what the Call Stack window showed me, also thanks in advance for your time

SanderMertens commented 6 months ago

Closing as there's a duplicate help thread on the discord.