Weird bug with SDL2 on Android


I wrote an app with SDL2 which generates a map of blocks which all have coordinates and the type of block stored. The actual textures of these blocks are static, so it does not waste memory for each block. So in the constructor of the block class I check whether or not the certain texture already exists or not and creates the texture if not.

When I generate a map with a size of 512x512, all 262144 blocks get initialized in a few seconds and everything works fine.

But when I generate a map with a size of 1024x1024, the app crashes at the creation of the first block. It actually crashes in my texture initialization function when it creates a SDL_Surface with IMG_Load which will be later converted to a SDL_Texture. As I said with a smaller map size everything works fine.

The code where it crashes:

bool C_Texture::InitTexture(std::string path, float scale_w, float scale_h){


SDL_Surface* surface = IMG_Load(path.c_str()); // HERE IT CRASHES

    m1::androidLog("Surface could not be intialised (Texture.cpp 46) ");

SDL_SetColorKey(surface, SDL_TRUE, SDL_MapRGB(surface->format, 0, 255, 255) );

texture = SDL_CreateTextureFromSurface( _GetRenderer , surface );
if(texture == nullptr){
    m1::androidLog("Texture could not be intialized (Texture.cpp 57)");
textureRect->w = surface->w * scale_w;
textureRect->h = surface->h * scale_h;

return texture != nullptr;


The texture Init function is only called once at the creation of the first block because I use static textures as described above.