Skip to content

Conversation

@ot-goegelem
Copy link

When removing the last satellite the following error pops up

image

This MR fixes it by handling this a bit more gracefully

@ot-goegelem ot-goegelem marked this pull request as ready for review November 29, 2025 22:24
@zhangzhiming212
Copy link

this question may from cesium's ‘Loop Rendering’ :
This code attempts to access Cesium's internal private properties at a very deep level (_primitives) in order to clean up memory. When you click "Deselect," the DataSource has already been removed from Cesium.

This causes the array under viewer.scene.primitives to become empty or its hierarchical structure to change. The original code assumes there is always an element at index 0 ([0]). Once the array is empty, accessing [0] will return undefined. Subsequently, trying to read its properties will throw an error: "Cannot read properties of undefined (reading '0')".

Solution
You need to use the optional chaining operator (?.) to protect each array index access. If the array is empty or does not exist, it will directly return undefined instead of causing a crash.
you can try to replace the code in satvis-next\src\modules\util\CesiumCleanupHelper.js with code below:

import { CesiumCallbackHelper } from "./CesiumCallbackHelper";

export class CesiumCleanupHelper {
// Cleanup leftover Cesium internal data after removing satellites
// CesiumGS/cesium#7184
static cleanup(viewer) {
const onTickEventRemovalCallback = CesiumCallbackHelper.createPeriodicTickCallback(viewer, 1, () => {
console.info("Removing leftover Cesium internal data");
onTickEventRemovalCallback();

  /* eslint-disable no-underscore-dangle */
  
  const labelCollection = viewer.scene.primitives
    ?._primitives?.[0]
    ?._primitives?.[0]
    ?._primitives?.[0]
    ?._labelCollection;

  if (labelCollection) {
    if (labelCollection._spareBillboards) {
         labelCollection._spareBillboards.forEach((billboard) => {
           labelCollection._billboardCollection.remove(billboard);
         });
         labelCollection._spareBillboards.length = 0;
    }
  }
  /* eslint-enable no-underscore-dangle */
});

}
}

hope useful :>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants