-
Notifications
You must be signed in to change notification settings - Fork 159
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
Alt+Tab on FullScreen Direct3D game hangs on 3.6.0.X #1287
Comments
I get a different error when running on Windows 7:
This is where it comes from (unfortunately it does not print error code there): Good thing that the problem is reproducible in some way. |
Ah. AGS does not stop running the game and keep redrawing even when window has no focus. Looks like suspending the alt+tabbed game is not working in SDL version yet (I could forget about this). Maybe Direct3D does not like that in fullscreen mode. But I don't remember how it worked in previous versions when Multitasking mode was on. Might be worth comparing, maybe there was some condition that prevented renderer from working that is now not active. UPDATE: interesting, testing 3.5.1 it seems that when the game is in multitasking mode Direct3D frozes up when alt+tabbing. |
Uhm. AGS has |
AGS has two modes: multitasking and non-multitasking, they are controlled by SetMultitaskingMode. In multitasking mode engine supposed to run game loops when alt+tabbed, otherwise it should suspend game execution. I keep forgetting details about allegro version, allegro probably had this as a library feature which AGS relied upon. This is no longer working in SDL version. Yes, As for drawing, I think that this may be dependent on a gfx mode and maybe on renderer too. For example game may loose focus but still be on screen in windowed mode. Or loose focus but be fullscreen on another display (don't remember if it works like that, but probably does?). So this is a complex condition. |
Erh, in the manual page you linked there's the following comment:
This kinda sounds familiar. Maybe the different behavior is due to my graphics card? |
So, more bad news, apparently the engine no longer suspends upon loosing focus since AGS 3.5.1. It works in 3.5.0. I believe this broke after the update mechanic was changed from using allegro's timer to the time period calculation + sleep in the engine itself. If my understanding is correct, allegro pauses its timers when told to suspend, but the new mechanic does not handle this at all. So now this has to be fixed starting from 3.5.1. But I guess this is a separate issue and task on its own. This ticket refers strictly to Direct3D problem, so should stay dedicated to it. The broken game pause is only a reason why this problem became easier to notice. |
SDL has a timer of it's own, does using it helps in any way? If it's the thread sleep in
Edit: Maybe it's worth opening a new issue for this specific? |
It's not about having a timer, it's about being able to suspend it anytime. Or, alternatively, keep running in a loop until certain flag is set/removed. SDL is only useful here if it provides utilities, but 3.5.1 does not have SDL anyway. But modern C++ itself probably has everything necessary for this. Yes of course, this should be a separate issue. |
The change in #1288 will prevent the crash on Directx, and it's a single line change, maybe consider it until the "real" Fullscreen is supported with it? I understand with both PRs both it will stop crashing and have the multitasking back. Then later the refactor for the extra SDL thread can be done when the full-screen selection type is available. |
Alright. Proper fixing everything will take a while anyway. In regards to multitask fix, previously I said it wrong, it is not simply "not enough", it actually cannot be applied to sdl2 version at all as it is, because it will halt the update thread endlessly. The events have to be made processed separately from the game update first. So there seem to still be a number of serious issues in this version, and I better get to work on them asap. |
I actually managed to adjust a fix for 3.6.0 with a minimal addition (81aa550), for some reason this idea did not come to me yesterday. That takes care of suspending game updates while there's no input focus, but I suspect that may be not enough for Direct3D fullscreen situation. BTW, allegro engine version had a mysterious "Delay(1000)" when handling this event, now i think that maybe this was made to make sure that game update is halted before hiding the window... just a guess. |
just for a note, with the temporary fix (#1288) now merged I don't have this problem anymore in Win10. |
I am not entirely sure if this is the same issue I have been experiencing, but it certainly sounds the same. using 3.5.1.12 on Linux and using OpenGL, I also experience hanging of AGS when Alt+Tabing away from the game in fullscreen mode. It seems to be fine in windowed mode. Just Alt+Tabing away doesn't always immediately hang AGS, but if I try to start recording the AGS game with OBS, then it definitely hangs. The hard drive light on my PC also turns on and stays on until I force close AGS. |
@PaddyMac you get this in any game or just a particular one? |
So far, the only game I've tried is The Cat Lady (GoG release). I only know of one other game in my library that I know uses AGS, so I'll give that one a try when I have the opportunity. |
I'm back to this problem, but would need to recall the details. IIRC since the multitasking mode has been fixed; and also meanwhile a proper switch was introduced between "real" and "desktop" fullscreen mode (#1428). Need to double check that "real" fullscreen works correctly on Windows now, and then see what can be done to close this bug report.
The issue reported was experienced with Direct3D exclusive fullscreen mode, for specific reasons. I don't remember anyone mentioning game hanging when using OpenGL before. |
In regards to "multitasking" mode, don't know how i missed this earlier, but i just realized that originally AGS prevented multitasking mode from working in fullscreen at all. This is both mentioned in documentation:
and may be noticed in the code: The silly problem is that this was before engine supported switching between modes at runtime. When introducing the mode switch, i missed this miltitasking restriction, so now it's probably possible to start in windowed mode with multitasking mode on, and then switch to fullscreen, and this mode will be kept. Tbh I suppose that it may be allowed in fullscreen so long as we may prevent renderer from unnecessary render / failing / hanging the program while switched out, but it definitely should be brought to consistent behavior (either allowed in fs or not). |
In regards to hanging, another ridiculous thing which i somehow missed is, our engine code potentially puts the render function in an infinite loop here: https://github.com/adventuregamestudio/ags/blob/release-3.5.1/Engine/ac/draw.cpp#L783 It runs Present attempts indefnitely, hoping that it will eventually succeed. While doing so it will probably not poll system events, etc, so hypothetically may lock the rest of the program. This has to be fixed. |
I think the multitasking setting is now corrected, and should not be applied when not supported: 9f09192 Multitasking is not supposed to work in exclusive fullscreen mode, at all, so that question is closed. However, there's still a problem, that I'm currently looking at: apparently, while switching out from fullscreen, the code execution may get into the endless "try render and present" loop, as there's no condition set when it should not go there or should get out if the game was switched out. As no event polling is done at the same time, the game cannot be restored (as stated in the ticket). So this is a general program logic issue, and has to be fixed. |
@ivan-mogilko after 9f09192 now the engine hangs for me when alt+tab a fullscreen game when using Direct3D renderer on Windows. |
Did not it hang for you before that? This is what the ticket was about. |
Ah! Eureka, I found why it's not resetting in fullscreen. The call to Apparently, when the program is switched out, it's window is reduced a little bit. This makes the engine to receive Lines 1389 to 1394 in e8a1af3
and then eventually here: ags/Engine/platform/windows/gfx/ali3dd3d.cpp Lines 776 to 786 in e8a1af3
This was meant to update renderer mode when the window is resized by the user. But in this case it effectively corrupts the fullscreen mode width & height parameters. Because when it tries to Reset device back, the mode is already different, and it simply cannot init the exclusive fullscreen with these. So, the cause is clear now, and making a quick hackish workaround proved that restoring true parameters make it work. So the remaining issue is to code a clean solution for this. |
Nice catch! Is the event
Exclusive fullscreen. I absolutely believe that the default Fullscreen should be bordless windows, and need the specialized option be set for exclusive fullscreen, since that one seems to make everything go haywire... |
I used the AGS build from here, ran Quest For Glory 2, and the log quickly gets MBs of here's a log where I managed to hang in the very few alt+tabAdventure Game Studio v3.6 Interpreter Copyright (c) 1999-2011 Chris Jones and 2011-2022 others ACI version 3.6.0.36Installing exception handler
Here's a different log where it took me a little more time qfg2vga_alt_tab_bug_log.zip |
Hm, would it work if you try 3.5.1 on same system? |
Erh, apparently no, it hangs in a different way that it captures my mouse forever and I can't kill AGS and need to restart my machine. Used the latest release of AGS 3.5.1, 3.5.1.22. |
For the reference this is how it's handled in SDL2: Does the 3.6.0 sdl2's software renderer work if it's forced to be direct3d in config?
|
The 3.6.0 sdl2's software renderer with direct3d never hangs! So, Yes! Here's the log for this$ ./ags_real.exe --console-attach --log-stdout=main:allAdventure Game Studio v3.6 Interpreter Installing exception handler
|
Well, these logs don't show much tbh, except it's clear that our renderer gets stuck in D3DERR_DEVICELOST for some obscure reason. I hope to find time and compare with SDL2 more closely tomorrow, but a simple hypothesis is that either we do something that we should not, or not do something that is necessary after this is detected. For slightly "better" logs it may be useful to (temporarily) add more debug messages inside all of these loops, and in |
Gave it a shot at adding more log. As I mentioned previously, with d3d not all alt+tabs are hanging, it usually takes some tries to cause a hanging. In the log, the alt+tabs that doesn't hang have a
Take your time, I am only answering quickly because it's the few times I happen to be home lately. |
@ericoporto my tests may be not accurate, or this depends on some factors, but the change I mentioned earlier actually fixes the problem for me on win7. I pushed it as 27306da. I've been running same game using 2 builds with and without this commit, and this actually makes a difference on my machine. Previously you mentioned that it does not fix the problem for you though, but could you test just in case? |
@ivan-mogilko , this change does make it harder for me hit the bug, but I can still cause the situation to happen through alt+tabbing a bit quicker |
Hm, I cannot reproduce this no matter how much I try. Maybe it depends on delay value? In the previous version the delay was 500 ms. EDIT: does this happen in any game, or in particular game / during particular scene? |
Tried 100ms and 1000ms, doesn't change much regards to hanging, but the smaller value reduced the blinking when alt+tab back in - when it works and doesn't hang.
Any game. I can reproduce it even by just loading an empty sierra template game or the one made for the GUI issue. |
So, something I noticed reading your log from above: this is how the switching into the game normally looks like:
This repeats 4 times, but the 5th last time looks like this:
To be precise, following part is missing in the case which leads to the hanging:
It seems like either the program not getting an event from SDL, or the window is not resized back successfully. |
that debug log is from here: Line 839 in 27306da
alt_tab_hang.mp4So just to illustrate how the hanging manifests here, made a video, once the hang happens, the mouse cursor disappears - not sure if the mouse cursor disappearing here is relevant. I need to use Windows Key+Tab to move AGS to a new workspace before I can go back to the previous workspace and use the task manager to kill AGS. Screen recording misses some frames, when alt+tab happens, so I had to film the screen. |
Recently Manu in the forums reported a similar problem, but it requires a GUI to reproduce. Edit: after investigating, the render targets are only recreated at this line Line 2387 in c47baf3
But once the Device is lost once in alt+tabbing, the render targets are deleted in |
That recent crash should be fixed by 278ba3b. But there's still problem that IDirect3DDevice9::Reset fails with code 0x8876086C sometimes (like each second time). EDIT: it seems like this is caused by |
So, apparently, engine also has to react to "switch in" event and release render targets in case we're in real fullscreen mode. After these two commits Direct3D is working again, at least on my system (don't know if anything changed for users who reported original problem in this ticket). |
Here's a log of a hang: log_hang.txt.zip And here is the same hang, but using the AGS 3.6.0.42 release, without the additional debug messages: log_hang2.txt.zip |
I have one small request, could you please print HRESULT as hex [DELETED] incorrect comment. |
Here's the log using %x: log.txt.zip After extra logs: log_v2_ResetD3DDevice.txt.zip From reading online (but not the docs), my guess for the hang would be either, a problem in my computer (drivers?), or some D3D object that is not invalidated/deleted before the device being reset. Maybe I need to add a log when textures and the render surface textures are cleared. log_extra_log_messages.txt.zip |
I was thinking about this, would it make sense to add an |
I don't know if it matters for this issue, but just now I found that potentially there could be render surface pointers not restored after device reset. I only noticed this problem in the current master branch, after PR #2353, where I replaced raw surface pointers with smart ptrs. Since this seem like a legit mistake, I backported the fix to release-3.6.0, e.g. see a4fb5e3 |
I don't have the issue anymore but I also have recently upgraded my Nvidia Drivers that I had not upgraded in two years... I remember before upgrading that I didn't had the issue anymore in 3.6.1 but had in 3.6.0 at the time. I tried previous versions of 3.6.0 and can't reproduce anymore.... So whatever issue that had, it got fixed some time ago, but the one I still had was an issue on my particular computer. |
Describe the bug
This bug has been reported on the forums as crashing here: https://www.adventuregamestudio.co.uk/forums/index.php?topic=58976.msg636635407#msg636635407
I actually don't have a crash on my Windows 10 PC, instead when I alt+tab a fullscreen Direct3D game, it just hangs with the window staying in the background, but I can't alt+tab back to it and the only way to close it is by killing using the task manager
AGS Version
Built directly from the master branch https://github.com/adventuregamestudio/ags/tree/3d0353e36ef55b14fffe3f7515d74adf095415a1
Game
Here's an example game, but it happens with any on this engine build (3.6.0.4 release happens too) game.zip
To Reproduce
Expected behavior
It's expected to alt+tab to any other window on the desktop and alt+tab back
Desktop:
The text was updated successfully, but these errors were encountered: