0

This is my code:

#include <iostream>
#include <SDL2/SDL.h>
#include <SDL2/SDL_version.h>
#include <SDL2/SDL_image.h>

const int WIDTH = 800, HEIGHT = 600;

int main( int argc, char *argv[] )
{

    std::cout << "can't access main\n";

    if (SDL_Init (SDL_INIT_EVERYTHING) < 0){
        std::cout << "SDL Init Error: " << SDL_GetError() << '\n';
    }

    if (!(IMG_Init(IMG_INIT_PNG) & IMG_INIT_PNG)){
        std::cout << "Fail to Init SDL_Image for .PNG Error: " << IMG_GetError() << '\n';
    }

    SDL_Surface *imgSur = NULL;
    SDL_Surface *window1_Sur = NULL;

    SDL_Rect *destR;
    destR -> x = 0;
    destR -> y = 0;
    destR -> h = 0;
    destR -> w = 0;


    SDL_Window *window1 = SDL_CreateWindow("Hewwo >///<", 
            SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 
            WIDTH, HEIGHT, 
            SDL_WINDOW_ALLOW_HIGHDPI);
    
    if (window1 == NULL){
        std::cout << "Fail to create window: " << SDL_GetError() << '\n';
        return EXIT_FAILURE;
    }

    


    imgSur = IMG_Load("data/pictures/Kohaku_Small.png");

    // imgSur = SDL_LoadBMP("data/pictures/Kohaku_Small.bmp");

    if (imgSur == NULL){
        std::cout << "Error loading data. SDL Error: " << SDL_GetError() << '\n';
    }
    else std::cout << "meh\n";

    SDL_Renderer *renderer;

    renderer = SDL_CreateRenderer(window1, -1, 0);

    SDL_Texture *txtr1 = SDL_CreateTextureFromSurface(renderer, imgSur);

    int imgH = imgSur -> h;
    int imgW = imgSur -> w;

    destR -> h = imgH;
    destR -> w = imgW;


    SDL_SetRenderDrawColor(renderer, 0xff, 0xff, 0xff, 0xff);

    SDL_Event window1_Event;
    bool quit = 0;

    while (!quit){
        if (SDL_PollEvent( &window1_Event)){
            if (window1_Event.type == SDL_QUIT){
                quit = 1;
            }
        }
        SDL_RenderClear( renderer );
        SDL_RenderCopy(renderer, txtr1, NULL, destR);
        SDL_RenderPresent(renderer);
    }

    SDL_DestroyTexture(txtr1);
    SDL_DestroyRenderer(renderer);
    SDL_DestroyWindow(window1);
    SDL_Quit();

    return EXIT_SUCCESS;
}

this is my makefile:

Copycat:
    g++ -I src/include -L src/lib -o Copycat Copycat.cpp -lmingw32 -lSDL2main -lSDL2 -lSDL2_image

when I compile with mingw32-make in VSCode it doesn't return any error and nothing happens at all

I tried debug something to find the problem and turned out it was the #include <SDL2/SDL_image.h> that prevent me from accessing the 'main' function as it can't print out the text. I tried reinstall SDL2 but it still the same, can somebody help me fix this problem?

genpfault
  • 51,148
  • 11
  • 85
  • 139
  • Must be a DLL issue. Launch the program by double-clicking it in the explorer to see the actual error message. Then it'll either say that some DLL is missing, or spew a cryptic message meaning it found an incompatible one. – HolyBlackCat Jan 22 '23 at 18:01
  • I reinstalled the dll and it worked, thanks man – Hoàng Công Vinh Jan 22 '23 at 19:02

0 Answers0