Skip to content

Commit d9fda75

Browse files
mgermeriegchoqueux
authored andcommittedMay 26, 2021
fix(LayeredMaterialNodeProcessing): prevent errors in layer update when removing layer
1 parent f612eb3 commit d9fda75

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed
 

‎src/Process/LayeredMaterialNodeProcessing.js

+15
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ function refinementCommandCancellationFn(cmd) {
2525
return true;
2626
}
2727

28+
// Cancel the command if the layer was removed between command scheduling and command execution
29+
if (!cmd.requester.layerUpdateState[cmd.layer.id]
30+
|| !cmd.layer.source._featuresCaches[cmd.layer.source.crs]) {
31+
return true;
32+
}
33+
2834
return !cmd.requester.material.visible;
2935
}
3036

@@ -137,6 +143,10 @@ export function updateLayeredMaterialNodeImagery(context, layer, node, parent) {
137143

138144
return context.scheduler.execute(command).then(
139145
(result) => {
146+
// Does nothing if the layer has been removed while command was being or waiting to be executed
147+
if (!node.layerUpdateState[layer.id]) {
148+
return;
149+
}
140150
// TODO: Handle error : result is undefined in provider. throw error
141151
const pitchs = extentsDestination.map((ext, i) => ext.offsetToParent(result[i].extent, nodeLayer.offsetScales[i]));
142152
nodeLayer.setTextures(result, pitchs);
@@ -206,6 +216,11 @@ export function updateLayeredMaterialNodeElevation(context, layer, node, parent)
206216

207217
return context.scheduler.execute(command).then(
208218
(result) => {
219+
// Does nothing if the layer has been removed while command was being or waiting to be executed
220+
if (!node.layerUpdateState[layer.id]) {
221+
return;
222+
}
223+
209224
// Do not apply the new texture if its level is < than the current
210225
// one. This is only needed for elevation layers, because we may
211226
// have several concurrent layers but we can only use one texture.

‎src/Process/handlerNodeError.js

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
const MAX_RETRY = 4;
33

44
export default function handlingError(err, node, layer, targetLevel, view) {
5+
// Cancel error handling if the layer was removed between command scheduling and its execution
6+
if (!node.layerUpdateState[layer.id]) {
7+
return;
8+
}
9+
510
if (err.isCancelledCommandException) {
611
node.layerUpdateState[layer.id].success();
712
} else if (err instanceof SyntaxError) {

0 commit comments

Comments
 (0)
Please sign in to comment.