Opened 10 years ago

Closed 10 years ago

#2753 closed defect (fixed)

Crash with wsdl when loading a mod with the selector

Reported by: Itms Owned by:
Priority: Release Blocker Milestone: Alpha 17
Component: Core engine Keywords:
Cc: historic_bruno, davidkbolton@… Patch:

Description (last modified by historic_bruno)

On Windows, when loading a mod (f.e. the public mod) with the mod selector, pyrogenesis crashes hard when trying to re-create a wsdl window. For players willing to play anyway: just select the mod, enable it, use the "Save configuration" button and relaunch 0ad. Here is a trace: http://pastebin.com/4hgAbThQ leper would obviously be the most qualified to fix this but I believe historic_bruno has some knowledge about wsdl, so I CC him. I tried to debug that but I'm fairly lost within that low-level code...

Attachments (1)

wsdl-clean-shutdown-wip.diff (2.0 KB ) - added by historic_bruno 10 years ago.

Download all attachments as: .zip

Change History (13)

comment:1 by Niek, 10 years ago

I can confirm the crash

comment:2 by leper, 10 years ago

Sounds like an issue with WSDL not shutting down properly (which causes it to fail init again later on). Can you try using SDL2? (#935 still sounds related)

comment:3 by historic_bruno, 10 years ago

FYI, I had the same problem testing SDL2 (#2041).

comment:4 by leper, 10 years ago

Hm, in that case it is something else than wsdl, but I still suspect an issue with something not shutting down properly. Can anyone print the retval of GetLastError() right after the failing call in wsdl.cpp)?

Unrelated but InitGraphics, Init and Shutdown aren't in the same order; would be worth investigating if g_VideoMode is shutdown properly (eg m_Window).

comment:5 by yashi, 10 years ago

I dug a bit last night. It seems to me that window->magic does not match _this->window_magic after the restart. Thus, IIUC, CHECK_WINDOW_MAGIC() in SDL_SetWindowFullscreen() in CVideoMode::SetVideoMode() failed with "invalid window".

will dig more tonight if my time permits.

Debian Linux Sid with libsdl2-2.0-0:amd64 2.0.2+dfsg1-4

comment:6 by Itms, 10 years ago

About things not behaving well while reloading with mods, the F9 console seems to get deactivated after mod selection.

With default configuration, in the mod selector, if you hit F9 the console appears, but once you've started the public mod nothing happens when hitting F9. Normal behavior when you launch directly the public mod. (see http://irclogs.wildfiregames.com/2014-08-29-QuakeNet-%230ad-dev.log at 21:42).

leper, do you still need the retval from GetLastError or is the window->magic thing the reason to the crash?

in reply to:  5 ; comment:7 by yashi, 10 years ago

OK, here is what I found.

SDL2 does not allow to use old resources, including SDL_Windows, across re-initialization. here is a gist to test just that.

However, g_VideoMode of type CVideoMode holds a reference to SDL_Window as m_Window and this m_Window is re-used in CVideoMode::SetVideoMode() every time it is called.

the current code sequence:

  1. call SetVideoMode() in mod selector and the call initialize m_Window.
  2. mod selector shuts down and SDL_Quit() is called.
  3. do the loop in RunGameOrAtlas() to re-initialize SDL.
  4. call SetVideoMode() and it will re-use m_Window

So, I just killed m_Window in CVideoMode::Shutdown() like this and it seems to work for me. What do you think?

  • source/ps/VideoMode.cpp

    index 9712c5f..dec0db9 100644
    a b void CVideoMode::Shutdown()  
    328333
    329334    m_IsFullscreen = false;
    330335    m_IsInitialised = false;
     336    SDL_DestroyWindow(m_Window);
     337    m_Window = NULL;
    331338}
    332339
    333340void CVideoMode::EnableS3TC()
Last edited 10 years ago by yashi (previous) (diff)

in reply to:  7 comment:8 by historic_bruno, 10 years ago

Replying to yashi:

SDL2 does not allow to use old resources, including SDL_Windows, across re-initialization. here is a gist to test just that.

That's probably the same bug that broke Atlas w/ SDL2 when starting it from the main menu. I will commit a fix to the sdl2-support git branch.

There is no SDL_DestroyWindow in SDL 1.2 though, so it must be a different if similar bug.

comment:9 by historic_bruno, 10 years ago

Though I'm not sure it's entirely necessary or desirable to restart the engine to switch mods, perhaps it's cleaner than trying to free only certain resources.

comment:10 by historic_bruno, 10 years ago

Description: modified (diff)

Debugged this a bit with WSDL, CreateWindowExW is failing with ERROR_INVALID_PARAMETER (no, WSDL doesn't bother telling us error codes...) There is a comment a few lines before that I believe explains this:

// ignore failure, which is probably caused by not unregistering the class

It seems RegisterClassW fails and returns 0. To "reuse" the class as the comment explains would require storing it in a global variable or something, and similar to unregister it on shutdown. The official SDL has logic for that.

I made a quick patch to fix this, but there are only more problems. The new window is created and looks ok, but keyboard input stops working and there is a new error on shutdown. There is a global "is_quitting" variable that never gets reset after shutdown, fixing that leads to even stranger errors. There must be some more global state somewhere...

These problems don't occur with Atlas because wxWidgets is responsible for much of the init. Needless to say I like the idea of restarting the engine even less now than I did before :(

by historic_bruno, 10 years ago

comment:11 by dbolton, 10 years ago

Cc: davidkbolton@… added

comment:12 by historic_bruno, 10 years ago

Resolution: fixed
Status: newclosed

This can be considered fixed, now that SDL2 is used for the Windows build (r15786). The mod selector shouldn't show up in new installs, however, but that's a different issue, along with the ones Itms reported above.

Note: See TracTickets for help on using tickets.