Skip to content

[GEN][ZH] Fix Alt-tabbing crash #846

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

Merged
merged 2 commits into from
May 19, 2025

Conversation

xezon
Copy link

@xezon xezon commented May 11, 2025

This change fixes the infamous Alt-tabbing crash and is an alternative implementation to #801. The advantage of this change is that it gets rid of what the EA developer has called a "Giant hack" and no longer resets the device with windowed fullscreen from the DXMaximizedWindowedMode shim, which newer version of Windows apply. This makes Alt-tabbing instantaneous without delay, at least when the game resolution matches the desktop resolution. Otherwise it goes through the device reset routine as follows.

Tested with 2560x1440 desktop, 1600x1200 game

WW3D::Begin_Render is resetting the device.
Resetting device.:
ShaderManager ChipsetID 12
Device reset completed
Could not do WW3D::Begin_Render()!  Are we ALT-Tabbed out?
WW3D::Begin_Render is resetting the device.
Resetting device.
ShaderManager ChipsetID 12
Device reset completed
Could not do WW3D::Begin_Render()!  Are we ALT-Tabbed out?
WW3D::Begin_Render is resetting the device.
Resetting device.
ShaderManager ChipsetID 12
Device reset completed
Could not do WW3D::Begin_Render()!  Are we ALT-Tabbed out?

This change adds additional debug logging to all device reset calls. WW3D::Begin_Render typically takes care of resetting the device.

TODO

  • Test on Windows XP?

@xezon xezon added this to the Stability fixes milestone May 11, 2025
@xezon xezon added Bug Something is not working right, typically is user facing Critical Severity: Minor < Major < Critical < Blocker Crash This is a crash, very bad labels May 11, 2025
@aliendroid1
Copy link

aliendroid1 commented May 11, 2025

Debug log: Could not do WW3D::Begin_Render()! Are we ALT-Tabbed out?
You even have it there in your own debug log
This is even happening if I launch the game and never leave the game window.

p.s #801 also makes alt tabbing instantaneous when resolution is the same

@aliendroid1
Copy link

Also with this, if you move the game to a different monitor it moves back on alt tab

@xezon
Copy link
Author

xezon commented May 12, 2025

#801 also makes alt tabbing instantaneous when resolution is the same

Not on my machine. It goes through the device reset code and takes 4 seconds or so to get back in the game, despite the game being technically in windowed mode (because of the DXMaximizedWindowedMode shim)

Debug log: Could not do WW3D::Begin_Render()! Are we ALT-Tabbed out?
You even have it there in your own debug log
This is even happening if I launch the game and never leave the game window.

Also with this, if you move the game to a different monitor it moves back on alt tab

We would need to check if that is new behaviour specific to this change. If not, then can be addressed separately.

@aliendroid1
Copy link

#801 also makes alt tabbing instantaneous when resolution is the same

Not on my machine. It goes through the device reset code and takes 4 seconds or so to get back in the game, despite the game being technically in windowed mode (because of the DXMaximizedWindowedMode shim)

Debug log: Could not do WW3D::Begin_Render()! Are we ALT-Tabbed out?
You even have it there in your own debug log
This is even happening if I launch the game and never leave the game window.

Also with this, if you move the game to a different monitor it moves back on alt tab

We would need to check if that is new behaviour specific to this change. If not, then can be addressed separately.

I found that the first begin render issue is unrelated but I tested and the issue with moving the window to a different monitor is specific to this change. Is the windowed mode shim something you applied or just something modern windows does?

@aliendroid1
Copy link

Also with these changes if you select a resolution that doesn't match your desktop and alt tab then the could not do begin render issue gets logged every time

@xezon
Copy link
Author

xezon commented May 12, 2025

Is the windowed mode shim something you applied or just something modern windows does?

This is what modern Windows applies forcefully and is what leads to this Alt-tabbing crash debacle in the first place. Windows XP will not do this.

Also with these changes if you select a resolution that doesn't match your desktop and alt tab then the could not do begin render issue gets logged every time

Yes. This is ok. Basically Render function will figure out that it cannot render and reset the device when it can again.

the issue with moving the window to a different monitor is specific to this change.

