[Bugfix] entity.at() returns GridPointState with dangling raw pointer into gridstate vector #264
Labels
No labels
Alpha Release Requirement
Bugfix
Demo Target
Documentation
Major Feature
Minor Feature
priority:tier1-active
priority:tier2-foundation
priority:tier3-future
priority:tier4-deferred
Refactoring & Cleanup
system:animation
system:documentation
system:grid
system:input
system:performance
system:procgen
system:python-binding
system:rendering
system:ui-hierarchy
Tiny Feature
workflow:blocked
workflow:needs-benchmark
workflow:needs-documentation
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
john/McRogueFace#264
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
UIEntity::at(x, y)returns aGridPointStatePython object that holds a rawUIGridPointState*pointer directly into the entity'sgridstatevector. If the entity changes grids (triggeringgridstate.resize()), the vector may reallocate its internal storage, leaving theGridPointStateobject with a dangling pointer. Any subsequent access through it is undefined behavior.Root Cause
UIEntity.cpp:130:The
PyUIGridPointStateObjectstruct stores:When
gridstateis resized (viaset_grid(),EntityCollection.append(), etc.),std::vectormay reallocate, invalidating all pointers into the old storage.Reproduction
Fix Options
GridPointStateto store(entity_weak_ptr, x, y)and compute the pointer on each accessGridPointStateashared_ptr<UIEntity>and recompute the pointer on accessgridstate; check it on accessOption 1 is simplest and safest.
Severity
Critical — use-after-free / dangling pointer leading to undefined behavior. Can corrupt memory silently or crash.