Archived

This topic is now archived and is closed to further replies.

dullboy

How to debug game applications

Recommended Posts

I don''t have two machines so I can''t take advantage of remote debugging. Also log files sometimes do not help or are awkward. Usually game window would cover the whole windows area so that I can''t see the visual studio. Probably I can set up the game as a regular windows application. So please tell me how to set it up. Thanks a lot.

Share this post


Link to post
Share on other sites
well when i debug, i think logic first of all. make sure that after each component of your game that you add, that it runs properly. and when you add something new, and it crashes, doesnt work right or something, then logically you have to asasume its what you just wrote. think through, what your problem is, and what could possibly be doing that. comment out code, write quick hacks to display information on your game screen. it may take a little work but i always find a solution.

Share this post


Link to post
Share on other sites
I put my game in windowed mode for debugging, always.
I know with DX previous to 9 this can be a horrible mess. Fortunately the DX9 SDK let me do it pretty quick (a day''s work to allow runtime switching between fullscreen and windowed).


~BenDilts( void );

Share this post


Link to post
Share on other sites
What rendering API are you using, DullBoy?

If it''s OpenGL, there shouldn''t be a problem.

If it''s DirectX, then I think you should look into the D3DPRESENT_PARAMETERS passed to CreateDevice - there''s a flag there to start it in windowed mode.

Superpig
- saving pigs from untimely fates, and when he''s not doing that, runs The Binary Refinery.
Enginuity1 | Enginuity2 | Enginuity3 | Enginuity4

Share this post


Link to post
Share on other sites
I am using DirectDraw, so there isn''t anything as you mentioned there. So does that mean if using DirectDraw, there is no way to run the program under windowed mode?

Share this post


Link to post
Share on other sites
One more thing. If I update DirectX SDK to 9.0, do I have to give up DirectDraw? I heard there isn''t DirectDraw any more in DirectX 9.0, is that true?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
You can still use DirectDraw, but it''ll still be only version 7.

Share this post


Link to post
Share on other sites
quote:
Original post by dullboy
I am using DirectDraw, so there isn''t anything as you mentioned there. So does that mean if using DirectDraw, there is no way to run the program under windowed mode?


Yes you can still run it in windowed mode, check out the flags for SetCooperativeLevel. Use DDSCL_NORMAL instead of DDSCL_FULLSCREEN.

Share this post


Link to post
Share on other sites
quote:
Original post by DukeAtreides076
quote:
Original post by dullboy
I am using DirectDraw, so there isn''t anything as you mentioned there. So does that mean if using DirectDraw, there is no way to run the program under windowed mode?


Yes you can still run it in windowed mode, check out the flags for SetCooperativeLevel. Use DDSCL_NORMAL instead of DDSCL_FULLSCREEN.


Actually, I did try to change DDSCL_FULLSCREEN to DDSCL_NORMAL, but the program crashed. Do I have to change something else in the mean time?

Share this post


Link to post
Share on other sites
quote:
Original post by dullboy
Actually, I did try to change DDSCL_FULLSCREEN to DDSCL_NORMAL, but the program crashed. Do I have to change something else in the mean time?



Make sure youre not using it with DDSCL_ALLOWMODEX or DDSCL_EXCLUSIVE, you just need DDSCL_NORMAL.

When you create your primary surface, dont set the width, height, or color depth.

Do you know where it crashed out?

Share this post


Link to post
Share on other sites
quote:
Original post by DukeAtreides076
quote:
Original post by dullboy
Actually, I did try to change DDSCL_FULLSCREEN to DDSCL_NORMAL, but the program crashed. Do I have to change something else in the mean time?



Make sure youre not using it with DDSCL_ALLOWMODEX or DDSCL_EXCLUSIVE, you just need DDSCL_NORMAL.

When you create your primary surface, dont set the width, height, or color depth.

Do you know where it crashed out?




Actually the primary surface creation failed. Do you mean don't call SetDisplayMode? If so, it crashed as well.



