When copying the old buffer value, if the old value is undefined (o… - #321
Merged
Conversation
…ut‑of‑bounds access to an empty array), preserve the default value of `-1` instead of writing `undefined`.
Code Size Check Report
Interface Check ReportThis pull request does not change any public interfaces ! |
stanleyljl
approved these changes
Sep 2, 2026
star-e
reviewed
Sep 2, 2026
| } | ||
|
|
||
| return this._layerList[id]; | ||
| return this._layerList[id] ?? null; |
Contributor
There was a problem hiding this comment.
polyfill of ?? will increase code size a bit.
The following code might have smaller size.
const v = this._layerList[id];
return v !== undefined ? v | null;
star-e
approved these changes
Sep 2, 2026
Contributor
|
@cocos-robot run test cases |
|
@llsansun, Please check the result of
Task Details
|
|
@llsansun, Please check the result of
Task Details |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Re: #
Changelog
error:
TypeError: Cannot read properties of undefined (reading 'tileSize')
at TerrainBlock.update (terrain.ts:539:46)
at Terrain.update (terrain.ts:1752:29)
at component-scheduler.ts:299:35
at ReusableInvoker._invoke (component-scheduler.ts:251:13)
at ReusableInvoker.invoke (component-scheduler.ts:213:14)
at ComponentScheduler.updatePhase (component-scheduler.ts:504:28)
at Director.tick (director.ts:780:37)
at Game._updateCallback (game.ts:1086:22)
at Pacer.updateCallback [as _ccprivate$_callback] (pacer-web.js:4:1650)
*When
terrain.rebuild(info)is called while the node is inactive,_layerBufferis still an empty array[]. When_rebuildLayerBuffercopies data from this empty array,undefinedoverwrites the pre‑initialized-1values in the new buffer. Later,TerrainBlock.update()receivesundefinedas the layer ID.getLayer(undefined)returnsundefined(notnull), which bypasses the!== nullcheck, eventually causing a crash when accessingundefined.tileSize.Two fixes:
_rebuildLayerBuffer (root‑cause fix): When copying old buffer values, if the old value is
undefined(out‑of‑bounds access on an empty array), preserve the default-1instead of writingundefined.getLayer (defensive fix): Return
nullwhen_layerList[id]isundefined, and filter cases whereid === undefined. Ensure the caller’s!== nullcheck works correctly for interception.Continuous Integration
This pull request:
Compatibility Check
This pull request: