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

don't call SDL_DestroyRenderer or SDL_Quit until we get to gfx_sdl_destroy #603

Merged
merged 1 commit into from
May 26, 2024

Conversation

briaguya-ai
Copy link
Collaborator

@briaguya-ai briaguya-ai commented May 25, 2024

soh testing pr: HarbourMasters/Shipwright#4172

in soh, quitting the game using the "Quit" option in the "Ship" menu was leading to garbage values in the config

this was happening because we call SaveWindowToConfig() in the Context destructor

Context::~Context() {
SPDLOG_TRACE("destruct context");
GetWindow()->SaveWindowToConfig();

which makes calls to Get(Width/Height/PosX/PosY)

void Window::SaveWindowToConfig() {
// This accepts conf in because it can be run in the destruction of LUS.
mConfig->SetBool("Window.Fullscreen.Enabled", IsFullscreen());
if (IsFullscreen()) {
mConfig->SetInt("Window.Fullscreen.Width", (int32_t)GetWidth());
mConfig->SetInt("Window.Fullscreen.Height", (int32_t)GetHeight());
} else {
mConfig->SetInt("Window.Width", (int32_t)GetWidth());
mConfig->SetInt("Window.Height", (int32_t)GetHeight());
mConfig->SetInt("Window.PositionX", GetPosX());
mConfig->SetInt("Window.PositionY", GetPosY());
}
}

which all call into mWindowManagerApi->get_dimensions

uint32_t Fast3dWindow::GetWidth() {
uint32_t width, height;
int32_t posX, posY;
mWindowManagerApi->get_dimensions(&width, &height, &posX, &posY);
return width;
}

which in SDL then calls SDL_GL_GetDrawableSize and SDL_GetWindowPosition

static void gfx_sdl_get_dimensions(uint32_t* width, uint32_t* height, int32_t* posX, int32_t* posY) {
SDL_GL_GetDrawableSize(wnd, static_cast<int*>((void*)width), static_cast<int*>((void*)height));
SDL_GetWindowPosition(wnd, static_cast<int*>(posX), static_cast<int*>(posY));
}

which gives us garbage if we've already called

    SDL_DestroyRenderer(renderer);
    SDL_Quit();

so, instead of directly calling these in gfx_sdl_close, we can rely on the fact that these get called when we destruct Fast3dWindow by calling gfx_destroy

Fast3dWindow::~Fast3dWindow() {
SPDLOG_DEBUG("destruct fast3dwindow");
gfx_destroy();
}

which in SDL land is gfx_sdl_destroy

void gfx_sdl_destroy(void) {
// TODO: destroy _any_ resources used by SDL
SDL_DestroyRenderer(renderer);
SDL_Quit();
}

@briaguya-ai briaguya-ai merged commit 0c4b491 into Kenix3:main May 26, 2024
5 checks passed
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

Successfully merging this pull request may close these issues.

1 participant