SanderMertens / flecs

A fast entity component system (ECS) for C & C++
https://www.flecs.dev
MIT License
5.7k stars 411 forks source link

free(): invalid pointer when using sorted query with std::list #1162

Closed SimonPierreED closed 1 month ago

SimonPierreED commented 3 months ago

Describe the bug A memory corruption seems to occur when using sorted queries with std::list in any components.

To Reproduce

  1. Compile the cpp/queries/sorting example with the first lines modified as follow
    
    #include <sorting.h>
    #include <iostream>
    +#include <list>

struct Position { double x, y;

// Order by x member of Position int compare_position( [...]


**Expected behavior**
The example compile and run just fine.

**Current behavious**

```log
-- First iteration
{1,0}
{2,0}
{4,0}
{5,0}
{6,0}

-- Second iteration
{2,0}
{4,0}
{5,0}
{6,0}
{7,0}

-- System iteration
{2,0}
{3,0}
{4,0}
{5,0}
{6,0}
{7,0}
free(): invalid pointer
Aborted

Additional context

Compiled on windows WSL2 : g++ (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0 Release and debug cause the same issue.

The list seems to be in a weird state in the destructor.

This is currently completely preventing me from used sorting. But otherwise thanks for the great work!

SanderMertens commented 1 month ago

Fixed!