D3DXFONT rendering/releasing weird problems [DX9]

Started by
4 comments, last by WhiteWizardEtc 12 years, 8 months ago
I am currently working on the Graphics portion of my game engine, and have hit a brick wall with font rendering, I have read a whole bunch of tutorials and it seems to be very straight forward, but these weird problems continue popping up. The creation of the font object works properly, HRESULT is ok and the object has a valid address, the d3d_device is fine because i am using to render terrain and objects allready. My problems appear when i got to render the font. the DrawText function itself runs and returns that the correct amount of characters has been written, but immediately after, a whole bunch of totally unrelated object pointers in the main engine loop become corrupter (set to things like 0x0000000f and 0x00000018). If i remove the draw() and just use the create() and release(), it crashes on release() with:

Unhandled exception at 0x76f76579 in ICT311.exe: 0xC0000005: Access violation reading location 0x222c166d.

now for some code.

Creation looks like this:
[source]
m_Font = NULL; //font object

hr = D3DXCreateFont( Direct3D_device, 20, 0, FW_BOLD, 1, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, TEXT("Arial"), &m_Font );
if(FAILED(hr))
{
throw Exception("DX:error loading font\n");
m_Font = NULL;
}
[/source]

~De-constructor:
[source]
if(m_Font!=NULL)
{
m_Font->Release(); //still problems with releasing this
m_Font = NULL;
}

//..a bit later down

//release Direct X stuff
Direct3D_object->Release();
Direct3D_device->Release();
[/source]

within DX::Render()
[source]
D3DCOLOR fontColor = D3DCOLOR_ARGB(255,0,0,255);

RECT rct;
rct.left=2;
rct.right=780;
rct.top=10;
rct.bottom=rct.top+20;

int result = m_Font->DrawText(NULL, TEXT("test text"), -1, &rct, 0, fontColor );
[/source]

Some things that may or may not be related:
  • Im using a pixel shader for the terrain rendering, but have tried setting it to NULL before rendering fonts
  • i have directx debugging enabled and it does not say anything apart from (Ignoring redundant SetRenderState) which i think is elsewhere
  • I do not have WinMain() as my entry point for directX, and instead i retrieve the window handle in the contructor of the graphics class
  • do the world, projection and view matrices affect font rendering? and if so, what should they be set as (similar to hud rendering i assume, but have not tried it yet)
  • i have also tried rendering the font within a sprite, same results

Any help would be much appreciated :), and btw this is my first post, so if i have used the source tags incorrectly then :(
Advertisement
I dont really see anything wrong, is your deconstructor for your font class being called at any time? or do you not have a deconstructor other than the default?

Side note, why do people use the TEXT( ) macro instead of L
hi, thanks for the reply.

I dont have a font class yet, its just sitting in the main directx graphics class, and i have stepped through debugging so i know that the release() is being called, thats where it throws that:
Unhandled exception at 0x76f76579 in ICT311.exe: 0xC0000005: Access violation reading location 0x222c166d.

I get the feeling that this problem has nothing to do with the font class, it just happened to show up when i went to use fonts. But i dont have enough knowledge of directx to know about its inner workings.

Text() seems more readable i guess, for people reading it who dont know what 'L' does.

Side note, why do people use the TEXT( ) macro instead of L



Because TEXT can be changed to mean anything. If you are compiling with different settings you may not want/need the L there. If you had used the L you would have to go through your code and change it everywhere you used L. If you used the TEXT macro you can just change the TEXT macro to mean something else and the code will still work.

Because TEXT can be changed to mean anything. If you are compiling with different settings you may not want/need the L there. If you had used the L you would have to go through your code and change it everywhere you used L. If you used the TEXT macro you can just change the TEXT macro to mean something else and the code will still work.


Thank you for that, it makes sense now.
BUMP

anyone got any ideas? no matter how wild or seemingly obvious.

on a related note, i did some fiddling today and found that if i release the font object right after the creation it runs fine, so something must be happening during update/render that is screwing the font up somehow. Another thing i noticed is that in the D3DXCreateFont() call i can set the text name (Arial etcetc) to whatever i want and it doesnt return errors, eg. Facename = TEXT("asdasdasdasd")

EDIT: later on i did some more testing
I started a new project solution and added in only the bare bones of the graphics system, and it works! So at least now i know there is nothing wrong with my font code, its some other conflict elsewhere and its going to take a longggg time to find

This topic is closed to new replies.

Advertisement