• Create Account

# SDL_ttf crashing at address 0x0000000

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

4 replies to this topic

### #1Beshon  Members   -  Reputation: 108

Like
0Likes
Like

Posted 08 May 2013 - 04:16 PM

The error is Unhandled exception at 0x6F4C2A9D (SDL_ttf.dll) in helloWorld.exe: 0xC0000005: Access violation reading location 0x00000000

The error is coming up at line 'text = TTF_RenderText_Blended(font, "Hello World!", color3);'

I looked it up and most people are saying its something to do with trying to nullify a pointer which is already null but as far as I can tell this isn't the issue here, so any help from someone would be really appreciated.

Full code is at http://pastebin.com/LhrZEga6

Code before the error occurs is below

#include "SDL.h"
#include "SDL_ttf.h"

int main( int argc, char* args[] )
{
//Start SDL
SDL_Init( SDL_INIT_EVERYTHING );
TTF_Init();

//Font stuff
TTF_Font* font = TTF_OpenFont("Arial.ttf", 32);

//Creates game screen and image object
SDL_Surface* screen, *image, *text;
screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE);

//Creates game loop
bool running = true;

//Creates text
SDL_Color color3 = {0xff, 0xff, 0xff};
text = TTF_RenderText_Blended(font, "Hello World!", color3);


Thanks again

### #2Servant of the Lord  Crossbones+   -  Reputation: 14400

Like
0Likes
Like

Posted 08 May 2013 - 04:39 PM

You didn't check whether 'font' loaded correctly:

if(!font)
{
std::cout << "An error occured loading the font \"" << filepath << "\".\n"
<< "TTF_OpenFont() says: \"" << TTF_GetError() << "\"" << std::endl;
return 0;
}

It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.

All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.                                                                                                                                                       [Need free cloud storage? I personally like DropBox]

### #3rip-off  Moderators   -  Reputation: 6593

Like
0Likes
Like

Posted 08 May 2013 - 04:49 PM

All your SDL calls should have error checking. For example, TTF_Init() could be failing too.

### #4Beshon  Members   -  Reputation: 108

Like
0Likes
Like

Posted 08 May 2013 - 05:08 PM

Ah thanks a bunch

It ended up being that I had to include the full directory of the font file and not just the name!

Thanks again

Edited by Beshon, 08 May 2013 - 05:13 PM.

### #5Servant of the Lord  Crossbones+   -  Reputation: 14400

Like
1Likes
Like

Posted 08 May 2013 - 05:13 PM

std::cout is a text stream that can be redirected wherever you like. Normally it is directed to the console, but it doesn't have to be.
SDL by default redirects it to a file called stdout.txt that is created in the same folder as your program's executable.

TTF_OpenFont() opens a .ttf file. It expects a file path to an actual file on your computer. Is there a file called "Arial.ttf" next to your executable?
If you want to get a font from the common font folder on your Windows machine, you have to provide the actual path to that folder and give the actual font name. There are some Win32-specific functions that Microsoft provides that can do that.

Windows-specific code for getting the font folder

Edited by Servant of the Lord, 08 May 2013 - 05:21 PM.

It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.

All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.                                                                                                                                                       [Need free cloud storage? I personally like DropBox]

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

PARTNERS