SDL_TEXTUREACCESS_STREAMING + window resize = crash

Using SDL2.04 on Windows I’m getting a crash that I can recreate easily in a simple test app.

I’m using SDL_TEXTUREACCESS_STREAMING to write pixels to a texture, which works great. The problem is when the window is resized by the operating system, it crashes, even before I use the streaming texture.

This code recreates the crash. What am I doing wrong? If I don’t create the streaming texture, everything works fine.

Code:

#include <SDL.h>

int main(int argc, char *argv[]) {
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, “0”);
SDL_Init(SDL_INIT_EVERYTHING);
SDL_DisplayMode desktopMode;
SDL_GetDesktopDisplayMode(0, &desktopMode);
SDL_Window *screenWindow = SDL_CreateWindow(“Test”, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
desktopMode.w / 2, desktopMode.h / 2, SDL_WINDOW_RESIZABLE);
SDL_Renderer *renderer = SDL_CreateRenderer(screenWindow, -1, SDL_RENDERER_PRESENTVSYNC);
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
SDL_Texture *gameTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGB888,
SDL_TEXTUREACCESS_TARGET, 64, 64);
SDL_Texture *test = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGB888,
SDL_TEXTUREACCESS_STREAMING, 64, 64);
int line = 0;
SDL_Event event;
bool running = true;
while(running) {
while(SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_QUIT:
running = false;
break;
case SDL_KEYDOWN:
switch(event.key.keysym.sym) {
case SDLK_ESCAPE:
running = false;
break;
}
}
}
SDL_SetRenderTarget(renderer, gameTexture);
SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE);
SDL_RenderClear(renderer);
if(line >= 64)
line = 0;
else
line++;
SDL_SetRenderDrawColor(renderer, 0, 255, 0, SDL_ALPHA_OPAQUE / 2);
SDL_RenderDrawLine(renderer, 0, line, 63, line);
SDL_SetRenderTarget(renderer, nullptr);
SDL_RenderCopy(renderer, gameTexture, nullptr, nullptr);
SDL_RenderPresent(renderer);
}
SDL_DestroyTexture(test);
SDL_DestroyTexture(gameTexture);
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(screenWindow);
SDL_Quit();
return 0;
}

I have noticed a very similar problem. (Windows 10, MinGW-w64, SDL 2.0.4 stable release)

If any texture exists at the time the window is resized, that was created by SDL_CreateTexture, no matter whether its access is SDL_TEXTUREACCESS_STREAMING or SDL_TEXTUREACCESS_STATIC, the app crashes due to a memory access violation.

Textures created by SDL_CreateTextureFromSurface do not cause this problem.

The problem only occurs with the DirectX renderer. The OpenGL renderer and software renderer do not have this issue.

I have noticed a very similar problem. (Windows 10, MinGW-w64, SDL 2.0.4
stable release)

If any texture exists at the time the window is resized, that was created
by SDL_CreateTexture,
no matter whether its access is SDL_TEXTUREACCESS_STREAMING or
SDL_TEXTUREACCESS_STATIC, the app crashes due to a memory access
violation.

This looks like bug https://bugzilla.libsdl.org/show_bug.cgi?id=3147, which
was fixed with commit https://hg.libsdl.org/SDL/rev/17e0ded12e6f

Basically, it crashed on resize if there were any textures present that had
a non-native pixel format.

KaiOn Sun, Jul 24, 2016 at 6:57 PM, rsethc wrote: