Search code examples
csdlsdl-ttf

Process ends at TTF_RenderText_Shaded line


My SDL program contains:

TTF_Init();
TTF_Font *font = TTF_OpenFont("segoeui.ttf",13);
SDL_Color textColor = {0,0,0};
SDL_Color backgroundColor = {34,177,76};
SDL_Surface *myText = TTF_RenderText_Shaded(font,"Some text",textColor,backgroundColor);

When I run the program from the Build and run button in Code::Blocks, there isn't any problem but when I run the program from the folder in Windows Explorer, the window opens and closes directly, and after the window closes, the process isn't running any more and the files stderr.txt and stdout.txt are still there. I've made some tests and found out that it's the line SDL_Surface *myText = TTF_RenderText_Shaded(font,"Some text",textColor,backgroundColor); that seems to end the process just like that like if the End Process button would have been pressed in the task manager.

Why does it do that? How can I fix it?


Solution

  • You should set your font with absolute path and not a relative one. If you plan to do crossplateform deployment, you may want to include something like that:

    TTF_Font *font;
    
    #ifdef _WIN32
        font = TTF_OpenFont("WinPath",13); // The windows path
    #elif  linux
        font = TTF_OpenFont("LinuxPaht",13); // The linux path
    #elif MacOS
        font = TTF_OpenFont("Mac path",13); // The mac path
    #endif
    
    if(font == null)
        // Throw an error, return or whatever.
    

    You can get exact directives at Detect Windows or Linux in C, C++