Skip to content

Commit 430b44f

Browse files
authored
Fix corrupted state due to custom extensions causing downstream errors in destroyDrawable (TurboWarp#28)
Certain custom extensions, such as SharkPool Layer Control, thoroughly corrupt internal state by rearranging drawables outside the layer they ought to belong to. This breaks a lot of things in various ways. One of the things it breaks is the loop where we try to find the drawable by checking where it's layer start and ends. The impact of this corruption is severe enough that it's best if we work around it.
1 parent 592e39a commit 430b44f

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

‎src/RenderWebGL.js‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -832,10 +832,25 @@ class RenderWebGL extends EventEmitter {
832832
if (index < endIndex) {
833833
this._drawList.splice(index, 1);
834834
this._updateOffsets('delete', currentLayerGroup.groupIndex);
835-
} else {
836-
log.warn('Could not destroy drawable that could not be found in layer group.');
837835
return;
838836
}
837+
838+
// Certain custom extensions, such as SharkPool Layer Control, thoroughly corrupt internal state
839+
// by rearranging drawables outside the layer they ought to belong to. This breaks a lot of things
840+
// in various ways. One of the things it breaks is the loop above where we try to find the drawable
841+
// by checking where its layer starts and ends. The impact of this corruption is severe enough that
842+
// it's best if we work around it.
843+
index = this._drawList.indexOf(drawableID);
844+
if (index === -1) {
845+
log.warn('Could not destroy drawable that could not be found in draw list.');
846+
return;
847+
}
848+
this._drawList.splice(index, 1);
849+
for (const groupName of this._groupOrdering) {
850+
if (this._layerGroups[groupName].drawListOffset > index) {
851+
this._layerGroups[groupName].drawListOffset--;
852+
}
853+
}
839854
}
840855

841856
/**

0 commit comments

Comments
 (0)