-1

I'm struggling with resizing and full screen mode of my project. This is what I'm working on Mandelbrot in a Pixel Shader and here on GIT https://github.com/ShamanLKG/Mandelbrot

The app crashes when Alt+Enter is pressed and I don't understand why.

case WM_SIZE:
{
    int width = LOWORD(lParam);  // Macro to get the low-order word.
    int height = HIWORD(lParam); // Macro to get the high-order word.

    pThis->D3D->OnResize(width, height);
    pThis->D3D = std::shared_ptr<Direct3D>(new Direct3D(hWnd, width, height));
    pThis->D2D = std::shared_ptr<Direct2D>(new Direct2D(hWnd, pThis->D3D));
    break;
}

I recreated the Direct3d and Direct2 objects on resize to solve issues with the navigation and to adjust the resolution of the window. But impossible so far to get the full screen working. The full screen works without recreating the D3D and D2D object but then I'm stucked with the original resolution and the navigation does not work properly. I use the OnResize() function from MSDN (https://learn.microsoft.com/en-us/windows/win32/direct3ddxgi/d3d10-graphics-programming-guide-dxgi#handling-window-resizing). I tried passing on a BOOL argument to InitD3D to tell the program if the swapchain is full screen or not from swapchain->GetFullScreenState but it did not help.

The navigation works as long at the window size is not changed, then it's not precise. Adjusting the yDelta with the change in screen ratio helps, but only when the window width is changed. It becomes again unstable when the window height is changed. So as workaround I recreated the D3D and D2D object to start with fresh parameters and having a function navigation. But as a result the full screen now crashes.

void Direct3D::CenterScreen(int xPos, int yPos)
{

    //float ratio = startRatio / currentRatio;
    int xDelta = xPos - width / 2;
    int yDelta = (yPos - height / 2);  //could divide by ratio to capture window width change

    realStart += (float)xDelta / (float)width * 2 * mandelWidth;
    imagStart += (float)yDelta / (float)height * 2 * mandelHeight;
}

Any clue how I could solve these issues? Many thanks in advance.

Gilles Walther
  • 126
  • 1
  • 7
  • You referred [document](https://learn.microsoft.com/en-us/windows/win32/direct3ddxgi/d3d10-graphics-programming-guide-dxgi#handling-window-resizing) has no `OnResize()` function. Your code will naturally call `IDXGISwapChain::ResizeBuffers` in response to `WM_SIZE` message. – Rita Han Feb 13 '20 at 01:52
  • I've implemented the onResize based on the example from MSDN and call it in WM_SIZE. The resizing works also in full screen but the resolution is not increased. I solved the resolution problem by reinitializing the DirectX modules, but then then the full screen mode crashes. – Gilles Walther Feb 13 '20 at 07:34
  • [mcve] required. Also, the term *"crash"* is used by a lot of people to mean a lot of different things. Please provide details on how the error manifests. – IInspectable Feb 13 '20 at 07:35
  • The files are available on the github link I provided. Sorry I thought it was sufficent. I'll update the post tonight with more code and explanations. – Gilles Walther Feb 13 '20 at 11:18
  • 1
    Questions need to be self-contained. Off-site resources tend to go stale after a while, or become inaccessible altogether. A link to a git repository isn't sufficient. Once you push a commit to that repository, this question no longer references the intended source code. See [ask] and [mcve] for details. – IInspectable Feb 13 '20 at 12:03

1 Answers1

0

Found the error, the Direct2D resources were not released causing the ResizeBuffers to fail with code 0x887A0001. The tutorial from https://bell0bytes.eu/fullscreen/ has been very helpful.

hr = swapchain->ResizeBuffers(0, 0, 0, DXGI_FORMAT_UNKNOWN, 0);

Lesson of the day, have a robust error handling system.

Gilles Walther
  • 126
  • 1
  • 7
  • 1
    Glad to hear you solve this issue. You can accept your own answer for underlining the solution, then it will be helpful for others are searching on this topic. – Rita Han Feb 17 '20 at 02:57