XNA Creators Club Online
Page 1 of 1 (9 items)
Sort Posts: Previous Next

Converted XBOX project problem

Last post 14/12/2007 11:11 by Nick Gravelyn. 8 replies.
  • 13/12/2007 23:31
    • (0)
    • premium membership
    • Posts 90

    Converted XBOX project problem

    My game generates lots of textures from rendertargets.

    It worked great under 1.0 but crashes under 2.0.

    What's wrong?

    I'm getting this exception whenever I clear the graphics device:

    An unhandled exception of type 'System.InvalidOperationException' occurred in Microsoft.Xna.Framework.dll

    Additional information: The active render target and depth stencil surface must have the same pixel size and multisampling type.

     

    Here's the code that sets up my rendertarget:

    RenderTarget2D target = new RenderTarget2D(graphics.GraphicsDevice, 512, 820, 0, SurfaceFormat.Color);

    graphics.GraphicsDevice.SetRenderTarget(0, target);

    graphics.GraphicsDevice.Clear(Color.White);

    P.S. What's the deal with having resolvebackbuffer return a ResolveTexture2D? What difference/benefit does it have beyond a Texture2D?

  • 13/12/2007 23:39 In reply to

    Re: Converted XBOX project problem

    Sounds like you either have multisampling on your game or your render target is larger than your depth buffer. The two solutions:

    For problem 1 you'll need to use one of the overloaded RenderTarget2D constructors to specify the MultiSampleType and MultiSampleQuality of your graphics device. These are found in GraphicsDevice.PresentationParameters.

    For problem 2 you'll need to create another DepthStencilBuffer to use for rendering to the render target. Check out my post over on Ziggyware for a bit on that: http://ziggyware.com/forum/viewthread.php?forum_id=12&thread_id=12615&pid=41068#post_41068.

    Hope that helps!
  • 13/12/2007 23:49 In reply to
    • (0)
    • premium membership
    • Posts 90

    Re: Converted XBOX project problem

    I've never set any of those settings (heck I don't even know what they do), but looking at the presentation parameters during debugging, I can see the multisampling values are set to 0 and none respectively which apparently matches my rendertarget.

    I don't know what a depthstencilbuffer is either, but I suppose I will investigate that. Funny I never needed to set one before...

  • 14/12/2007 0:07 In reply to
    • (0)
    • premium membership
    • Posts 90

    Re: Converted XBOX project problem

    I set a depthstencilbuffer and that seems to have removed that particular exception, however now I am getting this:

    An unhandled exception of type 'System.InvalidOperationException' occurred in Microsoft.Xna.Framework.dll

    Additional information: ResolveRenderTarget may not be called when the current render target is null. Use ResolveBackBuffer instead.

    The thing is, I am not calling ResolveRenderTarget, I am in fact calling ResolveBackBuffer, and in any case the rendertarget isn't null. Argh.

    Looks like there are some bloody big breaking changes in 2.0.

  • 14/12/2007 0:39 In reply to
    • (0)
    • premium membership
    • Posts 90

    Re: Converted XBOX project problem

    Ok. I am giving up, at least for tonight.

    I've tried everything I can think of and that stupid exception won't go away. The rendertarget is definitely not null, so I don't have a clue what's REALLY going on, but it isn't what the message is saying, that's for sure.

    Man, after really looking forward to 2.0 so I could use my full visual studio instead of express, I'm starting to wish I'd stayed back at 1; At least my game ran.

     

  • 14/12/2007 10:49 In reply to
    • (0)
    • premium membership
    • Posts 90

    Re: Converted XBOX project problem

    Ok, I created the simplest code I could that reproduced the problem (the following code will crash when ResolveBackBuffer is called):

    1) Create a new Xbox project.

    2) Add the following lines to the beginning of the Draw method:

    DepthStencilBuffer origBuffer = graphics.GraphicsDevice.DepthStencilBuffer;

    ResolveTexture2D result = new ResolveTexture2D(graphics.GraphicsDevice, 128,128, 0, SurfaceFormat.Color);

    RenderTarget2D target = new RenderTarget2D(graphics.GraphicsDevice, 128,128, 0, SurfaceFormat.Color);

    graphics.GraphicsDevice.SetRenderTarget(0, target);

    graphics.GraphicsDevice.DepthStencilBuffer = new DepthStencilBuffer(graphics.GraphicsDevice, 128,128, origBuffer.Format, origBuffer.MultiSampleType, origBuffer.MultiSampleQuality);

    graphics.GraphicsDevice.ResolveBackBuffer(result);

    graphics.GraphicsDevice.SetRenderTarget(0, null);

    graphics.GraphicsDevice.DepthStencilBuffer = origBuffer;

  • 14/12/2007 11:00 In reply to

    Re: Converted XBOX project problem

    In that code, you're not actually rendering to the back buffer, you're rendering to your render target, not that you're rendering anything to begin with.  My guess is that the exception is caused by calling ResolveBackBuffer when the back buffer is not the bound render target.

    You don't need to use ResolveRenderTarget or ResolveTexture2D if you use render targets directly.
    Microsoft DirectX/XNA MVP
  • 14/12/2007 11:01 In reply to
    • (0)
    • premium membership
    • Posts 90

    Re: Converted XBOX project problem

    Answer
    Reply Quote

    Nevermind. I figured it out. When wanting to use a rendertarget to create a texture you apparently don't resolve it. You have to switch the graphics device away from your rendertarget and then call the GetTexture method on the rendertarget itself.

    This is my working code from 1.0:

    graphics.GraphicsDevice.ResolveRenderTarget(0);

    result = target.GetTexture();

    graphics.GraphicsDevice.SetRenderTarget(0, null);

    This is the working code in 2.0:

    graphics.GraphicsDevice.SetRenderTarget(0, null);

    result = target.GetTexture();

    I guess what threw me was when ResolveRenderTarget no longer worked, I started looking for a replacement and the only thing comparable was ResolveBackBuffer. It didn't make sense, but I didn't see any other options. Since it returned a ResolveTexture2D I figured I had to use that and never even got so far as to check whether target.GetTexture() still even existed or not. I discovered the GetTexture call has to follow the SetRenderTarget call by trial and error.

    (Edit: Ironically the documentation on GetTexture demonstrates this, but because of the order in which I received the errors, I never read that section until just now.)

  • 14/12/2007 11:11 In reply to

    Re: Converted XBOX project problem

Page 1 of 1 (9 items) Previous Next