scratch-gui icon indicating copy to clipboard operation
scratch-gui copied to clipboard

[BUG] If there is no sprite to drag, TurboWarp keeps checking on every mouse move

Open Xeltalliv opened this issue 10 months ago • 4 comments

On the stage, if user presses mouse button down where there are no draggable sprites, and then starts moving the mouse while still holding the button pressed, on every mouse move TurboWarp will keep checking whether there is anything at the position of the original press. The moment some sprite comes into the contact with that position, that sprite will become dragged and will teleport to the mouse.

https://github.com/user-attachments/assets/a1dfc95c-aade-4a58-8444-6b4101f71417

While the direct consequences of the bug are minor, the main problem caused by it is actually performance. While doing it, it ends up calling pick(x, y), which runs for a single pixel on the CPU and requires silhouettes. For that it ends up calling unlazy() on every visible skin. Some extensions (e.g. Simple3D) add large dynamic skins, for which calling gl.readPixels can noticeably degrade performance.

Here is a screenshot that demonstrates console.log(new Error("unlazy")) being inserted to run every time unlazy() is called. The first part is the mouse down, the 1240 calls at the middle part are mouse move amd the last part is mouse up.

Image

This doesn't happen to Pen layer, because it is excluded from pick(x, y):

Image

Xeltalliv avatar Jun 06 '25 22:06 Xeltalliv

i was going to fix the performance by making all the pick() places only consider drawables corresponding to targets but I forgot text bubbles exist and are intended to block clicking on what's below so this will be a bit more annoying than a simple one line patch but it will be fixed soon

GarboMuffin avatar Jun 06 '25 23:06 GarboMuffin

Probably I will add an attribute like excludeFromPick or interactive to Drawable which will exclude it from pick() by default

The private field is already a reasonably similar idea

GarboMuffin avatar Jun 06 '25 23:06 GarboMuffin

I do not understand like the more technical parts of this problem but it pretty much makes 3D mobile games impossible no matter how much u optimise the game

Tobsterzz avatar Jun 07 '25 11:06 Tobsterzz

pick() is still being called more than it should, but pick() now ignores the Simple 3D drawable (and any other drawable marked non-interactive), so the performance impact should be fixed

GarboMuffin avatar Jun 07 '25 23:06 GarboMuffin