Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Id record refcount goes below 0 in world fini after adding pairs with arbitrary target ids #951

Closed
Hexlord opened this issue Mar 29, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@Hexlord
Copy link
Contributor

Hexlord commented Mar 29, 2023

Describe the bug
When using arbitraty id-s as targets of the relationship, corruptions occur in some scenarios, this is a 100% repro.
World destruction is not succesful, idr ref count reaches -1.

To Reproduce
The repro is located at https://github.com/Hexlord/flecs_test/blob/master/main.cpp
It is important that following defines are set in CMake:

add_compile_definitions(
    ECS_HI_COMPONENT_ID=512
    FLECS_CUSTOM_BUILD FLECS_STATS FLECS_CPP FLECS_MODULE FLECS_TIMER FLECS_SYSTEM FLECS_PIPELINE FLECS_EXPR FLECS_PARSER FLECS_LOG FLECS_MONITOR FLECS_REST
)

Expected behavior
No asserts should happen.

@Hexlord Hexlord added the bug Something isn't working label Mar 29, 2023
@SanderMertens
Copy link
Owner

SanderMertens commented Mar 29, 2023

Pasted the code here for visibility:

#include "flecs.h"

using namespace flecs;

struct CComp1 {
  int field;
};
struct CComp2 {
  int field;
};
struct CComp3 {
  int field;
};
int main(int argc, char *argv[]) {
  auto World = flecs::world();
  World.set_threads(1);
  // Removing any of these stops the crash.
  World.component<CComp1>();
  World.component<CComp2>();
  World.component<CComp3>();
  // Removing any of these stops the crash.
  auto Role1 = ecs_new_low_id(World.c_ptr());
  auto Role2 = ecs_new_low_id(World.c_ptr());
  ecs_bulk_desc_t BulkDesc = {};
  // Making this lower stops the crash.
  BulkDesc.count = 1331;
  auto Entities = ecs_bulk_init(World.c_ptr(), &BulkDesc);
  printf("last id: %lu\n", Entities[BulkDesc.count - 1]);
  // < 272 is fine, < 273 leads to crash on ecs fini.
  for (auto Index = 0u; Index < 273; ++Index) {
    auto E = World.entity();
    // 1983 can be changed to 1984 and still crash, not sure about this.
    printf("adding (%lu, %lu) to %lu\n", (unsigned long)Role2, (unsigned long)1983 + Index, E.id());
    E.add(ecs_pair(Role2, 1983 + Index));    
  }
  return 0;
}

@SanderMertens
Copy link
Owner

SanderMertens commented Mar 29, 2023

I can't reproduce the issue, made sure to build the project with the defines. Reproduced it with the cmake project.

@SanderMertens SanderMertens changed the title Idr corruption through intensive relationship usage Id record refcount goes below 0 in world fini after adding pairs with arbitrary target ids Mar 29, 2023
@SanderMertens
Copy link
Owner

Fixed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants