1

I have an issue with the method "SwapChain.ResizeBuffers(...)", whenever I call it I get errors... Basically, what I'm trying to do is: I want to be able to change the rendering resolution on the fly so I call this method (below) when I have changed the values of _RenderingWidth and _RenderingHeight...

    protected override void UpdateResolution()
    {
        if (_RenderTargetView != null) _RenderTargetView.Dispose();
        if (_BackBuffer != null) _BackBuffer.Dispose();

        _Device.OutputMerger.SetTargets((RenderTargetView) null);

        _SwapChain.ResizeBuffers(_SwapChain.Description.BufferCount, _RenderingWidth, _RenderingHeight, _SwapChain.Description.ModeDescription.Format, _SwapChain.Description.Flags);

        _BackBuffer = Texture2D.FromSwapChain<Texture2D>(_SwapChain, 0);
        _RenderTargetView = new RenderTargetView(_Device, _BackBuffer);

        _Device.OutputMerger.SetTargets(_RenderTargetView);
    }

The only information it gives me is:

An unhandled exception of type 'SlimDX.DXGI.DXGIException' occurred in SlimDX.dll
Additional information: DXGI_ERROR_INVALID_CALL: The application has made an erroneous API call that it had enough information to avoid. This error is intended to denote that the application should be altered to avoid the error.

My declarations:

    protected SlimDX.Direct3D10_1.Device1 _Device = null;
    protected SwapChain _SwapChain = null;

    protected Texture2D _BackBuffer = null;
    protected RenderTargetView _RenderTargetView = null;

[EDIT] I figured it out:

    var description = _SwapChain.Description;

    if (_RenderTargetView != null) _RenderTargetView.Dispose();
    if (_BackBuffer != null) _BackBuffer.Dispose();

    _SwapChain.Dispose();

    description.ModeDescription = new ModeDescription(_RenderingWidth, _RenderingHeight, new Rational(160, 1), Format.B8G8R8A8_UNorm);
    _SwapChain = new SwapChain(_Factory_DXGI, _Device, description);

    _BackBuffer = Texture2D.FromSwapChain<Texture2D>(_SwapChain, 0);
    _RenderTargetView = new RenderTargetView(_Device, _BackBuffer);

    _Device.OutputMerger.SetTargets(_RenderTargetView);

Re-initing everything... Don't know why I didn't think of this before!

ConnorVG
  • 21
  • 4
  • You don't need to reinit the swap chain. See http://stackoverflow.com/questions/18993399/resizing-render-target-direct2d-after-wm-size – jnm2 Jul 01 '14 at 19:48

0 Answers0