Closed Auburn closed 2 years ago
Thanks again for fixing flaws of my original code @Auburn 😁 I'll take it!
As a heads-up, I'm currently working on removing the object pools from the code base entirely, and replacing them with simple ImVector
s. The goal is to solve id reuse problems, such as the one you just fixed, as well as simplify the code. It's taking a while though, and in the meanwhile this fix is a good quality of life improvement. I'll create a pr eventually, and let you & other contributors know.
I had experienced issues with node attributes becoming unresponsive. I tracked the issue down to multiple entries in
Pins.Pool
sharing the same id, only one of these entries wasInUse
the rest were stale data.This was from v0.4 of imnodes but I can't see anything that would have fixed this on HEAD. Here is the debug view of
editor.Pins
when the issue occurred. Notice how several pins haveid=1536
but only 1 is markedInUse
. The current state of the node editor at this point was a single node with 2 attributes.When
ObjectPoolUpdate
is called at the end of every frame it loops over all the pins (including stale) and any notInUse
get their id invalidated in theIdMap
. This is bad since it invalidates theIdMap
for the valid pin with a matching id that is stillInUse
https://github.com/Nelarius/imnodes/blob/c986af0bbaf45f2adadabca42f48e972e8339dd5/imnodes_internal.h#L357This change fixes that by checking that the
IdMap
actually points to the current entry before invalidating it. By doing this you can also avoid having to clear theFreeList
every frame and also calling the destructor on notInUse
objects every frame too, which C++ classes as undefined behaviour.I only saw the issue happen with pins, but I don't see why it couldn't happen for the other object pools, so I changed the node specialisation too.