Public Group

# SDL_TTF crashes c++ program?

This topic is 604 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello, this is my first time using this forum so if im doing something wrong please tell me. I am very new to programming and I have been playing around with SDL for a while. I am now trying to display text on the screen using SDL_ttf. Using an internet tutorial, I have made a "Display text" function in my Screen class. Before I added the code my program ran fine. Now it crashes, even if my main function is blank. My ide shows me no error. When I try to run the program in windows cmd i get the error: "The program can't start because SDL2_ttf.dll is missing from your computer. Try reinstalling the program to fix this problem."  This is strange because I can see "libSDL2_ttf.dll.a" in my SDL2 folder.

##### Share on other sites

I can see "libSDL2_ttf.dll.a" in my SDL2 folder.

'*.dll.a' is not a dynamic '.dll' library.  If library ends with .a - then this library is linked statically. In your case it's .dll.a, means it's import library, it tells your compiler's linker to search for actual function in some .dll file, linked later dynamically, by system. You still need libSDL2_ttf.dll

##### Share on other sites

I can see "libSDL2_ttf.dll.a" in my SDL2 folder.

'*.dll.a' is not a dynamic '.dll' library.  If library ends with .a - then this library is linked statically. In your case it's .dll.a, means it's import library, it tells your compiler's linker to search for actual function in some .dll file, linked later dynamically, by system. You still need libSDL2_ttf.dll

This fixed the  "The program can't start because SDL2_ttf.dll is missing from your computer. Try reinstalling the program to fix this problem." but now I get a "The application was unable to start correctly (0xc000007b). Click OK to close the application." error, followed by a crash. Again, my main code is blank, and threes a single class with a header and .cpp (That I haven't even included).

##### Share on other sites

now I get a "The application was unable to start correctly (0xc000007b).

Check that dll you've copied was compiled for the same runtime as your main project. If something won't match (32-bit dll in 64-bit program, debugging/multithreading settings, etc), then program will fail to start.

##### Share on other sites

Ignore this

Edited by starfruit64

##### Share on other sites

now I get a "The application was unable to start correctly (0xc000007b).

Check that dll you've copied was compiled for the same runtime as your main project. If something won't match (32-bit dll in 64-bit program, debugging/multithreading settings, etc), then program will fail to start.

This fixes the "The application was unable to start correctly (0xc000007b)." error. Now i just get a crash. Anytime i use something related to SDL_TTF i get a crash, with no error in Eclipse. Any ideas?

##### Share on other sites

Anytime i use something related to SDL_TTF i get a crash

Now it might be anything, since it's your actions. You'll have to show minimal crashing example, which we can build and test. Maybe you didn't initialize library properly, or misused it in some other way.

##### Share on other sites

Anytime i use something related to SDL_TTF i get a crash

Now it might be anything, since it's your actions. You'll have to show minimal crashing example, which we can build and test. Maybe you didn't initialize library properly, or misused it in some other way.

Alright here is the minimal it takes to crash the program. I tested each step as i added code, and it only crashed once i got to this:

#include <iostream>
#include <fstream>
#include <SDL.h>
#include "SDL_ttf.h"
#include "Input.h"
#include "Screen.h"

const static int WIDTH = 800;
const static int HIGHT = 600;

using namespace std;
int main(int argc, char* argv[]) {

if (SDL_Init(SDL_INIT_VIDEO) < 0) {
SDL_Quit();
}
if (TTF_Init() == -1) {
SDL_Quit();

}

SDL_Window *window = SDL_CreateWindow("test",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED, WIDTH, HIGHT, SDL_WINDOW_SHOWN);
if (window == NULL) {
return false;
}

SDL_Renderer *renderer = SDL_CreateRenderer(window, -1,
SDL_RENDERER_PRESENTVSYNC);
if (renderer == NULL) {
return false;
SDL_DestroyWindow(window);
SDL_Quit();
}

SDL_Texture *texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888,
SDL_TEXTUREACCESS_STATIC, WIDTH, HIGHT);
if (texture == NULL) {
return false;
SDL_DestroyWindow(window);
SDL_DestroyRenderer(renderer);
SDL_Quit();
}

TTF_Font* font = TTF_OpenFont("Sans.ttf", 24);

SDL_Color color = {255, 255, 255};

SDL_Surface* surfaceMessage = TTF_RenderText_Solid(font, "Hello World!", color);

SDL_Texture* message = SDL_CreateTextureFromSurface(renderer, surfaceMessage);
SDL_Rect message_rect;
message_rect.x = 0;
message_rect.y = 0;
message_rect.w = 100;
message_rect.h = 100;

SDL_RenderCopy(renderer, message, NULL, &message_rect);

SDL_Quit();
TTF_Quit();
return 0;
}

Edited by starfruit64

##### Share on other sites

This code would crash if no "Sans.ttf" file could be found in app's current working directory. It doesn't crash otherwise for me. Check what's result from TTF_OpenFont(), is it null or a valid pointer.

1. 1
2. 2
Rutin
19
3. 3
khawk
18
4. 4
5. 5
A4L
11

• 9
• 12
• 16
• 26
• 10
• ### Forum Statistics

• Total Topics
633769
• Total Posts
3013754
×