Safety of keeping a component's data pointer long term. #1145
-
I'm keeping a mutable pointer to a component's data (which I got from I couldn't find anything about this in the documentation. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I think it would be wise to consider the pointer invalid as soon as you return control to Flecs. Besides modifying entities that share the same archetype (share the same components) and modifying the components on the entity itself, one thing that also comes to mind would be if you have any sorting queries. It might be safe if you can guarantee the entity's archetype never changes, but this sounds like a design flaw from the start. If what you're trying to achieve can't be done using ECS alone, what about storing a shared pointer in the component itself? |
Beta Was this translation helpful? Give feedback.
I think it would be wise to consider the pointer invalid as soon as you return control to Flecs. Besides modifying entities that share the same archetype (share the same components) and modifying the components on the entity itself, one thing that also comes to mind would be if you have any sorting queries. It might be safe if you can guarantee the entity's archetype never changes, but this sounds like a design flaw from the start. If what you're trying to achieve can't be done using ECS alone, what about storing a shared pointer in the component itself?