Ok this needs fixing. I do not have a second monitor, so cannot test this right now. How can a fullscreen window be moved to another monitor however? It spawns on one and stays there, no?

@aliendroid1
Copy link

Is the windowed mode shim something you applied or just something modern windows does?

This is what modern Windows applies forcefully and is what leads to this Alt-tabbing crash debacle in the first place. Windows XP will not do this.

Also with these changes if you select a resolution that doesn't match your desktop and alt tab then the could not do begin render issue gets logged every time

Yes. This is ok. Basically Render function will figure out that it cannot render and reset the device when it can again.

the issue with moving the window to a different monitor is specific to this change.

Ok this needs fixing. I do not have a second monitor, so cannot test this right now. How can a fullscreen window be moved to another monitor however? It spawns on one and stays there, no?

Windows + shift + → to move window to different monitor. Also test without the command line arguments for quick start and resolution and see if switching windows is still slow with alt tab using the original fix

@xezon
Copy link
Author

xezon commented May 12, 2025

Windows + shift + → to move window to different monitor.

Ok interesting. I did not know that existed. Does the incorrect reposition only happen with Game Resolution == Desktop Resolution or also with Game Resolution != Desktop Resolution?

@aliendroid1
Copy link

Windows + shift + → to move window to different monitor.

Ok interesting. I did not know that existed. Does the incorrect reposition only happen with Game Resolution == Desktop Resolution or also with Game Resolution != Desktop Resolution?

Both. If the resolution is smaller then it actually gets anchored to the top left corner but that's not specific to these changes

@Mauller
Copy link

Mauller commented May 12, 2025

Works okay for me, i didn't have significant issues before hand and i can see it implicitly handling the render reset.

Would need someone with windows 11 and an nvidia card to try who knows they have issues.

@sorcerer86pt
Copy link

Works okay for me, i didn't have significant issues before hand and i can see it implicitly handling the render reset.

Would need someone with windows 11 and an nvidia card to try who knows they have issues.

Aka myself for example. Win 11 with a rtx 3080

@aliendroid1
Copy link

I've looked into it more and I think it probably is better to merge this now and fix the window location bug separately because the double reset method is overkill and it still doesn't make it work correctly on the second monitor unless both monitors have the same resolution

@xezon xezon added Gen Relates to Generals ZH Relates to Zero Hour labels May 16, 2025
Copy link

@Mauller Mauller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As people with the issue say that this resolves the problem i will approve it.
I don't get the problem but the changes are sensible as the game already checks for device loss and appropriately recovers without the need for the dirty hack.

@xezon
Copy link
Author

xezon commented May 17, 2025

Do we have anyone that can test on Windows XP?

@xezon
Copy link
Author

xezon commented May 18, 2025

fix the window location bug separately

Will you be able to fix this? Unfortunately I cannot test this here because I only have one monitor.

@aliendroid1
Copy link

fix the window location bug separately

Will you be able to fix this? Unfortunately I cannot test this here because I only have one monitor.

I believe so. I was waiting on this pr and #541. I'll start working on it.

@Mauller
Copy link

Mauller commented May 19, 2025

Do we have anyone that can test on Windows XP?

At this point i don't think we would want to worry about compatibility for anything older than windows 7 x32.

@xezon
Copy link
Author

xezon commented May 19, 2025

Ok

@xezon xezon force-pushed the xezon/fix-alt-tab-crash branch from 1b10d4b to 4df5354 Compare May 19, 2025 19:50
@xezon
Copy link
Author

xezon commented May 19, 2025

I removed the logging from this change because it is not necessary for the fix and I will add that logging with a separate change instead.

@xezon xezon merged commit 9ff7ba2 into TheSuperHackers:main May 19, 2025
19 checks passed
@xezon xezon deleted the xezon/fix-alt-tab-crash branch May 19, 2025 20:45
@sorcerer86pt
Copy link

Finally

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something is not working right, typically is user facing Crash This is a crash, very bad Critical Severity: Minor < Major < Critical < Blocker Gen Relates to Generals ZH Relates to Zero Hour
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Windows 10: Game crashes on ALT+Tab
4 participants