PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

What is wrong with this piece of code?

Hi all,

I have this piece of code in the handler to a menu:

CGapiDisplay gd_Display;
CGapiSurface gd_Backbuffer;
CGapiSurface gd_S1;

cRes = gd_Display.OpenDisplay(hWnd, GDOPENDISPLAY_FULLSCREEN);
cRes = gd_Display.GetBackBuffer(&gd;_Backbuffer);
cRes = gd_S1.CreateSurface(g_hInst,IDB_BITMAP1);

< do stuff >

delete &gd;_S1;
delete &gd;_Backbuffer;
delete &gd;_Display;

The first time I click on the menu the program works as it should. However, the second time the OpenDisplay function returns error: GDERR_PRIMARYSURFACEALREADYEXISTS.

Do I need to close the display somehow? Note that I removed sanity checks and the body of the function.

Thanks!
Hi,

The issues are in you C++ code. You should not delete objects which are instantiated on the stack.

So. Just remove the following rows and the code should work correctly:

// Remove these lines:
delete &gd_S1;
delete &gd_Backbuffer;
delete &gd_Display;
// End of line removal

Best regards,
Johan
efortier · 21 Apr 2002, 20:30 UTC — re: What is wrong with this piece of code? -- New try
Hello, and thanks for your reply!

I tried what you mentionned and it still doesn't work. So I created a new PocketPC 2002 project, and added only these lines to a menu message handler:

case ID_mnuGapiDraw:
{
HRESULT cRes = GD_OK;
CGapiDisplay gd_Display;
cRes = gd_Display.OpenDisplay(hWnd, GDOPENDISPLAY_FULLSCREEN );
if(cRes != GD_OK)
{
ShowErr(1,cRes,hWnd);
break;
}
cRes = gd_Display.SetDisplayMode(GDDISPMODE_NORMAL);
if(cRes != GD_OK)
{
ShowErr(2,cRes,hWnd);
break;
}
break;
}

On the first try, all works correctly. The second time I click on the menu, the SetDisplayMode return the PRIMARYSURFACEALREADYEXISTS error message.

Are there any restrictions to when and where GapiDraw should be used?

There's so little code that I don't know what I'm doing wrong. My PC runs Windows 2000 with the eVC distribution, and my portable is an iPAQ 3850 with no add-ons.

Thanks for any other infos. Sorry for the lack of tabs or spaces. The forums removed them...
Thanks for the feedback,

This is fixed in GD1.02