devkitPro / SDL

Simple Directmedia Layer
https://libsdl.org
zlib License
10 stars 12 forks source link

Wii U Render: unsafe to delete a recent render target #76

Open ds-sloth opened 2 weeks ago

ds-sloth commented 2 weeks ago

Bug Report

What's the issue you encountered?

While testing our Wii U port of TheXTech engine (https://github.com/TheXTech/TheXTech), my collaborator @Wohlstand found that the engine crashed when SDL_SetWindowSize is called to resize the window during initialization. We debugged this further and found it was related to similar crashes when the game's render texture is recreated.

For some reason (I couldn't find the root cause), it seems to be entirely unsafe to delete a texture that was used as a render target in the current frame. Perhaps the result is inadequate GPU synchronization, but I don't know.

This affects cases where the user writes code like SDL_RenderSetTarget(renderer, NULL); SDL_RenderDeleteTexture(old_target);, but it also affects seemingly unrelated routines like SDL_WindowResize(window, ...);, which recreate the render target internally. The result is a system hang or an emulator crash.

Our workaround was to disable calls to SDL_WindowResize (which weren't meaningful) on Wii U, and to delete the second-most recent render target (rather than the most recent one) on Wii U. Both of these represent target-specific code which is generally undesirable in our low-maintenance SDL2 ports of the engine.

How can the issue be reproduced?

The easiest way to reproduce this crash is to attempt to resize the SDL window during any code using the renderer. Finding the principles underlying a fix for that crash would likely make fixing the render target deletion crash very easy.

Environment?

I'm using Fedora, but this also affects our CI builds which pull from your Docker image. I really don't think that the environment is related.

Additional context?

N/A

GaryOderNichts commented 2 weeks ago

I assume by SDL_WindowResize you mean SDL_SetWindowSize?

ds-sloth commented 2 weeks ago

Yes, my apologies. I just found this repo today, and wrote these notes from my memory of the issue, which I debugged a few days ago.