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

Windows: wrong stack pointer for crash log dialog window on non-main thread #8860

Closed
JGRennison opened this issue Mar 13, 2021 · 0 comments
Closed
Milestone

Comments

@JGRennison
Copy link
Contributor

In the current Windows exception handler, a dialog box is shown by changing the instruction and stack pointers and then continuing execution.

_safe_esp is used as the new stack pointer.
ShowCrashlogWindow is used as the new instruction pointer.

_safe_esp is set to a value of the stack pointer of the main thread during initialisation. Therefore, this mechanism is not valid for handling crashes on non-main threads as the wrong stack would be used. When testing on 32 and 64 bit x86 the dialog box indeed failed to be displayed.

As the game loop and other functionality is now no longer in the main thread, crashes which are also not in the main thread can be expected to become less uncommon in future.

I've resolved this in my branch by using the top of stack from the thread environment block for non-main threads, but I don't expect you to necessarily be happy with that solution. I still thought it may be of interest to draw your attention to it though.
I did not add a fix for ARM as I've got no way of testing it, in principle you can use the same mechanism though.
JGRennison/OpenTTD-patches@883e19f

@TrueBrain TrueBrain added this to the 1.11.0 milestone Mar 13, 2021
michicc added a commit to michicc/OpenTTD that referenced this issue Mar 13, 2021
michicc added a commit to michicc/OpenTTD that referenced this issue Mar 13, 2021
michicc added a commit to michicc/OpenTTD that referenced this issue Mar 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants