mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-19 14:52:40 +08:00
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:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user