diff --git a/cocos/terrain/terrain.ts b/cocos/terrain/terrain.ts index 167f47a2b1..e1675961c0 100644 --- a/cocos/terrain/terrain.ts +++ b/cocos/terrain/terrain.ts @@ -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; } } }