Convert raw pointers to coordinate-based access (closes #264, closes #265)

GridPoint and GridPointState Python objects now store (grid, x, y)
coordinates instead of raw C++ pointers. Data addresses are computed
on each property access, preventing dangling pointers after vector
resizes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
John McCardle 2026-03-07 23:30:32 -05:00
commit 115e16f4f2
5 changed files with 182 additions and 61 deletions

View file

@ -1353,10 +1353,9 @@ PyObject* UIGrid::py_at(PyUIGridObject* self, PyObject* args, PyObject* kwds)
// Use the type directly since GridPoint is internal-only (not exported to module)
auto type = &mcrfpydef::PyUIGridPointType;
auto obj = (PyUIGridPointObject*)type->tp_alloc(type, 0);
//auto target = std::static_pointer_cast<UIEntity>(target);
// #123 - Use at() method to route through chunks for large grids
obj->data = &(self->data->at(x, y));
obj->grid = self->data;
obj->x = x;
obj->y = y;
return (PyObject*)obj;
}
@ -1396,8 +1395,9 @@ PyObject* UIGrid::subscript(PyUIGridObject* self, PyObject* key)
auto obj = (PyUIGridPointObject*)type->tp_alloc(type, 0);
if (!obj) return NULL;
obj->data = &(self->data->at(x, y));
obj->grid = self->data;
obj->x = x;
obj->y = y;
return (PyObject*)obj;
}