Sign in to follow this  

[SlimDX] Device.Reset() Failing Inexplicably

This topic is 2656 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 problems getting Device.Reset() to work on my machine. Google has not been terribly helpful in telling me what is wrong, so I figured I'd give it a shot here.

My setup:
-Visual Studio 2010, compiling against .NET 4.0 and the prebuilt SlimDX x86 4.0 library
-Direct3D9 debug libraries in use; debug output is MAX; maximum validation, break on memory leaks, break on D3D9 error, multimon debugging are ALL ENABLED.
-Using Direct3D9.

This is all that is in the output window during the lifetime of my application:
The thread 'vshost.LoadReference' (0x7f0) has exited with code 0 (0x0).
'Circle.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Documents and Settings\user\Desktop\Dev\Games\Circle\Circle\bin\Debug\Circle.exe', Symbols loaded.
'Circle.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll',
Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
The program '[0x17B8] Circle.vshost.exe: Managed (v4.0.30319)' has exited with code -2147483645 (0x80000003).
The program '[0x17B8] Circle.vshost.exe: Program Trace' has exited with code 0 (0x0).







The program crashes completely on Device.Reset(), logging the message about error code 0x80000003, which seems to indicate invalid arguments, however the PP that I pass as a parameter is the same that I created at the start of the program. Here are the relevant parts of code (class is DeviceContext):

public delegate void OnDeviceResetDelegate();
public event OnDeviceResetDelegate OnDeviceReset;

public delegate void OnDeviceLostDelegate();
public event OnDeviceLostDelegate OnDeviceLost;

private Direct3D _d3d;
private Device _device;
private PresentParameters _pp;

// ctor. Called once after creating window. Handle is always valid; backbufferSize is always 800x600.
public DeviceContext(IntPtr handle, Size backbufferSize)
{
_pp = new PresentParameters();
_pp.AutoDepthStencilFormat = Format.A8R8G8B8;
_pp.BackBufferCount = 1;
_pp.BackBufferFormat = Format.A8R8G8B8;
_pp.BackBufferHeight = backbufferSize.Height;
_pp.BackBufferWidth = backbufferSize.Width;
_pp.DeviceWindowHandle = handle;
_pp.EnableAutoDepthStencil = false;
_pp.FullScreenRefreshRateInHertz = 0;
_pp.Multisample = MultisampleType.None;
_pp.MultisampleQuality = 0;
_pp.PresentationInterval = PresentInterval.Default;
_pp.PresentFlags = PresentFlags.None;
_pp.SwapEffect = SwapEffect.Discard;
_pp.Windowed = true;

this.Initialize();
}

// ..................

// See above.
private bool Initialize()
{
_d3d = new Direct3D();

// TODO: non-blanket exception; device caps check
try
{
_device = new Device(_d3d, 0, DeviceType.Hardware, _pp.DeviceWindowHandle, CreateFlags.HardwareVertexProcessing, _pp);
}
catch (Exception ex)
{
MessageLogger.WriteLine("{0}", ex.Message);
return false;
}

return true;
}

// ..................

// This is called in my main loop before attempting to do any rendering.
public void Validate()
{
Result result = _device.TestCooperativeLevel();

if (result == ResultCode.DeviceLost)
{
if (this.OnDeviceLost != null)
{
this.OnDeviceLost();
}

while (true)
{
result = _device.TestCooperativeLevel();

// TODO: other cases so that this loop isn't totally infinite?
if (result == ResultCode.DeviceNotReset)
{
_device.Reset(_pp); // This is where it crashes and displays the error 0x80000003 in the console

if (this.OnDeviceReset != null)
{
this.OnDeviceReset();
}
break;
}

System.Threading.Thread.Sleep(1000);
}
}
}







I'm skeptical of whether VS2010 plays nicely with the D3D9 debug libraries (they would crash the environment last time I tried using them with VS2010), and I think that I should be getting quite a bit more feedback from them. Any thoughts?

EDIT: As a little sidenote, I've NEVER been able to get Device.Reset() to work in SlimDX before. I used to use a workaround where I would just completely recreate the device, which would work, given the same PP...I've just never bothered to try to get it working properly. Now I'd like to do so. The D3D object is valid at the point of reset. Before I turned on debug libraries in the D3D control panel, the application wouldn't crash, but the device wasn't completely reset either; instead, the device was not associated with a D3D object.

Thanks for your time.

Share this post


Link to post
Share on other sites
Whoops. Didn't know such a setting existed.

I'm now getting this error:
Direct3D9: (ERROR) :All user created stateblocks must be freed before Reset can succeed. Reset Fails.

I promptly tracked this down to me not calling OnDeviceLost() and OnDeviceReset() on an ID3DXSprite object. I never knew these methods were so important; I guess you learn something new every day, huh? Thanks for a prod in the right direction, it all works as expected now!

Share this post


Link to post
Share on other sites

This topic is 2656 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this