Archived

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

SikCiv

DX7 DDraw - flip problem

Recommended Posts

When I change the coop level of my app a few times the screen goes blank and I have to reset the PC. This only happens when the app is changed to FullScreen. Ive narrowed it down to the lpDDSPrimary->flip() command so I tried to disable the WAIT flag by using ->flip(DDFLIP_DONOTWAIT) but it still crashes here. Here is my code..
  

//Original:

  if(lpDDSPrimary)
  {
    ddrval = lpDDSPrimary->flip(DDFLIP_WAIT);
    if(ddrval!=DD_OK) 
    {
        DebugOutpu("Failed to flip primary surface.");
        return;
    }
  }


//Debugging

  if(lpDDSPrimary)
  {
    ddrval = lpDDSPrimary->flip(DDFLIP_DONOTWAIT);
    if(ddrval!=DD_OK) 
    {
        DebugOutpu("Failed to flip primary surface.");
        return;
    }
  }


  
Im suspecting it may be a lost surface problem, but my restore code releases all old surfaces before it re-creates them. Is there a DirectDraw command to get a surface count of all the current surfaces in memory? Also, do surface pointer NULL out automatically when they are lost? I use lpDDSurface = NULL anyway just in case.... if(lpDDSurface) lpDDSurface->Release(); lpDDSurface = NULL;

Share this post


Link to post
Share on other sites
Hello SikCiv

Just a wee thought, DDSCL_FULLSCREEN *must* be used with DDSCL_EXCLUSIVE flag set ... when you change the co-op level perhaps you overlooked this and it all comes apart at the flip ?

Another thing I just noticed is that you only pass one parameter in your flip (the flags) ... I'm not certain what the story with Dx8 is but earlier versions take two params. Of course this would come out in the compile if that were the problem, so I suppose it isn't.

El Duderino

Edited by - El Duderino on April 25, 2001 11:46:43 PM

Share this post


Link to post
Share on other sites
I dont think thats the problem, the problem is intermittent so its very hard to diagnose, here''s some code snippets from my ddraw creation function in order..

  

DirectDrawCreateEx(NULL, (VOID**)&lpDD7, IID_IDirectDraw7, NULL);

lpDD7->SetCooperativeLevel(hWndMain, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);

lpDD7->SetDisplayMode(640,480,16,0,0);

ZeroMemory(&ddsd, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX;
ddsd.dwBackBufferCount = 1;
ddrval = lpDD7->CreateSurface (&ddsd, &lpDDSPrimary, NULL);

ZeroMemory(&ddscaps, sizeof(ddscaps));
ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
ddrval=lpDDSPrimary->GetAttachedSurface(&ddscaps, &lpDDSBack);






Is it possible for lpDDSPrimary to lose its contents or pointer while flipping? Is there a function in DDraw that tests a surface pointer instead of using ''if(lpDDSPrimary) ...''?

Share this post


Link to post
Share on other sites
Well, if your surface is lost, check to see if the error is DD_SURFACELOST with a quick if statment. If this is the error, use the flag DD_SURFACERESTORE(I think that is the name of the flag), and that should restore the surface. Make sure that you keep the DDFLIP_WAIT flag set so that direct draw will wait to access the surface if it is being temporarily used by something else. El Duderino was right when he said that if a fullscreen mode, DDSCL_EXCLUSIVE must also be set. I have not seen all of you code, but make sure that you are locking your backbuffer surface, and then unlocking it before you perform you call your flipping code.

Edem Attiogbe

Share this post


Link to post
Share on other sites
I cannot retrieve an error code from flip because it crashes the app (and the whole system), and its very intermittent. At the moment im calling my coopchange function in WM_TIMER so it changes over and over, sometimes it goes on for half an hour, other times it hangs on the fourth coop change, and its always when it goes into fullscreen mode, and it always hangs on the same line, lpDDSPrimary->flip(). There is no locking performed at all, and I check that lpDDSPrimary is not NULL, and blitting prior to the flip is successful ... Im stumped.

It never used to do it until I changed my gfx code a bit, but if it works most of the time, I cant see that what I did was incorrect, anyway heres what ive changed:

1) Instead of restoring the surfaces after say an ALT-TAB, I release the surface and reload the bitmap file fresh.

2) Instead of using ->RestoreAllSurfaces I release the surfaces and reload them (same as (1)).

It works 99% of the time but still, can this cause intermittent problems?








Share this post


Link to post
Share on other sites