SanderMertens / flecs

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

Excessive Entities Registered During Enum Constant Registration on MSVC Compiler #1047

Closed Indra-db closed 1 year ago

Indra-db commented 1 year ago

Describe the bug Upon registering an enum constant using the MSVC compiler, 128 entities are registered irrespective of the actual field count within the enum. This was observable while utilizing a minimal code snippet, where only two enum fields were present but resulted in the registration of 128 entities.

To Reproduce

  1. Execute the provided code snippet on a system utilizing the MSVC compiler.
enum Movement {
    Walking,
    Running
};

int main(int, char* []) {

    flecs::world ecs;
    //flecs::world ecs2;

    auto e = ecs.entity();

    std::cout << e.id() << std::endl;
    flecs::entity ee = ecs.entity().add<Movement>();
    auto e2 = ecs.entity();

    std::cout << e2.id() << std::endl;

return 0;
}
  1. Upon execution, observe the entity IDs output to the console.
  2. During debugging, specifically monitor the entity constant registration phase and notice the registration of 128 entities for the registered enum.

Expected behavior The expected outcome should be the registration of only two entities correlating to the enum fields: Walking and Running, rather than an arbitrary 128 entities.

Actual Behavior: The system registers 128 entities for each registered enum, yielding entity IDs 549 and 680 in this particular instance

Additional context

compiler: Microsoft (R) C/C++ Optimizing Compiler Version 19.29.30151 for x64.

Observable both in Flecs 3.2.4 and 3.2.7. Other releases not tested.

This bug is also viewable on the explorer, showing that too many entities have been registered under the enum. image

SanderMertens commented 1 year ago

I'm not able to reproduce the issue using msvc 19.35. How did you build the code?

Indra-db commented 1 year ago

@SanderMertens just building with visual studio 19 flecs_bug.zip this is the repro solution image

Indra-db commented 1 year ago

Made some new observations:

The bug persists on platform toolset v142 Microsoft Visual Studio Community 2019 Version 16.11.29 prints 549 680 810

does not persist on platform toolset v143 Microsoft Visual Studio Community 2022 (64-bit) - Current Version 17.4.4 prints 548 553 556

Indra-db commented 1 year ago

updated Visual studio Community 2019 Version 16.11.30, the bug still persists on there and on all language standards.

edit: compiler version on vs19: Microsoft (R) C/C++ Optimizing Compiler Version 19.29.30152 for x86 using cmd cl I double checked this with std::cout << "Visual Studio Compiler Version: " << _MSC_VER << std::endl; and that reports 1929 too.

compiler version vs22: Microsoft (R) C/C++ Optimizing Compiler Version 19.34.31937 for x86

SanderMertens commented 1 year ago

Fixed!

Esp9527 commented 11 months ago

My Windows _MSC_VER= 1929, I found same bug. ( flecs version master)

if I changed enum.hpp code 1930 to 1929, the bug will fix.

so there need change 1930 to 1929?

@SanderMertens