Skip to content

Commit 6722aac

Browse files
authored
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
1 parent 6855231 commit 6722aac

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

cocos/terrain/terrain.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1815,11 +1815,11 @@ export class Terrain extends Component {
18151815
* @zh 获得纹理层
18161816
*/
18171817
public getLayer (id: number): TerrainLayer | null {
1818-
if (id === -1) {
1818+
if (id === -1 || id === undefined) {
18191819
return null;
18201820
}
18211821

1822-
return this._layerList[id];
1822+
return this._layerList[id] || null;
18231823
}
18241824

18251825
/**
@@ -2584,7 +2584,8 @@ export class Terrain extends Component {
25842584
const index1 = j * this.blockCount[0] + i;
25852585

25862586
for (let l = 0; l < TERRAIN_MAX_BLEND_LAYERS; ++l) {
2587-
layerBuffer[index0 * TERRAIN_MAX_BLEND_LAYERS + l] = this._layerBuffer[index1 * TERRAIN_MAX_BLEND_LAYERS + l];
2587+
const oldVal = this._layerBuffer[index1 * TERRAIN_MAX_BLEND_LAYERS + l];
2588+
layerBuffer[index0 * TERRAIN_MAX_BLEND_LAYERS + l] = oldVal !== undefined ? oldVal : -1;
25882589
}
25892590
}
25902591
}

0 commit comments

Comments
 (0)