ecs: fix pointer invalidation in get/setComponent #401

Merged
dweiller merged 1 commit from memory-bug into main 2022-07-12 13:56:49 +00:00
dweiller commented 2022-07-11 08:24:50 +00:00 (Migrated from github.com)

The reference to the old archetype is invalidated by getOrPut() calls of
std.ArrayHashMap. The implementation of std.ArrayHashMap means that
pointers can be invalidated on getOrPut() calls even if the key exists
in the map
. This means that the reference to the old archetype needs to
be refreshed unconditionally (i.e. not only if the new archetype didn't
exist previously).

Maybe it's worth suggesting upstream that std.ArrayHashMap changes so getOrPut() doesn't invalidate pointers if the key exists. The issue is that getOrPut() calls ensureTotalCapacity() to make sure there is a free element, thus invalidating pointers if the map is full.

  • By selecting this checkbox, I agree to license my contributions to this project under the license(s) described in the LICENSE file, and I have the right to do so or have received permission to do so by an employer or client I am producing work for whom has this right.
The reference to the old archetype is invalidated by getOrPut() calls of std.ArrayHashMap. The implementation of std.ArrayHashMap means that pointers can be invalidated on getOrPut() calls _even if the key exists in the map_. This means that the reference to the old archetype needs to be refreshed unconditionally (i.e. not only if the new archetype didn't exist previously). Maybe it's worth suggesting upstream that `std.ArrayHashMap` changes so `getOrPut()` doesn't invalidate pointers if the key exists. The issue is that `getOrPut()` calls `ensureTotalCapacity()` to make sure there is a free element, thus invalidating pointers if the map is full. - [x] By selecting this checkbox, I agree to license my contributions to this project under the license(s) described in the LICENSE file, and I have the right to do so or have received permission to do so by an employer or client I am producing work for whom has this right.
emidoots (Migrated from github.com) approved these changes 2022-07-12 13:56:44 +00:00
emidoots (Migrated from github.com) left a comment

Wow, interesting, didn't realize this was the case. Thanks for this @dweiller !

Wow, interesting, didn't realize this was the case. Thanks for this @dweiller !
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
hexops/mach!401
No description provided.