Hi SDL Gurus,
This title is a bit ‘click bait’ but I’m facing a strange (even blocking) problem.
Calling SDL_EventPoll( … ) causes memory to grow on every calls, and that, only on RaspberryPi.
Same code, running on standard Laptop computer, does not cause a such memory grow behavior.
Here is my actual raspbian stack:
+--------------------------------------------------------------------------------------+
| leak.c |
+--------------------------------------------------------------------------------------+
| libSDL2: |
| Package: libsdl2-dev |
| Version: 2.0.5+dfsg1-2 |
| APT-Sources: http://raspbian.raspberrypi.org/raspbian stretch/main armhf Packages |
| Depends: [...] libsdl2-2.0-0 (= 2.0.5+dfsg1-2) |
+--------------------------------------------------------------------------------------+
| xinit |
| Version: 1.3.4-3 |
| APT-Sources: http://raspbian.raspberrypi.org/raspbian stretch/main armhf Packages |
+--------------------------------------------------------------------------------------+
| Linux raspberrypi 4.14.79-v7+ #1159 SMP Sun Nov 4 17:50:20 GMT 2018 armv7l GNU/Linux |
+--------------------------------------------------------------------------------------+
Can someone give a me clue or a way to dig in the problem ?
Is this a known behavior/problem ?
In SDL2, in X11, in a lower piece of software ?
Thanks in advance.
Summary
The following code show in console the memory grow, enabling, disabling SDL_PollEvent().
Same code compiled and executer on x86_64 computer don’t leak memory.
Here is a simple inline example :
#include <SDL2/SDL.h>
#include <stdio.h>
#include <sys/resource.h>
#include <time.h>
int main() {
fprintf(stdout,"Starting ...\n");
if (SDL_Init(SDL_INIT_VIDEO) != 0 ) {
fprintf(stdout,"Video init failed: (%s)\n",SDL_GetError());
return -1;
}
{
SDL_Window* pWindow = NULL;
pWindow = SDL_CreateWindow("Test window", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_SHOWN);
if( pWindow ) {
SDL_InitSubSystem(SDL_INIT_EVENTS);
struct rusage ru_status;
time_t test_phase1_end, test_end, now;
long previous_maxrss;
int delay_60fps_average_ms = 16;
int leaking = 1;
test_end = time(NULL) + 30;
do {
test_phase1_end = time(NULL)+10;
previous_maxrss = 0L;
do {
if (leaking) {
// Here is the important part:
// On Linux 4.10.0-32-generic #36~16.04.1-Ubuntu SMP Wed Aug 9 09:19:02 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
// memory is stable
// On Linux raspberrypi 4.14.79-v7+ #1159 SMP Sun Nov 4 17:50:20 GMT 2018 armv7l GNU/Linux
// memory is growing on every call of SDL_PollEvent / SDL_EventsPump
SDL_Event e;
while ( SDL_PollEvent(&e) ) {}
}
SDL_Delay(delay_60fps_average_ms);
now = time(NULL);
if (getrusage(RUSAGE_SELF, &ru_status)) {
fprintf(stderr,"RUsage gathering failed\n");
}
else {
if (previous_maxrss != ru_status.ru_maxrss) {
fprintf(stdout,"epoch: %10ld SDl_PollEvent: %s Mem: %ld\n", now, leaking?"yes":"no", ru_status.ru_maxrss);
}
previous_maxrss = ru_status.ru_maxrss;
}
} while( now < test_phase1_end );
leaking = leaking?0:1;
} while (now < test_end);
fprintf(stdout,"Exiting ...");
SDL_DestroyWindow(pWindow);
}
else {
fprintf(stderr,"Window creation failed: (%s)\n",SDL_GetError());
}
}
SDL_Quit();
fprintf(stdout,"Done.\n");
return 0;
}
[EDIT1]
Here is the starting point of this story :
Lôve bitbucket bug tracker
[EDIT2]
As a side effect, if I hit and maintain a key down on the keyboard, the code starts slowing down and then crash few seconds later.
May be there is a common point with this (old) following topic :
X11_KeyRepeat crash