[edited by - dullboy on August 17, 2003 1:47:45 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by dullboy
Actually the primary surface creation failed. Do you mean don't call SetDisplayMode? If so, it crashed as well.



Do you know what error code CreateSurface is sending?

For your surface description here is all that you need:


DDSURFACEDESC ddsd;
ZeroMemory(ddsd);

ddsd.dwSize = sizeof(DDSURFACEDESC);
ddsd.dwFlags = DDSD_CAPS;
ddsd.dwCaps = DDSCAPS_PRIMARYSURFACE;


I think that should work...I'm getting rusty with DDraw...

EDIT: Yes, you dont need to call SetDisplayMode.

[edited by - DukeAtreides076 on August 17, 2003 2:12:33 AM]

Share this post


Link to post
Share on other sites
There is another way that involves a bit more hardware...
What I would do in your situation is use dual monitor (single machine). In that case, even when you are running in full screen mode, you still have the other screen available for debugging.
You will need either another PCI graphics adapter, or you can get a dual monitor graphics adapter.
Cheers.

Share this post


Link to post
Share on other sites
But then there''ll be problem with focus! Suppose you''re watching game on first monitor and debugger on second one. The game has the focus and you cannot use the debugger, can you?

[blue]Oxygenium[/blue]

Share this post


Link to post
Share on other sites
Here are some snippets from my old Direct Draw class. I can't guarantee it's the best way of doing things. It's old code and I was learning at the time. However, I could run my apps either windowed or full screen without a problem.

This is only part of the code so it won't compile, but you'll be able to see what you need to do to initialise Direct Draw, initialise the primary surface, and flip.

Note that in windowed mode you cannot just flip. You need to blit from the backbuffer to the primary surface.

Don't worry too much about lines like MDDSPrimary.GetDDSPtr()->Blt . This is just my Direct Draw Surface class. GetDDSPtr() returns a standard Direct Draw Surface pointer.

Hope that helps. Don't ask me too many questions about it though. It's been years since I wrote it and some of it was taken from tutorials/books that I was learning from.


LPDIRECTDRAW7 DD_Ptr; // Pointer to the Direct Draw object

LPDIRECTDRAWCLIPPER DD_ClipperPtr; // Pointer to clipper (windowed mode)


bool cMDirectDraw::InitWindowed(HWND hWnd, int Width, int Height)
{

Debugger.Print("Initialising Direct Draw windowed");

bFullScreen = false;

DD_hWnd=hWnd;
DD_Width=Width;
DD_Height=Height;

if (DirectDrawCreateEx(NULL,(void **)&DD_Ptr,IID_IDirectDraw7,NULL)!=DD_OK)
{
// shutdown any other dd objects and kill window

Debugger.Print("DirectDrawCreateEx FAILED");
Shutdown();
return(false);
}

// set the coop level to normal for windowed mode

if (DD_Ptr->SetCooperativeLevel(hWnd, DDSCL_NORMAL)!=DD_OK)
{
// shutdown any other dd objects and kill window

Debugger.Print("SetCooperativeLevel FAILED");
Shutdown();
return(false);
}

// Create the primary surface

if (!CreatePrimaryAndBackbufferSurfaces())
{
Debugger.Print("CreatePrimaryAndBackbufferSurfaces FAILED");
Shutdown();
return(false);
}

// Create a clipper to ensure that our drawing stays inside our window

if (DD_Ptr->CreateClipper( 0, &DD_ClipperPtr, NULL ) != DD_OK)
{
Debugger.Print("CreateClipper FAILED");
Shutdown();
return(false);
}

// set to hWnd to get window co-ords

if (DD_ClipperPtr->SetHWnd( 0, hWnd ) != DD_OK)
{
Debugger.Print("Clipper SetHWnd FAILED");
Shutdown();
return(false);
}

// attach the clipper to the primary surface

if (MDDSPrimary.GetDDSPtr()->SetClipper(DD_ClipperPtr) != DD_OK)
{
Debugger.Print("SetClipper to primary surface FAILED");
Shutdown();
return(false);
}

return true;
}


bool cMDirectDraw::CreatePrimaryAndBackbufferSurfaces(void)
{
DDSURFACEDESC2 ddsd;
DDSCAPS2 ddscaps;

LPDIRECTDRAWSURFACE7 lpDDSPri, lpDDSBack;

if (bFullScreen)
{
// Create flippable primary surface

memset( &ddsd, 0, sizeof(ddsd) );
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP |
DDSCAPS_COMPLEX;
ddsd.dwBackBufferCount = DD_NumBackBuffers;

if (DD_Ptr->CreateSurface(&ddsd, &lpDDSPri, NULL)!=DD_OK)
{
Debugger.Print("Create Surface for full screen Primary FAILED");
return(false);
}

// Get a pointer to the back buffer

memset(&ddscaps, 0, sizeof(ddscaps));
ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
if (lpDDSPri->GetAttachedSurface(&ddscaps, &lpDDSBack) != DD_OK)
{
Debugger.Print("GetAttachedSurface for full screen Backbuffer FAILED");
return(false);
}
} else {
// Create a normal primary surface

memset( &ddsd, 0, sizeof(ddsd) );
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
if (DD_Ptr->CreateSurface(&ddsd, &lpDDSPri, NULL)!=DD_OK)
{
Debugger.Print("Create Surface for windowed Primary FAILED");
return(false);
}

// Create a separate backbuffer

memset( &ddsd, 0, sizeof(ddsd) );
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
ddsd.dwWidth = DD_Width;
ddsd.dwHeight = DD_Height;
if (DD_Ptr->CreateSurface( &ddsd, &lpDDSBack, NULL ) != DD_OK)
{
Debugger.Print("CreateSurface for windowed mode Backbuffer failed");
return(false);
}
}

MDDSPrimary.SetDDSPtr(lpDDSPri);
MDDSBack.SetDDSPtr(lpDDSBack);

Debugger.Print("PrimarySurfacePointer: %d", lpDDSPri);
Debugger.Print("BackSurfacePointer: %d", lpDDSBack);

return(true);

} // end cMDirectDraw::CreatePrimaryAndBackbufferSurfaces



bool cMDirectDraw::Flip(bool bWait)
{

RECT RecSrc;
RECT RecDest;
POINT ClientScreenPos;

UpdateTimer();

if (bFullScreen)
{
// Full screen - Flip the Primary surface

return (MDDSPrimary.Flip(bWait));
} else {
// Windowed - blit backbuffer to primary surface

ClientScreenPos.x = 0;
ClientScreenPos.y = 0;
ClientToScreen(this->GetWindowsHandle(), &ClientScreenPos);
GetClientRect(this->GetWindowsHandle(), &RecDest);
OffsetRect(&RecDest, ClientScreenPos.x, ClientScreenPos.y);
SetRect(&RecSrc, 0, 0, Settings.Width, Settings.Height);

if (!MDDSPrimary.GetDDSPtr()->Blt(&RecDest, MDDSBack.GetDDSPtr(), &RecSrc, DDBLT_WAIT, NULL) == DD_OK)
{
Debugger.Print("Windowed flip blit failed");
}
return true;
}
}



[edited by - MisterMoot on August 17, 2003 12:50:33 PM]

[edited by - MisterMoot on August 17, 2003 12:53:02 PM]

Share this post


Link to post
Share on other sites