When copying the old buffer value, if the old value is undefined (o… (#321)

* When copying the old buffer value, if the old value is `undefined` (out‑of‑bounds access to an empty array), preserve the default value of `-1` instead of writing `undefined`.

* opt
This commit is contained in:
llsansun
2026-09-02 18:02:58 +08:00
committed by GitHub
parent 68552314c0
commit 6722aac669
+4 -3
View File
@@ -1815,11 +1815,11 @@ export class Terrain extends Component {
* @zh 获得纹理层
*/
public getLayer (id: number): TerrainLayer | null {
if (id === -1) {
if (id === -1 || id === undefined) {
return null;
}
return this._layerList[id];
return this._layerList[id] || null;
}
/**
@@ -2584,7 +2584,8 @@ export class Terrain extends Component {
const index1 = j * this.blockCount[0] + i;
for (let l = 0; l < TERRAIN_MAX_BLEND_LAYERS; ++l) {
layerBuffer[index0 * TERRAIN_MAX_BLEND_LAYERS + l] = this._layerBuffer[index1 * TERRAIN_MAX_BLEND_LAYERS + l];
const oldVal = this._layerBuffer[index1 * TERRAIN_MAX_BLEND_LAYERS + l];
layerBuffer[index0 * TERRAIN_MAX_BLEND_LAYERS + l] = oldVal !== undefined ? oldVal : -1;
}
}
}