2 DX8 problems, again

Started by
3 comments, last by JensE 19 years, 6 months ago
Hi, hope you can help me one more time [crying] (1) Present() fails every last time it is called, I cannot remember the dx error exactly, but the message might mean that the device window was already destroyed before Present() was called. So something with my program termination handling might be wrong, here's some code:

        // message loop
	while (!this->m_bEndApp)
	{	
	     while (PeekMessage(&stMsg, NULL, 0, 0, PM_REMOVE))
             {
   	       TranslateMessage(&stMsg);
	       DispatchMessage(&stMsg);
	     }
  	     
             if (!this->m_bEndApp)
                  // render and present
	}

        // in window procedure

	case WM_DESTROY:
	{	
	  This->m_bEndApp = TRUE;

	  PostQuitMessage(0);

	  return 0;
	}
	break;


Is something wrong with this code? The program is exited by clicking the close cross (WM_CLOSE -> WM_DESTROY -> WM_QUIT). (2) When I switch my video mode from a non-multisampled to a multisampled back buffer, Reset() fails, although the ms mode is supported by the device (when I create it with this ms mode, it doesn't fail AND the D3DCaps Viewer says the MS type is supported). However, it's not the case if I start with a multisampled back buffer und switch to a mode with another type of ms back buffer. Reason: "Direct3D8: (ERROR) :Unsupported multisample type requested. CreateRenderTarget/CreateDepthStencil failed." Normally, I would suppose that my depth buffer is not recreated with multisampling and that would be the reason, but look at my pseudo-code:


   ReleaseUserMem();
   ReleaseSwapChains();
   ReleaseDepthStencil();

   Reset();

   if (DepthFormat != UNKNOWN)
   {
     CreateDepthStencilBuffer(zWidth, zHeight, zFormat, MSType);
   }


Step by step: a) Release all device memory b) Reset the device with the new MS type, all other present params stay the same as before (no depth buffer specified) c) Create the depth buffer What is wrong? Maybe a driver issue?
Advertisement
For the first problem, try this:

	while (!this->m_bEndApp)	{		     while (PeekMessage(&stMsg, NULL, 0, 0, PM_REMOVE))             {   	       TranslateMessage(&stMsg);	       DispatchMessage(&stMsg);	     }  	     else	     {                  // render and present              }	}
This code doesn't seem to make a difference. With the "while(PeekMessage())" statement I fetch all messages currently available, and after that I render. What would the "else" change, even if there was an "if" before?

Did you mean:

if (PeekMessage(...))
{
...
}

else
{
Render();
}

This way I would only fetch ONE message every frame! Additionally, there won't be performed any rendering at all, because it is only rendered, if there is NO message in the queue!
For the first part, you are posting a quit message after a quite message has already been posted. I don't know exactly why the last present is failing, but after a window is closed you get the following message in the following order:

WM_CLOSE,
WM_DESTROY,
WM_NCDESTROY,

You call PostQuitMessage inside the WM_DESTROY handler, and PostQuitMessage sends a WM_QUIT message to your app.

It would be safer if in your message handler you handled the WM_QUIT message and set m_bEndApp to true once you caught it. Once you get the WM_DESTROY message you should already be out of your main loop and onto unregistering and your window...

As for the second problem, Some depth formats are incompatable with some multisample settings even though the multisample type is supported. Maybe you missed that bit in the caps viewer?

Just incase:

D3D DevTypes -> HAL -> Adapter Formats -> <BB Format> -> Render Format Compatability -> <BB Format> -> <Tutisample Type> -> Click on the depth stencil format you are trying to create and check the supported quality levels. 1 technically means it's not supported.
[size=2]aliak.net
I'm totally sure that the ms type is compatible with the selected depth buffer format. Furthermore the device is Reset() with EnableAutoDepthStencil set to false and AutoDepthStencilFormat set to D3DFMT_UNKNOWN. The depth buffer would be created afterwards, but before that Reset() fails, that is the problem.

Quote:
Click on the depth stencil format you are trying to create and check the supported quality levels. 1 technically means it's not supported.


I use D3D8 for now, and there don't seem to exist quality levels as in D3D9.

--------------------------------------------------------

The Present() problem confuses me more and more. After I installed older nvidia drivers (because I wanted to play Thief 1 [embarrass]) the problem disappeared.

I disagree with what you said about my message handling:

Quote:
The PostQuitMessage function indicates to the system that a thread has made a request to terminate (quit). It is typically used in response to a WM_DESTROY message.

When the thread retrieves the WM_QUIT message from its message queue, it should exit its message loop and return control to the system. The exit value returned to the system must be the wParam parameter of the WM_QUIT message.


I can leave PostQuitMessage() out and end the message loop, if bEndApp is true, but that would not be the windows standard way.

This topic is closed to new replies.

Advertisement