Jump to content

  • Log In with Google      Sign In   
  • 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.

  • You cannot reply to this topic
4 replies to this topic

#1 Beshon   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

 



Sponsor:

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

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;
}

 

smile.png


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.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


#3 rip-off   Moderators   -  Reputation: 8713

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.



#4 Beshon   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.


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

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.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]





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