SDL2-image won't load textures (but surfaces work) and i don't get any error message

221 Views Asked by At

i am making a game using SDL2, using IMG_LoadTexture() to load images, and it works fine on my main computer, but i recently acquired a new laptop, and the same code on this new machine won't load textures, but SDL doesn't give me any error message.

  • IMG_LoadTexture() returns null
  • IMG_GetError() and SDL_GetError() give me nothing (which is weird, since IMG_LoadTexture() returning null means an error occured)
  • Loading surfaces (IMG_Load()) works
  • I work on msys2/mingw64 and launch the executable from the MSYS2/MINGW64 shell, checked for zlip and libpng, everything is here
  • Checked SDL initialization, SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) returns 0 (no error), IMG_Init(IMG_INIT_PNG | IMG_INIT_JPG) returns 3 (no error), same outputs as on the other computer where everything works.
  • Happens with all tested image formats (png, jpg, bmp)

The code

does anyone have any idea about what could be the cause of such a situation ? In the mingw install or something ?

Reproducing this

Here are the steps that led to the situation :

  • Install msys from the official website

  • install the following libraries using pacman :

    • base
    • make
    • mingw-w64-x86_64-gcc
    • mingw-w64-x86_64-SDL2
    • mingw-w64-x86_64-SDL2_image
  • Compile the following program :

    #include "SDL2/SDL.h"
    #include "SDL2/SDL_image.h"
    #include "SDL2/SDL_syswm.h"
    #include <iostream>    
    int main(int argc, char** argv){
    
        int res = SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK);
    
        std::cout << res << '\n';
        if ( res < 0){
            printf("Couldn't initialize SDL (%d): %s\n", res, SDL_GetError());
            exit(1);
        }
    
        res = IMG_Init(IMG_INIT_PNG | IMG_INIT_JPG);
    
        std::cout << res << '\n';
        if (res < 0) {
            printf("Couldn't initialize SDL Image (%d): %s\n", res, IMG_GetError());
            exit(1);    
        };
    
        int rendererFlags = SDL_RENDERER_ACCELERATED;
        int windowFlags = 0;
    
        SDL_Window* window = SDL_CreateWindow("KuriX", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 800, 600, windowFlags);
    
        if (!window){
            printf("Failed to open %d x %d window: %s\n", 800, 600, SDL_GetError());
            exit(1);
        }
    
        SDL_SysWMinfo win_info;
    
        SDL_VERSION(&win_info.version);
        SDL_GetWindowWMInfo(window, &win_info);
    
        SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
    
        SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, rendererFlags);
    
        if (!renderer){
            printf("Failed to create renderer: %s\n", SDL_GetError());
            exit(1);
        }
    
        SDL_Texture* t = IMG_LoadTexture(renderer, "JPGTest.jpg");
        std::cout << t << '\n';
    
        if (t == NULL){
            std::cerr << "Error ! Message : " << IMG_GetError() << '\n';
        }
    
        return 0;
    }
    
  • compile/link with

    g++ testSDL.cpp -o out.exe `sdl2-config --cflags --static-libs` -Wall -g -std=gnu++2a -static-libgcc -static-libstdc++ -lSDL2_image -lm
    

    Output :

    0
    3 
    0
    Error ! Message :
    

Keep in mind that the same code, using the same libraries, works fine on my main computer, and all previous computers i used previously. Something must have went wrong with the installation on the new laptop, but i just don't see what.

0

There are 0 best solutions below