Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onwheel handler panics at installation with BorrowError on mobile #3523

Open
Madoshakalaka opened this issue Nov 9, 2023 · 5 comments
Open
Labels

Comments

@Madoshakalaka
Copy link
Contributor

Madoshakalaka commented Nov 9, 2023

Problem
onwheel handler panics at installation when used together with certain onpointermove callbacks on mobile after a certain amount of pointermove events. Also reproducible if ontouchmove is used instead of onpointermove event.

Steps To Reproduce
this handler seems to be the culprit

let onwheel = Callback::default();

let onpointermove = use_callback(panning_origin.clone(), {
    let view_box = view_box.dispatcher();
    move |e: PointerEvent, panning_origin| {
        if let Some(o) = **panning_origin {
            let c = calc_pointer_coords(&e.target_dyn_into::<SvgsvgElement>().unwrap(), &e);
            view_box.dispatch((o.0 - c.0, o.1 - c.1));
        }
    }
});

// comment out the {onwheel} line, and the panic disappears.
html!{
  <svg 
     {onwheel} 
     {onpointermove}>
  </svg> 
}

I have boiled my code down to a minimal producing example, here is the repo.

Screenshots
this is the expected behavior. It works on the PC.
expected
However, it panics on the phone after some events.

IMG_0544.mov

(me when I shake my dot too much that it panics)

You can try move in several times, little by little, or you can move a lot at one go, but eventually it will panic (after a fixed amount of events I think)

Noticeably, in my real project, the panic appears much much quickly. Only after less than half second of touch moving. I assume it maybe has to do with the actual onwheel handler.

This is reproduced both on an iPhone and an Android phone.

I tried some workarounds, including converting onpointermove handler to a manual event listener using web_sys; using Callback::from instead of the use_callback hook. Nothing worked.

Here are the panic messages, there are two of them. And they repeat if you keep moving after it panics:

image

image

(debug tips: if you use iPhone, turn on web inspector in the settings, and connect it to a Mac to see the console messages)

Environment:

  • Yew version: 0.21
  • Rust version: nightly and 1.73 both reproduced, likely irrelevant
@Madoshakalaka Madoshakalaka changed the title touch event handlers panic on mobile Certain event handlers panic with BorrowError on mobile Nov 9, 2023
@Madoshakalaka Madoshakalaka changed the title Certain event handlers panic with BorrowError on mobile onwheel handler panics at installation with BorrowError on mobile Nov 9, 2023
@Madoshakalaka Madoshakalaka reopened this Nov 9, 2023
@Madoshakalaka
Copy link
Contributor Author

Also, the content of onpointermove matters. If the onpointermove callback was empty, for example, the panic wouldn't happen

@Madoshakalaka
Copy link
Contributor Author

I tested line by line and it seems that the view_box.dispatch((o.0 - c.0, o.1 - c.1)); line causes the panic

@Madoshakalaka
Copy link
Contributor Author

Madoshakalaka commented Nov 9, 2023

For now, a workaround is to manually register the onwheel handler as shown here . You need an extra let e = e.dyn_ref::<WheelEvent>().unwrap(); in the actual callback.

@Madoshakalaka
Copy link
Contributor Author

update: onpointerup also panics at installation if used together with onpointermove

@Madoshakalaka
Copy link
Contributor Author

Madoshakalaka commented Nov 18, 2023

update: This panic seems to goes away if opt-level is set to either 1 or 'z'. So in most cases, building in release mode would fix the panic.

Or as a workaroud, use opt-level='z' in dev profile by adding this to the Cargo.toml:

[profile.dev]
opt-level = 'z'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant