GridLayer, UIGridPoint, and GridChunk each stored a raw GridData* that could dangle if the grid was destroyed while external shared_ptrs (e.g. Python layer wrappers) still referenced child objects. The destructor now nulls all parent_grid pointers before cleanup. All usage sites already had null guards, so this completes the fix. These were the last three unfixed bugs from the memory safety audit. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
188b312af0
commit
2f4928cfa3
2 changed files with 161 additions and 0 deletions
|
|
@ -12,6 +12,30 @@ GridData::GridData()
|
|||
|
||||
GridData::~GridData()
|
||||
{
|
||||
// #270: Null out parent_grid in all layers so surviving shared_ptrs
|
||||
// (held by Python wrappers) don't dangle after grid destruction
|
||||
for (auto& layer : layers) {
|
||||
if (layer) layer->parent_grid = nullptr;
|
||||
}
|
||||
|
||||
// #271: Null out parent_grid in all grid points (flat storage)
|
||||
for (auto& p : points) {
|
||||
p.parent_grid = nullptr;
|
||||
}
|
||||
|
||||
// #277: Null out parent_grid in chunks and chunk manager
|
||||
if (chunk_manager) {
|
||||
for (auto& chunk : chunk_manager->chunks) {
|
||||
if (chunk) {
|
||||
chunk->parent_grid = nullptr;
|
||||
for (auto& cell : chunk->cells) {
|
||||
cell.parent_grid = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
chunk_manager->parent_grid = nullptr;
|
||||
}
|
||||
|
||||
cleanupTCOD();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue