Jump to content
  • Advertisement
Sign in to follow this  
sooms

[SlimDX - DX9] device.Reset returns error code

This topic is 2611 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

Hey all.

I'm having an issue trying to restore the SlimDX rendering device after alt tabbing back into the game I am working on when it is full screen. The device.Reset( _primaryWindow.PresentationParameters) function returns the following error code:

{D3DERR_INVALIDCALL: Invalid call (-2005530516)}

I have tried running with Directx debug runtime messages on but I get nothing useful at this piece of code.

The RestoreLostDevice() looks like so:

public void RestoreLostDevice()
{
// Release all non-managed resources

// Cleanup depth stencils
_cleanupDepthStencils();

// Set all texture units to nothing
DisableTextureUnitsFrom( 0 );

// Unbind any vertex streams
for ( int i = 0; i < _lastVertexSourceCount; ++i )
{
device.SetStreamSource( i, null, 0, 0 );
}
_lastVertexSourceCount = 0;

// Release all automatic temporary buffers and free unused
// temporary buffers, so we doesn't need to recreate them,
// and they will reallocate on demand. This saves a lot of
// release/recreate of non-managed vertex buffers which
// wasn't need at all.
hardwareBufferManager.ReleaseBufferCopies( true );

// We have to deal with non-managed textures and vertex buffers
// GPU programs don't have to be restored
( (D3DTextureManager)textureManager ).ReleaseDefaultPoolResources();
( (D3DHardwareBufferManager)hardwareBufferManager ).ReleaseDefaultPoolResources();

// release additional swap chains (secondary windows)
foreach ( D3DRenderWindow sw in _secondaryWindows )
{
sw.DisposeD3DResources();
}

// Reset the device, using the primary window presentation params
try
{
SlimDX.Result result = device.Reset( _primaryWindow.PresentationParameters );
//SlimDX.Result result = device.TestCooperativeLevel();
if ( result.Code == D3D.ResultCode.DeviceLost.Code )
return;
}
catch ( SlimDX.SlimDXException dlx )
{
LogManager.Instance.Write( "[Error] Received error while trying to restore the device." );
LogManager.Instance.Write( LogManager.BuildExceptionString( dlx ) );
return;
}
catch ( Exception ex )
{
throw new AxiomException( "Cannot reset device!", ex );
}

// will have lost basic states
_basicStatesInitialized = false;
vertexProgramBound = false;
fragmentProgramBound = false;

// recreate additional swap chains
foreach ( D3DRenderWindow sw in _secondaryWindows )
{
sw.CreateD3DResources();
}

// Recreate all non-managed resources
( (D3DTextureManager)textureManager ).RecreateDefaultPoolResources();
( (D3DHardwareBufferManager)hardwareBufferManager ).RecreateDefaultPoolResources();

if (cursorProperties.texture != null)
RestoreCursor();

LogManager.Instance.Write( "!!! Direct3D Device successfully restored." );

_deviceLost = false;
}
}


The returned error doesn't crash the game as such, but when the next frame attempts to be rendered the FillMode is set to 0 causing the rendering to not occur.

Any tips or ideas on what is going on here is greatly appreciated.

Regards,
Andrew.

Share this post


Link to post
Share on other sites
Advertisement
Whenever this has happened to me, it's been because I've forgotten to free all resources before calling Device.Reset().

Try commenting out the creation of resources until the problem goes away, and then you've found the culprit.

Share this post


Link to post
Share on other sites

Whenever this has happened to me, it's been because I've forgotten to free all resources before calling Device.Reset().

Try commenting out the creation of resources until the problem goes away, and then you've found the culprit.


After more digging and getting the directx debug messages to work properly you are indeed correct. Going to be quite tricky removing the entry of some of the resources but I'll see what I can do.

Cheers,
Andrew.

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!