Try at removing instances renderer directly after removal

This commit is contained in:
AlexandreSi
2023-12-05 16:59:43 +01:00
parent e382e2ecea
commit 28067662a2
8 changed files with 54 additions and 5 deletions

View File

@@ -743,6 +743,18 @@ export default class LayerRenderer {
}
}
destroyInstanceRenderers(instances: gdInitialInstance[]) {
console.log('layer.destroyInstanceRenderers: ', instances.length)
for (let instanceToDestroy of instances) {
console.log('instance to destroy for object ', instanceToDestroy.getObjectName())
const renderedInstance = this.renderedInstances[instanceToDestroy.ptr]
if (renderedInstance) {
console.log("DESTROY")
renderedInstance.onRemovedFromScene();
}
}
}
/**
* Remove rendered instances that are not associated to any instance anymore
* (this can happen after an instance has been deleted).
@@ -753,7 +765,9 @@ export default class LayerRenderer {
if (this.renderedInstances.hasOwnProperty(i)) {
const renderedInstance = this.renderedInstances[i];
if (!renderedInstance.wasUsed) {
console.log("was not used, on remove from scene")
renderedInstance.onRemovedFromScene();
console.log("delete rendered instance")
delete this.renderedInstances[i];
} else renderedInstance.wasUsed = false;
}

View File

@@ -329,6 +329,18 @@ export default class InstancesRenderer {
}
}
destroyInstanceRenderers(instances: gdInitialInstance[]) {
console.log("DESTROY INSTANCES RENDERERS")
for (let i in this.layersRenderers) {
if (this.layersRenderers.hasOwnProperty(i)) {
const layerRenderer = this.layersRenderers[i];
console.log("DESTROY INSTANCES RENDERERS in layer")
layerRenderer.destroyInstanceRenderers(instances);
}
}
}
/**
* Clean up rendered layers that are not existing anymore
*/

View File

@@ -234,6 +234,8 @@ export default class SelectedInstances {
}
const instance = selection[i];
console.log(instance, instance.getObjectName())
const instanceRect = this.instanceMeasurer.getInstanceAABB(
instance,
new Rectangle()

View File

@@ -621,6 +621,11 @@ export default class InstancesEditor extends Component<Props> {
);
};
destroyInstanceRenderers = (instances: gdInitialInstance[]) => {
console.log('instancesEditor.destroyInstanceRenderers: ', instances.length);
this.instancesRenderer.destroyInstanceRenderers(instances);
};
/**
* Immediately add serialized instances at the given
* position (in scene coordinates).
@@ -783,7 +788,10 @@ export default class InstancesEditor extends Component<Props> {
return;
}
console.log('on down instance, select');
console.log(
'on down instance, select, object name:',
instance.getObjectName()
);
this.props.instancesSelection.selectInstance({
instance,
multiSelect: this.keyboardShortcuts.shouldMultiSelect(),

View File

@@ -155,5 +155,6 @@ export type SceneEditorsDisplayInterface = {|
preventSnapToGrid?: boolean,
addInstancesInTheForeground?: boolean,
|}) => Array<gdInitialInstance>,
destroyInstanceRenderers: (gdInitialInstance[]) => void,
|},
|};

View File

@@ -206,6 +206,9 @@ const MosaicEditorsDisplay = React.forwardRef<
addSerializedInstances: editor
? editor.addSerializedInstances
: () => [],
destroyInstanceRenderers: editor
? editor.destroyInstanceRenderers
: () => {},
},
};
});

View File

@@ -196,6 +196,9 @@ const SwipeableDrawerEditorsDisplay = React.forwardRef<
addSerializedInstances: editor
? editor.addSerializedInstances
: () => [],
destroyInstanceRenderers: editor
? editor.destroyInstanceRenderers
: () => {},
},
};
});

View File

@@ -1216,12 +1216,18 @@ export default class SceneEditor extends React.Component<Props, State> {
console.log('removeInstance');
this.props.initialInstances.removeInstance(instance);
});
const { editorDisplay } = this;
if (editorDisplay) {
editorDisplay.instancesHandlers.destroyInstanceRenderers(
selectedInstances
);
}
console.log('clearSelection');
console.log('clearSelection', selectedInstances.length);
this.instancesSelection.clearSelection();
if (this.editorDisplay) {
console.log('clearHighlightedInstance');
this.editorDisplay.instancesHandlers.clearHighlightedInstance();
if (editorDisplay) {
console.log('clearHighlightedInstance', selectedInstances.length);
editorDisplay.instancesHandlers.clearHighlightedInstance();
}
console.log('setting state');