mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-07 17:43:51 +00:00
fix(history): bounds-check chunkIndex in captureChunk/restoreChunk
ADTTerrain.chunks is std::array<MapChunk, 256> — out-of-range indexing is undefined behaviour. Reject indices outside [0, 255] and return empty / no-op rather than crashing on a stale undo record from a future-version terrain layout.
This commit is contained in:
parent
17ca42b70b
commit
4c0f8dd5c0
1 changed files with 4 additions and 0 deletions
|
|
@ -5,6 +5,9 @@ namespace editor {
|
|||
|
||||
ChunkSnapshot EditorHistory::captureChunk(const pipeline::ADTTerrain& terrain, int idx) {
|
||||
ChunkSnapshot snap;
|
||||
// ADTTerrain.chunks is std::array<MapChunk, 256>; out-of-range
|
||||
// would be undefined behaviour. Return an empty snapshot instead.
|
||||
if (idx < 0 || idx >= 256) return snap;
|
||||
snap.chunkIndex = idx;
|
||||
snap.heights = terrain.chunks[idx].heightMap.heights;
|
||||
snap.alphaMap = terrain.chunks[idx].alphaMap;
|
||||
|
|
@ -13,6 +16,7 @@ ChunkSnapshot EditorHistory::captureChunk(const pipeline::ADTTerrain& terrain, i
|
|||
}
|
||||
|
||||
void EditorHistory::restoreChunk(pipeline::ADTTerrain& terrain, const ChunkSnapshot& snap) {
|
||||
if (snap.chunkIndex < 0 || snap.chunkIndex >= 256) return;
|
||||
terrain.chunks[snap.chunkIndex].heightMap.heights = snap.heights;
|
||||
terrain.chunks[snap.chunkIndex].alphaMap = snap.alphaMap;
|
||||
terrain.chunks[snap.chunkIndex].layers = snap.layers;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue