Skip to content

Reference invalidation from vector usage #7

@avarsh

Description

@avarsh

Returning references to components is bad, since we can run into reference invalidation. This is when the vector reallocates its memory in order to grow, meaning all the components are reallocated, causing the references to be invalid. The following test:

samplecode

gives this output:

refout

most likely as a result of the original reference pointing to an invalid block of memory. Obviously an easy solution is to just not do something like this in your code, i.e. do not use a component retrieved from the list before you add a new component. However I'd also like to look at some alternatives.

Note: this issue was originally opened on the ape2d-ecs repository.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ecsRelating to the entity component system framework.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions