Jump to content
  • Advertisement
Sign in to follow this  
lucasite

DX11 [SlimDx] Dx11 Resizing Form Exception [Solved]

This topic is 2892 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all,
I have written the following code to handle my form resizing:
public void FormResize(object sender, EventArgs e)
{
var form = (Form)sender as Form;
renderView.Dispose();
swapChain.ResizeBuffers(1, form.ClientSize.Width, form.ClientSize.Height, Format.R8G8B8A8_UNorm, SwapChainFlags.None);
renderView = new RenderTargetView(device, backBuffer);
device.ImmediateContext.Rasterizer.SetViewports(new Viewport(0, 0, form.ClientSize.Width, form.ClientSize.Height, 0.0f, 1.0f));
}



but it throws an exception the next time the draw method begins:
"External component has thrown an exception."

Im sure I read somewhere that I need to dispose the RenderTargetView first. And as far as I can see, the swapchain and viewport are the only places that refers to sizes.

Can anyone spot what Im doing wrong?

regards

Luca

Share this post


Link to post
Share on other sites
Advertisement
This is only a guess - but where's that backbuffer variable coming from? I'd imagine the Resource you're using to create the RenderTargetView would be invalid after you resized the backbuffers? E.g.

public void FormResize(object sender, EventArgs e) {
var form = (Form) sender as Form;
renderView.Dispose();
swapChain.ResizeBuffers(1, form.ClientSize.Width, form.ClientSize.Height, Format.R8G8B8A8_UNorm, SwapChainFlags.None);
using(Texture2D bb = Resource.FromSwapChain<Texture2D>(swapChain, 0)) {
renderView = new RenderTargetView(device, bb);
}
device.ImmediateContext.Rasterizer.SetViewports(new Viewport(0, 0, form.ClientSize.Width, form.ClientSize.Height, 0.0f, 1.0f));
}

Share this post


Link to post
Share on other sites
That was it, thanks Starnick.
Id also missed out the setTarget line aswell. So here's the code for anyone else who stumbles across this issue.

public void FormResize(object sender, EventArgs e)
{
var form = (Form)sender as Form;
renderView.Dispose();

swapChain.ResizeBuffers(1, form.ClientSize.Width, form.ClientSize.Height, Format.R8G8B8A8_UNorm, SwapChainFlags.None);
using (var bb = Resource.FromSwapChain<Texture2D>(swapChain, 0))
renderView = new RenderTargetView(device, bb);

device.ImmediateContext.OutputMerger.SetTargets(renderView);
device.ImmediateContext.Rasterizer.SetViewports(new Viewport(0, 0, form.ClientSize.Width, form.ClientSize.Height, 0.0f, 1.0f));
}

Share this post


Link to post
Share on other sites
I was wondering why you were setting your viewport there. Usually you have something like BeginDraw() where you set the render targets and clear them. Your form won't always be resizing, so your targets may not always be set each frame, this could be a problem if you're using other render targets elsewhere in your code I would imagine.

In my own code I have a "multiple swapchain - one device" setup, where each form (or panel) has its own backbuffer that it manages. So each has a BeginDraw()/EndDraw() that sets and clears its render target/depthstencil buffer, and presents to the screen. In between those two method calls is where I would put my setting of render states, view ports, and actual geometry drawing.

Anyways, food for thought. Glad you got it working!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!