PointerDragBehavior doesn't cancel drag when you mouse up outside the canvas

  1. Open https://playground.babylonjs.com/#1EBCJY#21 (or most any playground with a PointerDragBehavior).
  2. Drag the green box to the left, continuing off the canvas onto the code editor.
  3. Mouse up while still over the editor.
  4. Mouse over the canvas again.
    Result: drag continues as if the mouse button is still down.
    Expect: drag to be canceled.

Reproes with latest alpha, but not with 4.2, so it seems like this must have recently broken.

Lemme take a look and see what’s going on

Related issue it seems: Scale Gizmos When Cursor Goes Off/On Canvas

Thanks for pointing this one out to me, @Knar

I retested against 5.0.0-alpha.16, presuming that this PR was intended to fix this issue. Now the drag does get canceled in the above case, but it also cancels even if you don’t mouse up while outside the canvas bounds. So, new steps:

  1. Open https://playground.babylonjs.com/#1EBCJY#21 .
  2. Drag the green box to the left, continuing off the canvas onto the code editor.
  3. Mouse over the canvas again (with mouse button still down).
    Result: drag has been canceled, green box doesn’t continue moving.
    Expect: drag to continue.

Reproes in 5.0.0-alpha.16, but not with 4.2, in which the drag continues as expected.

The behavior seems to have changed again in 5.0.0-alpha.17. Now the drag-out-and-back behaves as expected the first time, but not on subsequent drags. Full steps:

  1. Open https://playground.babylonjs.com/#1EBCJY#21 .
  2. Drag the green box to the left, continuing off the canvas onto the code editor.
  3. Mouse over the canvas again (with mouse button still down).
    Result: drag continues, as expected.
  4. Mouse up.
  5. Drag the green box in the same way as before (off the canvas and back on).
    Result: drag cancels as soon as you leave the canvas.
    Expect: drag to continue if you keep the mouse button down, as in Babylon 4.2.

@PolygonalSun, any ideas?

I’m thinking that a change may need to be made to handle the logic for held pointer clicks when the leave the canvas area. As it stands now, when the input leaves the canvas, all pressed pointer buttons are treated as though a pointerup event was created. I think what may need to be done is to extend the context of the pointer input to the window and explicitly handle how the input is interpreted when in the context of the window but not the canvas. I’m still working on a way to accomplish this that isn’t effectively “reinventing the wheel” with the DeviceInputSystem.

I may have been overthinking things. Fix is in PR: DeviceInputSystem: Fix pointer events when cursor leaves canvas by PolygonalSun · Pull Request #10249 · BabylonJS/Babylon.js (github.com)

2 Likes

Working great in alpha.18. Thanks @PolygonalSun!

1 Like