SDL Forum Index
SDL
Simple DirectMedia Layer Forums
Reply to topic
SDL2 OPENGL SDL_RENDERER_ACCELERATED MEMORY LEAK
derekwtag


Joined: 11 Nov 2016
Posts: 1
Reply with quote
I had a huge memory leak when using SDL_RENDERER_ACCELERATED for creating an SDL_Renderer in Ubuntu 16.04-64Bits.

The leak was shown in the System Monitor but was not detected by Valgrind.

When I replaced SDL_RENDERER_ACCELERATED flag with SDL_RENDERER_SOFTWARE flag, the memory leak disappeared.

The reason to use RENDERER_ACCELERATED flag is that it made our application run faster in displaying images continuously.

Here is a simple C program to demonstrate the issue.

main.c:

#include "SDL.h"
#include "SDL_video.h"

int main(int argc, char* argv[])
{
SDL_Window *SDLWin;
SDL_Event event;

while (1)
{
SDL_Init(SDL_INIT_VIDEO); // init video

SDLWin = SDL_CreateWindow("SDL2 Example", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 60, 40, SDL_WINDOW_OPENGL);

//SDLWin = SDL_CreateWindow("SDL2 Example", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 60, 40, 0); //changing the flag from SDL_WINDOW_OPENGL to 0 does not eliminate the memory leak

SDL_Renderer* SDlRenderer = SDL_CreateRenderer(SDLWin, -1, SDL_RENDERER_ACCELERATED ); //cause a huge memory leak!

//SDL_Renderer* SDlRenderer = SDL_CreateRenderer(SDLWin, -1, SDL_RENDERER_SOFTWARE); //no memory leak

SDL_DestroyRenderer(SDlRenderer);

while (SDL_PollEvent(&event))
{
switch( event.type )
{
case SDL_WINDOWEVENT:
//printf("SDL_WINDOWEVENT\n");
break;
case SDL_KEYDOWN:
printf("SDL_KEYDOWN\n");
break;
case SDL_QUIT:
printf("SDL_QUIT\n");
break;
default:
printf("event type = %d\n", event.type);
break;
}
}

SDL_DestroyWindow(SDLWin);
SDL_QuitSubSystem(SDL_INIT_VIDEO);
SDL_Quit();
SDL_Delay(500);
}

return 0;
}

Makefile:

INCLUDES = -I/usr/include/SDL2

CFLAGS = -g -Wall -Werror -std=c11 $(INCLUDES)

LD = gcc
LDFLAGS =
LDLIBS = -L/usr/lib/x86_64-linux-gnu -lSDL2

SOURCES = main.c
OUT = sdl_opengl

.PHONY: all

all: $(OUT)

$(OUT): $(patsubst %.c,%.o,$(SOURCES))
$(LD) $(LDFLAGS) -o $@ $? $(LDLIBS)

clean:
rm *.o $(OUT)
View user's profileSend private message
nc-pv


Joined: 06 Jan 2017
Posts: 3
Reply with quote
I am experiencing the same.

Did you try to measure the memory consumption? Will it just keep growing beyond any limits?
View user's profileSend private message
SDL2 OPENGL SDL_RENDERER_ACCELERATED MEMORY LEAK
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT  
Page 1 of 1  

  
  
 Reply to topic