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

IOS touch event crashed #2058

Closed
warycat opened this issue Nov 8, 2021 · 4 comments
Closed

IOS touch event crashed #2058

warycat opened this issue Nov 8, 2021 · 4 comments
Labels
C - needs investigation Issue must be confirmed and researched DS - ios F - question There's no such thing as a stupid one

Comments

@warycat
Copy link

warycat commented Nov 8, 2021

I suppose it could be a Xcode configuration error. I have no idea how to fix it.

I have a simple Metal View setup and running showing a simple texture. After I touch the screen it crashed.

Here is the event handling code. It works on my Mac, but crashes on my iPad.

fn handle_window_event(
    event: WindowEvent,
    control_flow: &mut ControlFlow,
    game_state: &mut GameState,
) {
    match event {
        WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
        WindowEvent::MouseInput {
            device_id,
            state,
            button,
            modifiers,
        } => {
            if state == ElementState::Pressed {
                println!("Pressed");
                game_state.index += 1;
                game_state.index %= 60000;
            }
        }
        WindowEvent::Touch(touch) => match touch.phase {
            TouchPhase::Ended => {
                println!("Touched");
                game_state.index += 1;
                game_state.index %= 60000;
            }
            _ => {}
        },
        _ => {}
    }
}

Here is the error showing in console.

2021-11-07 16:21:47.507939-0800 TestWinit[5975:615681] MTLCommandQueue <CaptureMTLCommandQueue: 0x2803dd180> -> <MTLDebugCommandQueue: 0x2835b5980> -> <AGXA12FamilyCommandQueue: 0x13c8581d0>
    label = <none> 
    device = <AGXA12XDevice: 0x13800ea00>
        name = Apple A12X GPU
2021-11-07 16:21:52.087333-0800 TestWinit[5975:615681] *** Assertion failure in -[UIGestureGraphEdge initWithLabel:sourceNode:targetNode:directed:], UIGestureGraphEdge.m:24
2021-11-07 16:21:52.089250-0800 TestWinit[5975:615681] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: sourceNode'
*** First throw call stack:
(0x1827ee04c 0x19ae62f54 0x1840a76cc 0x18524373c 0x184e963bc 0x18509bf98 0x184d5e618 0x184d928c8 0x184d9fa68 0x184f4f318 0x184d72c30 0x184d67a1c 0x184d6cec8 0x182810020 0x182820ce0 0x18275afe8 0x1827607f4 0x1827743b8 0x19e10438c 0x1851146a8 0x184e937f4 0x104f8dc04 0x104f8cc84 0x104f896a4 0x104f87b44 0x108c0da24)
libc++abi: terminating with uncaught exception of type NSException
dyld4 config: DYLD_LIBRARY_PATH=/usr/lib/system/introspection DYLD_INSERT_LIBRARIES=/Developer/usr/lib/libBacktraceRecording.dylib:/Developer/usr/lib/libMainThreadChecker.dylib:/usr/lib/libMTLCapture.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: sourceNode'
terminating with uncaught exception of type NSException

@maroider maroider added DS - ios C - needs investigation Issue must be confirmed and researched F - question There's no such thing as a stupid one labels Nov 8, 2021
@maxammann
Copy link

I can confirm this bug on version 0.24 and 0.26. It also makes the app crash on my iPad. Right now I'm not handling touch events.

@maxammann
Copy link

I have a potential idea why this is happening based on this post: https://developer.apple.com/forums/thread/61432?answerId=204270022#204270022

Let's assume we initialize winit like this:

let mut event_loop = EventLoop::new();
let window = Window::new(&event_loop).unwrap();

event_loop.run(move |event, _, control_flow| {
...
});
  1. First we create a new Window and initialize iOS views:
    let view = view::create_view(&window_attributes, &platform_attributes, frame.clone());
  2. Then we call run():
    pub fn run<F>(self, event_handler: F) -> !

Based on the post from the apple forum, the initialization of the view is happening maybe too early. In fact it is happening before the UIApplication is created.
The views are created as soon as the main() function of the app is called. I suspect that this is too early.

@madsmtm
Copy link
Member

madsmtm commented Sep 8, 2024

Fixed by #3447 and #3826 (we first deprecated, and now disallow creating windows before the application has been initialized).

@madsmtm madsmtm closed this as completed Sep 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C - needs investigation Issue must be confirmed and researched DS - ios F - question There's no such thing as a stupid one
Development

No branches or pull requests

4 participants