-
Notifications
You must be signed in to change notification settings - Fork 892
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
Possible Winit segmentation fault on close of application on Mac Os on a Mac Air M1 #3379
Comments
The example doesn't actually seem to be using |
Sorry for the delay in replying.... Yes it is the code that produces the Exception Just re downloaded it to check and also changed to stable, just in case it was nightly that caused the problem. The segmentation fault occurs with both nightly and stable You are correct that the example does not use tiny-skia. It must have been late... (or too early).
Commenting out softbuffer line
Does not produce the segmentation fault on exit at least not on a Mac Air m1. |
The general code in the example is unsafe, so it might not be an UB at the end of the day, the reason why it's unsafe, because people just hacked up something, so it could be not a real world problem, but just some unsound code in the example. Make sure to drop the |
This is related to this issue #3317 , however since softbuffer is using |
Tried again, still cannot reproduce on Macbook Pro w. M2 Pro running macOS Sonoma 14.2.1. While I agree with @kchibisov, I think this kind of thing still shouldn't cause segmentation faults, especially not while releasing objects; to me, that hints more towards a double-free somewhere in Winit or @apps4uco perhaps you can try to wrap the surface creation in an autorelease pool? Something like (using the let mut surface = objc2::rc::autoreleasepool(|_| {
softbuffer::Surface::new(&context, window.clone()).unwrap()
}); |
Hi, If I try to drop the surface and context inside the loop
I get a compile error
Using @madsmtm idea of using objc2 pool gives the same segmentation fault adding these lines right at the end of main.
I get the output
So it appears (to me) to be that the drop of the context is causing the segmentation fault. Its weird that it cant be reproduced on another Mac, on mine it consistently fails. Attaching the current source code |
You can use the |
Thanks for looking into this.... I tried @kchibisov 's suggestion. New code attached. winit-softbuffer-objc2-option.zip I also set the following variables in the shell, as indicated by https://developer.apple.com/library/archive/documentation/Performance/Conceptual/ManagingMemory/Articles/MallocDebug.html MallocStackLogging=1 Output
Note the println of Sleep 1 is never printed I also tried
|
Hmm, just to explore that path, perhaps you could try creating the window, context and surface inside of |
... sure. I delayed the init of the surface as shown:
Still get a segmentation fault. Also using the code shown in comments also produces the same result. Output
Note: println Sleep is not called. |
Huh, with that example I get a segmentation fault too! Hold on, let me try to figure it out. |
Just realized that you can get a report on the process exiting on a Mac, (Im more of a Linux developer ...) |
Ugh, stupid me, I already fixed this in rust-windowing/softbuffer#180, which was why I couldn't seem to find any problem with the code - and then I probably had trouble reproducing because my editor updated the lockfile or something... Run |
Yep that solved it.... Cool thanks for looking into it ... And fixing it |
In a small project that only has 3 direct dependencies, on MacOs M1 there is a segmentation fault on program exit (click on close button) Im not exactly sure what crate is causing the UB so I figured Id report it in case it was winit.
Cargo.toml has
winit-softbuffer-tinyskia.zip
rustc -V
rustc 1.77.0-nightly (3cdd004e5 2023-12-29)
uname -a
Darwin .....-mac-m1 22.5.0 Darwin Kernel Version 22.5.0: Thu Jun 8 22:22:19 PDT 2023; root:xnu-8796.121.3~7/RELEASE_ARM64_T8103 arm64
The text was updated successfully, but these errors were encountered: