-
Notifications
You must be signed in to change notification settings - Fork 288
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
Fix for crash when using NSAutoreleasePool on macOS #1414
base: master
Are you sure you want to change the base?
Conversation
I've attached some crash report info here: Zip contains the results of 10 runs. Each run that crashed (9 of 10) includes a backtrace of all the threads, and if a crash report was output to the terminal that is included as well. The terminal's output of the crash reports did appear threaded, so it's possible there could be multiple crash reports threaded together in the output. Backtraces are clean though. |
How did you create the backtraces? E.g. the stack trace in run05-crash-report.txt does not match the backtrace in run05-backtrace.txt, ideally it would be the one from the crash but it seems to be from some time afterwards? |
I usually do this:
Then the console should contain the crash output as well as the backtraces. |
Yes, that's actually exactly what I did. The stack traces and crash reports do not match. 🤷♂️ Here are some screenshots of the terminal (different kinds of crashes, some with reports output to terminal, some not): more_crash_reports-screenshots.zip It's honestly the weirdest problem I've ever observed/debugged. |
I noticed the crash seems to happen quite often when creating the new display, in
Could you try making some changes to osxgl.m as below and seeing if it makes any difference? Frustrating because I don't have your hardware and I can't ever get it to crash like this.
|
I tried out these changes but unfortunately it didn't seem to have any affect on the amount/number of crashes.
I hear that. I wish there was something I could do to mitigate it. Bear in mind, I'd be more than happy to attempt any other ideas you may want to try out though. |
I'm running a bit low on ideas. Still thinking about the fact the crash seems to come from with Because |
One other thing - I don't think the autorelease pool is needed in |
b0f62ed
to
42588c0
Compare
Problem
This pull request fixes a crash that can occur when using
NSAutoreleasePool
duringal_destroy_display
in macOS. The crash appears inconsistently, at different times, with different types of crashes, and sometimes not at all - but only occurs after a call toal_destroy_display()
. Also, the crashes only began to appear after I upgraded macOS to Ventura (13.1) on M1.I believe it's the result of a double-free.
Possible Solution
To fix this issue, the line
al_free(d)
was removed from the end ofal_destroy_display()
. In this case, I'm guessing the declaration ofALLEGRO_DISPLAY_OSX_WIN* dpy = (ALLEGRO_DISPLAY_OSX_WIN*) d;
at the top of the function within the scope of aNSAutoreleasePool
may have resulted in the[pool drain]
destroyingdpy
. Then, withal_free(d)
having already destroyed the resource, the crash could possibly occur at some managed point after a pool drain, once the draining thread had a chance to address it.Now, I'm not familiar with Objective-C and not entirely confidant with how Allegro 5 manages its memory and contexts internally, so this is just a guess to the solution/cause. Removing the
al_free(d)
(or removing the[pool drain]
line entirely) did stop the crashes.Recreating the Issue
This issue only appeared on macOS (Ventura 13.1, M1), with the fix here resulting in no more crashing.
Also, I tested the change on macOS (Monterey 12.5.1, Intel), which did not produce the issue before, and it still continues to run normally.
Easiest way to reproduce the problem (if you can reproduce the ✨secret hardware configuration✨) might be with this code below. Running the program will likely reproduce a crash 9 out of 10 runs.