directx return values

Started by
6 comments, last by lakibuk 23 years, 10 months ago
If you do things with directx, e.g. creating a surface, you get a return value like DD_OK or some error value. Is it possible to show on the screen, what value was returned. It need this especially for debugging purposes. How can it be done,if you just show the value,you only see a number. How to see the return-values name (like DD_SURFACELOST).
Karl - Blueskied Games | my german site: Gratis Spiele
Advertisement
Hi

The Names are just defines, so they are replaced by the preprocessor. So the Names aren't in the final code, and can't be written out.
One way to get detailed Error Information is to use the errorhandling function from the D3DX Package, but i don't know how good it is.
The other way is, to write your own Function maybe like that :

    DirectXError(int Error){  switch(Error)  {    case DD_OK :       break;    case DD_LOSTSURFACE :       MessageBox("Uuups i lost that Surface");      break;    .    .    .  }}    


Using your own Function, you have the Advantage of making everything you wan't with the errors, and give them out like you wan't to, mayba to an extra Window or something.

Lars

Edited by - Lars W. on June 18, 2000 7:08:06 AM
--------> http://www.larswolter.de <---------
I got tired of seeing numbers myself So, I wrote up a function for each DX component that converts the return values to strings. Yes, it was tedious. Just big switch statements casing every return code in the docs. I use these in conjuction with an error out function that writes to an error file. So, for example, if I there is an error calling a DirectDraw function:

    HRESULT hrhr = SomeDirectDrawFunctionif (FAILED(hr)){   Error_Out ("SomeDirectDrawFunction failed \n%s\n",          DHR_To_String (hr));}     




Edited by - Aldacron on June 18, 2000 7:19:54 AM
I use the following code (Partially shown):

///////////////////////////////////////////////////////////////////////
// ERROR MESSAGE HANDLING
///////////////////////////////////////////////////////////////////////

BOOL xDDMsg(char* func, HRESULT hr) //Format & Display DD error msgbox
{
char text[64];
char emsg[64];
xlatDDerr( hr, emsg );
sprintf(text,"%s: %s\0",func,emsg);
ErrMsg(text);
return FALSE;
}

BOOL ErrMsg(char* emsg) //Display Message box
{
//lpDD7->FlipToGDISurface();
MessageBox(hDDWnd,emsg,"Direct Draw Error",MB_OK/MB_ICONSTOP/MB_SYSTEMMODAL);
return FALSE;
}

/////////////////////////////////////////////////////////////////////

void xlatDDerr(HRESULT rc, char* EMsg) //translate DD HRESULT codes
{
#ifdef testmode
if(rc==DD_OK) { strcpy(EMsg,"DD_OK"); return; }
if(rc==DDERR_ALREADYINITIALIZED ) { strcpy(EMsg,"DDERR_ALREADYINITIALIZED "); return; }
if(rc==DDERR_BLTFASTCANTCLIP) { strcpy(EMsg,"DDERR_BLTFASTCANTCLIP"); return; }

---etc---

if(rc==DDERR_WASSTILLDRAWING) { strcpy(EMsg,"DDERR_WASSTILLDRAWING"); return; }
if(rc==DDERR_WRONGMODE) { strcpy(EMsg,"DDERR_WRONGMODE"); return; }
if(rc==DDERR_XALIGN) { strcpy(EMsg,"DDERR_XALIGN"); return; }
#endif
sprintf(EMsg,"HRESULT=%X\0",rc);
}
/////////////////////////////////////////////////////////////////////

...it may not be the most efficient, but it works. I derived the error names from the SDK documentation via cut and paste.


hmm.. I see Lars posted at the same time - the case method might be a little better, but I like the single message box function, and actual error names.... We''ll let you decide

thx !
i hoped there was an easier way to solve this problem.
there are thousands of error values 8-(
Karl - Blueskied Games | my german site: Gratis Spiele
This is how it is done in UnrealTournament:

    FString D3DError( HRESULT h ){	#define D3DERR(x) case x: return TEXT(#x);	switch( h )	{		D3DERR(DD_OK)		D3DERR(DDERR_ALREADYINITIALIZED)		D3DERR(DDERR_BLTFASTCANTCLIP)                //More error values...                default: return FString:<img src="tongue.gif" width=15 height=15 align=middle>rintf(TEXT("%08X"),(INT)h);		}		#undef D3DERR        }    
Use D3DXGetErrorString() to translate the number into a readable string.

- WitchLord

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

As usual, WitchLord has the best answer. My method is left over from DX5 and DX3...

This topic is closed to new replies.

Advertisement