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

Bug on Windows: game crashes when the PC wakes up from sleep #688

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

tyomitch
Copy link

@tyomitch tyomitch commented Apr 5, 2020

If I close and reopen my laptop during the game, it crashes with

SDL Error
LockRect(): INVALIDCALL
The error occurred at: ....\SourceX\dx.cpp line 264

I have absolutely no experience with SDL, but I've managed to put
together a workaround. Improvements are welcome.

@ghost
Copy link

ghost commented Apr 5, 2020

Congratulations 🎉. DeepCode analyzed your code in 1.109 seconds and we found no issues. Enjoy a moment of no bugs ☀️.

👉 View analysis in DeepCode’s Dashboard

@AJenbo
Copy link
Member

AJenbo commented Apr 5, 2020

Interesting, ill try and find a laptop to test on :)

@tyomitch
Copy link
Author

tyomitch commented Apr 6, 2020

Interesting, ill try and find a laptop to test on :)

I don't currently have a desktop PC, but I suppose you can get the same effect there by pressing the power button during the game, to send the PC to sleep.

@AJenbo
Copy link
Member

AJenbo commented Apr 6, 2020

I was unable to replicate this both on Linux, and windows 10.

Could you give some specs for you machine and sdl version your using?

@tyomitch
Copy link
Author

tyomitch commented Apr 6, 2020

Fujitsu Lifebook E752, Windows 10 ver. 1909, SDL 2.0.10: https://youtu.be/obSPmm1D580 (sorry for the shaky phone!)

@AJenbo
Copy link
Member

AJenbo commented Apr 6, 2020

Looks like it's an Intel GPU, the Windows machine I tested on had an AMD GPU. I do have a machine with an Intel GPU, but it doesn't have Windows installed.

Could you try SDL 2.0.12?

@tyomitch
Copy link
Author

tyomitch commented Apr 6, 2020

Looks like it's an Intel GPU

Yes, it's Intel HD Graphics 4000

Could you try SDL 2.0.12?

Still the same :-(

SourceX/dx.cpp Outdated
@@ -261,7 +261,31 @@ void RenderPresent()
#ifndef USE_SDL1
if (renderer) {
if (SDL_UpdateTexture(texture, NULL, surface->pixels, surface->pitch) <= -1) { //pitch is 2560
ErrSdl();
// We should supposedly handle SDL_RENDER_DEVICE_RESET, but I tried and it doesn't arrive
if (!strcmp(SDL_GetError(), "LockRect(): INVALIDCALL")) {
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if this could be detected similar to what was done with GetOutputSurface based on the state of the texture. could you check the state of SDL_WasInit() and see what returns?

Copy link
Author

Choose a reason for hiding this comment

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

0xe231 which is the same value as passed to SDL_Init

I guess that only the texture(s) get invalidated by the sleep, not the whole of SDL.

@tyomitch
Copy link
Author

tyomitch commented Apr 7, 2020

Will it help if I upload a dump file, stopped at a breakpoint after the sleep, with the texture invalidated?

@AJenbo AJenbo added this to the 1.3.0 milestone Mar 20, 2021
@julealgon julealgon added the bug Something isn't working label Apr 4, 2021
@AJenbo
Copy link
Member

AJenbo commented Oct 22, 2021

@tyomitch could you test to see if this issue is still present. We are having trouble reproducing it.

@tyomitch
Copy link
Author

@tyomitch could you test to see if this issue is still present. We are having trouble reproducing it.

Yes, the same, except that the failing assertion is now at "....\Source\dx.cpp line 313"

SourceX/dx.cpp Outdated
@@ -261,7 +261,31 @@ void RenderPresent()
#ifndef USE_SDL1
if (renderer) {
if (SDL_UpdateTexture(texture, NULL, surface->pixels, surface->pitch) <= -1) { //pitch is 2560
ErrSdl();
// We should supposedly handle SDL_RENDER_DEVICE_RESET, but I tried and it doesn't arrive
if (!strcmp(SDL_GetError(), "LockRect(): INVALIDCALL")) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if (!strcmp(SDL_GetError(), "LockRect(): INVALIDCALL")) {
if (string_view(SDL_GetError()) == "LockRect(): INVALIDCALL") {

SourceX/dx.cpp Outdated
// We should supposedly handle SDL_RENDER_DEVICE_RESET, but I tried and it doesn't arrive
if (!strcmp(SDL_GetError(), "LockRect(): INVALIDCALL")) {
SDL_DestroyTexture(texture);
SDL_DestroyRenderer(renderer);
Copy link
Collaborator

Choose a reason for hiding this comment

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

It'd probably be a good idea to extract this to a function and also handle SDL_RENDER_DEVICE_RESET

Copy link
Author

Choose a reason for hiding this comment

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

That would be in UiHandleEvents() in DiabloUI/diabloui.cpp right?

Copy link
Member

Choose a reason for hiding this comment

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

UiHandleEvents() runs during the main menu, but in-game it is FetchMessage_Real() in Source/miniwin/misc_msg.cpp

If I close and reopen my laptop during the game, it crashes with

> SDL Error
> LockRect(): INVALIDCALL
> The error occurred at: ..\..\Source\dx.cpp line 313
Also, handle `SDL_RENDER_DEVICE_RESET`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants