The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
SDL_TEXTUREACCESS_STREAMING + window resize = crash
AntTheAlchemist


Joined: 13 Feb 2015
Posts: 60
Location: UK
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;
}
capehill


Joined: 13 Feb 2016
Posts: 18
Which renderer you are using/getting? (you can query this information from renderer object)
rsethc


Joined: 24 Jul 2016
Posts: 1
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.
SDL_TEXTUREACCESS_STREAMING + window resize = crash
Kai Sterker
Guest

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

Quote:
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.


Kai