dioxus icon indicating copy to clipboard operation
dioxus copied to clipboard

Browser occasionally changes types of events and their fields depending on where they come from

Open esimkowitz opened this issue 1 year ago • 8 comments

Problem

The onpointermove event appears broken on Windows. When a component that binds to this event is present, the moment the user moves the cursor, the main thread panics with an InvalidType error.

Steps To Reproduce

Steps to reproduce the behavior:

  • Create a component that binds to the onpointermove event.
  • On Windows, run dx serve --platform desktop
  • Access the component with the bound event
  • Try moving the mouse
  • Observe that the application crashes

Expected behavior

Binding to the onpointermove event should return an Event<PointerData> event to the event handler.

Screenshots

N/A

Environment:

  • Dioxus version: 0.5.1
  • Rust version: 1.78.0
  • OS info: Windows 11 (22631.3527)
  • App platform: desktop

Questionnaire

  • [ ] I'm interested in fixing this myself but don't know where to start
  • [ ] I would like to fix and I have a solution
  • [x] I don't have time to fix this right now, but maybe later

esimkowitz avatar May 02 '24 19:05 esimkowitz

Adding the stack trace:

thread 'main' panicked at C:\Users\Gaming PC\.cargo\registry\src\index.crates.io-6f17d22bba15001f\dioxus-html-0.5.1\src\transit.rs:41:17:
Failed to deserialize event data for event pointermove:  InvalidType(
    Float(
        462.484375,
    ),
    "i32",
)
'Map(
    {
        String(
            "alt_key",
        ): Bool(
            false,
        ),
        String(
            "button",
        ): I64(
            -1,
        ),
        String(
            "buttons",
        ): U64(
            0,
        ),
        String(
            "client_x",
        ): U64(
            691,
        ),
        String(
            "client_y",
        ): U64(
            176,
        ),
        String(
            "ctrl_key",
        ): Bool(
            false,
        ),
        String(
            "height",
        ): U64(
            1,
        ),
        String(
            "is_primary",
        ): Bool(
            true,
        ),
        String(
            "meta_key",
        ): Bool(
            false,
        ),
        String(
            "offset_x",
        ): F64(
            462.484375,
        ),
        String(
            "offset_y",
        ): F64(
            129.296875,
        ),
        String(
            "page_x",
        ): U64(
            691,
        ),
        String(
            "page_y",
        ): U64(
            176,
        ),
        String(
            "pointer_id",
        ): U64(
            1,
        ),
        String(
            "pointer_type",
        ): String(
            "mouse",
        ),
        String(
            "pressure",
        ): U64(
            0,
        ),
        String(
            "screen_x",
        ): U64(
            907,
        ),
        String(
            "screen_y",
        ): U64(
            435,
        ),
        String(
            "shift_key",
        ): Bool(
            false,
        ),
        String(
            "tangential_pressure",
        ): U64(
            0,
        ),
        String(
            "tilt_x",
        ): U64(
            0,
        ),
        String(
            "tilt_y",
        ): U64(
            0,
        ),
        String(
            "twist",
        ): U64(
            0,
        ),
        String(
            "width",
        ): U64(
            1,
        ),
    },
)'
stack backtrace:
   0:     0x7ff78149f41a - <unknown>
   1:     0x7ff7814c05db - <unknown>
   2:     0x7ff78149b7f1 - <unknown>
   3:     0x7ff78149f206 - <unknown>
   4:     0x7ff7814a162f - <unknown>
   5:     0x7ff7814a12c7 - <unknown>
   6:     0x7ff7814a1b6d - <unknown>
   7:     0x7ff7814a1a29 - <unknown>
   8:     0x7ff78149fd29 - <unknown>
   9:     0x7ff7814a16e6 - <unknown>
  10:     0x7ff7814c9357 - <unknown>
  11:     0x7ff780ef75e4 - <unknown>
  12:     0x7ff780ee97cd - <unknown>
  13:     0x7ff780ef6f6c - <unknown>
  14:     0x7ff780f75a81 - <unknown>
  15:     0x7ff780f18f5a - <unknown>
  16:     0x7ff780f026f3 - <unknown>
  17:     0x7ff780f65a1c - <unknown>
  18:     0x7ff780f8e645 - <unknown>
  19:     0x7ff780f82834 - <unknown>
  20:     0x7ff780f35f84 - <unknown>
  21:     0x7ff780f54904 - <unknown>
  22:     0x7ff780f5a493 - <unknown>
  23:     0x7ff780f542da - <unknown>
  24:     0x7ff780f788d9 - <unknown>
  25:     0x7ff780f801c5 - <unknown>
  26:     0x7ff780f8255b - <unknown>
  27:     0x7ff780f7ff1c - <unknown>
  28:     0x7ff780f708c3 - <unknown>
  29:     0x7ff780f70718 - <unknown>
  30:     0x7ff780eb8fd7 - <unknown>
  31:     0x7ff780f36011 - <unknown>
  32:     0x7ff780f5485d - <unknown>
  33:     0x7ff780f5a493 - <unknown>
  34:     0x7ff780f5470b - <unknown>
  35:     0x7ff780f788c1 - <unknown>
  36:     0x7ff780f81372 - <unknown>
  37:     0x7ff780f6fc99 - <unknown>
  38:     0x7ffd096cd7bc - DefSubclassProc
  39:     0x7ffd096cd65c - DefSubclassProc
  40:     0x7ffd180289a1 - DispatchMessageW
  41:     0x7ffd18028461 - DispatchMessageW
  42:     0x7ff780f5a13f - <unknown>
  43:     0x7ff780f65779 - <unknown>
  44:     0x7ff780f65dfb - <unknown>
  45:     0x7ff780f7f6e1 - <unknown>
  46:     0x7ff780f02202 - <unknown>
  47:     0x7ff780f02c2e - <unknown>
  48:     0x7ff780eefa27 - <unknown>
  49:     0x7ff780eef94c - <unknown>
  50:     0x7ff780f87000 - <unknown>
  51:     0x7ff780f86a91 - <unknown>
  52:     0x7ff780eadff6 - <unknown>
  53:     0x7ff780f7c149 - <unknown>
  54:     0x7ff780f57f28 - <unknown>
  55:     0x7ff780f7c104 - <unknown>
  56:     0x7ff780f0a5b7 - <unknown>
  57:     0x7ff780f02a80 - <unknown>
  58:     0x7ff780f02e6e - <unknown>
  59:     0x7ff780ea83f2 - <unknown>
  60:     0x7ff780ca4988 - <unknown>
  61:     0x7ff780ca22be - <unknown>
  62:     0x7ff780ca1252 - <unknown>
  63:     0x7ff780ca1f3b - <unknown>
  64:     0x7ff780ca12ee - <unknown>
  65:     0x7ff780ca1631 - <unknown>
  66:     0x7ff781497582 - <unknown>
  67:     0x7ff780ca160a - <unknown>
  68:     0x7ff780ca12d9 - <unknown>
  69:     0x7ff7814c695c - <unknown>
  70:     0x7ffd184f257d - BaseThreadInitThunk
  71:     0x7ffd19d8aa48 - RtlUserThreadStart

