[Bugfix] grid.at() returns GridPoint with dangling raw pointer into grid storage #265
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#265
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
UIGrid::py_at(x, y)andUIGrid::subscript()return aGridPointPython object that holds a rawUIGridPoint*pointer directly into the grid's internal point storage. If the grid's storage is ever reallocated or the grid is destroyed while theGridPointobject is alive, the pointer dangles.Root Cause
UIGrid.cpp:1362(py_at):UIGrid.cpp:1403(subscript):The
PyUIGridPointObjectstruct stores:The
gridmember being ashared_ptrprevents the grid from being destroyed while a GridPoint exists, but doesn't protect against internal reallocation of the grid's point storage.Reproduction
Note: Currently the grid's
pointsvector size is fixed at construction and never resized, so this is lower risk in practice. However, thegridfield is ashared_ptr, so the grid won't be destroyed while GridPoint objects exist. The main risk is if grid resize is ever implemented.Fix Options
GridPointto store(grid_shared_ptr, x, y)and recompute the pointer on each property access viagrid->at(x, y)Severity
Medium — currently low risk because grid size is fixed at construction, but the pattern is fragile. The
shared_ptr<UIGrid> gridmember already prevents the worst case (grid destruction). However, this is a hazard waiting for anyone who adds grid resize functionality.