Newbee DX error handling question
Hi all,
I am new to c/c++ and Direct X programming, and I need to implement some code for error handling in my current project, cause it won''t run on all machines for some still unknown reason... I''d rather ask you guys here at Gamedev than trying to find out myself... As a newbee I don''t want to waste too much time on error handling, since I have a lot more than that to worry about so to speak... ;-)
All I do now is a simple test for failure, using the FAILED() macro...
if (FAILED(DirectDrawCreate(NULL,&lpdd),NULL)))
{
// error
}
I need your help for a good way to show where the error occured on screen using either a message box or writing to a file... I am running the project in full-screen mode...
Thanks in advance!
Well, you should REALLY consider implementing windowed mode for debug. It is not much work if you use the D3DX helper functions (if not it is a bit more work) and it is to no end helpful in debugging.
Ok, enough of that. Here is how I do it.
Edit: Reformatting
Edited by - BitMaster on October 1, 2000 5:15:21 AM
Ok, enough of that. Here is how I do it.
// Some file included by nearly everything#ifdef _DEBUG#define ASSERT_DX(exp) CheckDX(exp, #exp, __FILE__, __LINE__)#else#define ASSERT_DX(exp) exp#endif#define CHECK_DX(exp) CheckDX(exp, #exp, __FILE__, __LINE__)inline void CheckDX(HRESULT hr, const string & code, const string & file, DWORD line){ if (FAILED(hr)) throw XResult(hr, code, file, line);}// Some code you want to checkCHECK_DX(pDD->CreateSurface(...)); // This code will always be checkedASSERT_DX(pSurface->Blt(...)); // This code will only be checked in debug builds
Edit: Reformatting
Edited by - BitMaster on October 1, 2000 5:15:21 AM
Ah, yes I forgot about that log file...
// tools.hextern ofstream & LogFile;#define LOG(out) LogFile << out// tools.cppofstream LogFile("Debug.txt");// And somewhere around the code the error happenstry { // The code that keeps crashing}catch (const XResult & exc) { LOG(exc.what() << endl);}catch (...) { LOG("other exception" << endl);}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement