Jump to content
  • Advertisement
Sign in to follow this  

D3D9 Font C++. In need of help.

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, been scouting the forums for some time when I've been stuck but never signed up before. And I have a little "Access violation problem", I am a beginner of both c++ and dx9 so it's probably nothing hard. Thanks in advance. First, my Font class.
class dmText
void CreateText();
void NullFont();
void RenderText(int x,int y, LPCWSTR dmString);

static LPD3DXFONT dmFont;

I use CreateText to create the Font. RenderText to render Text and NullFont to rlease it after it being done rendering. (I havn't added all functions I want yet so don't diss it completely ;) )
void dmText::CreateText()
D3DXFONT_DESC FontDesc = {24,


void dmText::RenderText(int x,int y, LPCWSTR dmString)

RECT fontPlace = {x,y,800,600};


void dmText::NullFont()

if(dmFont != NULL)
 dmFont = NULL;

That's that. It's corectly set up, and it's then renderd. After adding brakepoints and watching it, it gets renderd corectly once, then it crashes selecting.

In this function.
void MainRender()

dx_d3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(80,120,50), 1.0f, 0 );

// Begin the scene
if( SUCCEEDED( dx_d3dDevice->BeginScene() ) )

// End the scene

    dx_d3dDevice->Present( NULL, NULL, NULL, NULL );

All Lib's and headers included.
#include <Windows.h>
#include "d3dx9.h"
#include <mmsystem.h>
#pragma warning( disable : 4996 )
#include <strsafe.h>
#pragma warning( default : 4996 ) 
#include "dinput.h"
#pragma comment(lib,"d3d9.lib")
#pragma comment(lib,"dxerr9.lib")
#pragma comment(lib,"dinput8.lib")
#pragma comment(lib,"dxguid.lib")
#pragma comment(lib,"dinput.lib")

I guess it has something to do with it not getting released and nulled right, but after messing with it for a good while I figured that I'm in need of help. Thanks a lot in advance. EDIT: Exact error message. Unhandled exception at 0x00401688 in DM.exe: 0xC0000005: Access violation reading location 0x00000000.

Share this post

Link to post
Share on other sites
That error is telling you that you are trying to acces some object that is pointing to 0x0000. This implies one of 2 things. Either you are incorrectly initializing some object (check error messages), are you destroy an object then try to use it again.

Either way, you need to make sure you are running with the debug runtimes and read your DirectX error messages. These will be much more specific and will give yo VERY good idea why your functions are failing.

Share this post

Link to post
Share on other sites
pmsText.NullFont() is destroying the internal dmFont object, then the next time you execute MainRender and try to call pmsText.RenderText, it will attempt to dereference dmFont (which has been set to NULL) and this results in an access violation.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!