esimkowitz avatar May 02 '24 19:05 esimkowitz

I am unable to reproduce it on Windows 10. Perhaps it's a Windows 11 issue? I used this code snippet (is this what causes the crash for you?)

rsx! {
    div {
        style: "width: 10vw; height: 10vh; background-color: red;",
        onpointermove: move |data| {
            println!("hi | {:?}", data);
        }
    }
}

DogeDark avatar May 03 '24 05:05 DogeDark

I am unable to reproduce it on Windows 10. Perhaps it's a Windows 11 issue? I used this code snippet (is this what causes the crash for you?)

Yeah this is what caused the issue for me. The event handler is never getting reached, it seems like it's crashing in the event mapping code. I can try to dig into it a bit more and see if there's some field that is getting added for Windows 11 that we're missing.

esimkowitz avatar May 03 '24 18:05 esimkowitz

Same issue here, It panics on any input (mouse or pen input) on windows 11.

Doublonmousse avatar Jun 21 '24 09:06 Doublonmousse

All fields are named correctly, the issue is types, hence the

 InvalidType(
    Float(
        462.484375,
    ),
    "i32",

messages.

The weird part is that types aren't constant either depending on the state of the pointer

Doublonmousse avatar Jul 06 '24 21:07 Doublonmousse

name type expected by dioxus windows 11, pen hover and mouse windows 11, touch press windows 11, pen press guess
           
alt_key bool bool bool bool bool
button i16 i64 i64 i64 i64
buttons u16 u64 u64 u64 u64
client_x i32 f64 f64 u64 f64
client_y i32 u64 f64 f64 f64
ctrl_key bool bool bool bool bool
height i32 u64 u64 u64 f64
is_primary bool bool bool bool bool
meta_key bool bool bool bool bool
offset_x i32 f64 f64 f64 f64
offset_y i32 u64 f64 f64 f64
page_x i32 f64 f64 u64 f64
page_y i32 u64 f64 f64 f64
pointer_id i32 u64 u64 u64 u64
pointer_type string string string string string
pressure f32 u64 f64 f64 f64
screen_x i32 f64 f64 u64 f64
screen_y i32 u64 f64 f64 f64
shift_key bool bool bool bool bool
tangential_pressure f32 u64 u64 u64 f64
tilt_x i32 u64 u64 u64 i64
tilt_y i32 u64 u64 u64 i64
twist i32 u64 u64 u64 u64
width i32 u64 f64 u64 f64

Doublonmousse avatar Jul 06 '24 21:07 Doublonmousse

Ok, I have a working version here https://github.com/Doublonmousse/dioxus for windows 11.

Type changes are of the types i16 -> i64, i32 -> i64, i32 -> u64 (there may be ways to cast the values when deserializing) but there's a couple of i32 -> f64 changes that'd be a little more challenging.

And some f32 -> f64 too

I'm not sure the debug print for onpointermove shows everything I'd want to test yet (are all button presses and release events captured for a pen that's hovering? Same thing for a pen on the screen. Is the eraser correctly detected ?)

Doublonmousse avatar Jul 06 '24 22:07 Doublonmousse

We now handle events without pancking - just fail to deserialize - but we really need to fix the underlying bug.

It doesn't look like we'll be able to fix it for 0.6.0 release but might be able to later during the 0.6.0 release cycle.

jkelleyrtp avatar Aug 21 '24 00:08 jkelleyrtp