Jump to content
  • Advertisement
Sign in to follow this  
Calin

ID3DXFont problem

This topic is 4839 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

I am trying to use ID3DXFont. The code gets compiled but when I run the build it crashes instantly. Here is the code I use

//1. Create a pointer at global scope:
 
ID3DXFont *g_font = NULL;

// 2. call  D3DXCreateFont:

        HRESULT rslt=0;

	rslt=D3DXCreateFont(g_pD3D,     //D3D Device
                     22,               //Font height
                     0,                //Font width
                     FW_NORMAL,        //Font Weight
                     1,                //MipLevels
                     false,            //Italic
                     DEFAULT_CHARSET,  //CharSet
                     OUT_DEFAULT_PRECIS, //OutputPrecision
                     ANTIALIASED_QUALITY, //Quality
                     DEFAULT_PITCH|FF_DONTCARE,//PitchAndFamily
                     "Arial",          //pFacename,
              &g_font);
    
// 3. Release the interface in GameShutDown function;

 if(g_font){
      g_font->Release();
      g_font=NULL;
   }

// 4. Call DrawText in my Render() function:


   RECT fontRect;
   SetRect (&fontRect, 50,50,70,70);
   
   char * text = "hello";
   
   g_font->DrawText(NULL,        //pSprite
                                text,  //pString
                                -1,          //Count
                                &fontRect,  //pRect
                                DT_LEFT|DT_NOCLIP,//Format,
                                0xFFFFFFFF); //Color
    


Can someone point me what`s wrong in this code? One more thing the debugger traks down the problem to this line: 0xFFFFFFFF); //Color. [Edited by - Calin on August 16, 2005 6:08:08 AM]

Share this post


Link to post
Share on other sites
Advertisement
Am I missing something or does:

[source lang = "cpp"]

//here you delete "g_font"

if(g_font)
{
g_font->Release();
g_font=NULL;
}

//here you try and use "g_font"

g_font->DrawText(NULL, //pSprite
text, //pString
-1, //Count
&fontRect, //pRect
DT_LEFT|DT_NOCLIP,//Format,
0xFFFFFFFF); //Color




look a trifle fishy?

Share this post


Link to post
Share on other sites
Quote:

What do you when font creation fails?

Nothing up to now. I just began working at this (I am trying to make a log file system)

Share this post


Link to post
Share on other sites
Quote:
Original post by Source
Am I missing something or does:

*** Source Snippet Removed ***

look a trifle fishy?


I didn`t post my entire code. I release the interface in the GameShutDown function. GameShutDown is called when WinMain message loop is done.


[Edited by - Calin on August 16, 2005 11:29:56 AM]

Share this post


Link to post
Share on other sites
Ok, I just added some error lockup code (HRESULT FAILED). D3DXCreateFont fails indeed. Do you know what might be the cause?

Edit: The debugging code:

'Primitives.exe': Loaded 'C:\Documents and Settings\Calin\My Documents\LrnRes\DirectX\Basic features\32bits\The Basics Part 3\2. Formats and Culling\primitives1vb\Debug\Primitives.exe', Symbols loaded.
'Primitives.exe': Loaded 'C:\WINDOWS\system32\ntdll.dll', Exports loaded.
'Primitives.exe': Loaded 'C:\WINDOWS\system32\kernel32.dll', Exports loaded.
'Primitives.exe': Loaded 'C:\WINDOWS\system32\d3d9.dll', Exports loaded.
'Primitives.exe': Loaded 'C:\WINDOWS\system32\d3d8thk.dll', Exports loaded.
'Primitives.exe': Loaded 'C:\WINDOWS\system32\gdi32.dll', Exports loaded.
'Primitives.exe': Loaded 'C:\WINDOWS\system32\user32.dll', Exports loaded.
'Primitives.exe': Loaded 'C:\WINDOWS\system32\msvcrt.dll', Exports loaded.
'Primitives.exe': Loaded 'C:\WINDOWS\system32\advapi32.dll', Exports loaded.
'Primitives.exe': Loaded 'C:\WINDOWS\system32\rpcrt4.dll', Exports loaded.
'Primitives.exe': Loaded 'C:\WINDOWS\system32\version.dll', Exports loaded.
'Primitives.exe': Loaded 'C:\WINDOWS\system32\winmm.dll', Exports loaded.
'Primitives.exe': Loaded 'C:\WINDOWS\system32\d3dx9_26.dll', Exports loaded.
-------------------------------------------32Bits.co.uk Error Handling-
The following error occurred on line 246 of c:\documents and settings\calin\my documents\lrnres\directx\basic features\32bits\the basics part 3\2. formats and culling\primitives1vb\sg0_03.cpp
D3DERR_INVALIDCALL
Extra information: D3DXCreateFont() failed.
The program '[1260] Primitives.exe: Native' has exited with code -1 (0xffffffff).
[\source]



[Edited by - Calin on August 16, 2005 12:48:41 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by Calin
Ok, I just added some error lockup code (HRESULT FAILED). D3DXCreateFont fails indeed. Do you know what might be the cause?


The most common cause is an invalid device pointer. Are you sure the device is valid at the time you are passing it to D3DXCreateFont? Based on the log you posted it doesn't appear to have been initialized.

Share this post


Link to post
Share on other sites
I have a similar problem (crashing instantly) though my crash isn't due to a null pointer (or atleast the logs don't show it). It looks to me like your problem is:


if (g_font)
{
g_font->DrawText(NULL, //pSprite
text, //pString
-1, //Count
&fontRect, //pRect
DT_LEFT|DT_NOCLIP,//Format,
D3DCOLOR_ARGB(255,255,255,255); //Color
}
else
add_log("Warning: g_font->DrawText(), g_font NULL!");



Try and fix that and see how it goes.

Edit: changed the color code, should work properly now.

[Edited by - CodeMaster Rapture on August 16, 2005 4:26:52 PM]

Share this post


Link to post
Share on other sites
CodeMaster Rapture: A Null pointer was the reason why my game crashed.


The following error occurred on line 246 of c:\documents and settings\calin\my documents\...\sg0_03.cpp
D3DERR_INVALIDCALL
Extra information: D3DXCreateFont() failed.





The problem is situated somewhere in the D3DXCreateFont(). Anyways, thanks for trying to help.

Share this post


Link to post
Share on other sites
DrunkenHyena you are right. I`v placed my D3DXCreateFont function before my
D3D Initialization code. Thanks so much. Rating ++

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!