Моя структура рендеринга выглядит следующим образом: < /p>
Код: Выделить всё
class Scene
{
MeshCollection meshes;
OtherDrawableCollection others;
public void Draw(RenderContext context)
{
meshes.Draw(context);
others.Draw(context);
}
}
class MeshCollection : IRenderable
{
List Items;
public void Draw(RenderContext context)
{
foreach (var mesh in Items)
{
var rs = mesh.IsBackFaceCulling
? context.States.SolidBackCulling
: context.States.SolidNoCulling;
context.Graphics.SetRasterizerState(rs.Get());
context.Graphics.Draw(mesh);
}
}
}
// A helper holding shared, reusable state objects
class CommonStates : IDisposable
{
private ComPtr _solidBackCulling;
private ComPtr _solidNoCulling;
public ComPtr SolidBackCulling => _solidBackCulling;
public ComPtr SolidNoCulling => _solidNoCulling;
public void Initialize(GraphicsDevice device)
{
device.CreateRasterizerState(RasterizerDescs.Solid, _solidNoCulling.GetAddressOf());
device.CreateRasterizerState(RasterizerDescs.SolidBack, _solidBackCulling.GetAddressOf());
}
public void Dispose()
{
_solidBackCulling.Dispose();
_solidNoCulling.Dispose();
}
}
Код: Выделить всё
class OtherDrawableCollection : IRenderable, IDisposable
{
ResourceHandle _customState;
public void Initialize(RenderContext context)
{
// Creates a new rasterizer state, same as CommonStates.SolidNoCulling
_customState = context.Graphics.CreateRasterizerState(RasterizerDescs.Solid);
}
public void Draw(RenderContext context)
{
foreach (var drawable in Items)
{
context.Graphics.SetRasterizerState(_customState.Get());
context.Graphics.Draw(drawable);
}
}
public void Dispose() => _customState?.Dispose();
}
class ResourceHandle : IDisposable where T : unmanaged, ID3D11DeviceChild.Interface
{
private ComPtr _resource;
public unsafe T* Get() => _resource.Get();
public ResourceHandle(ComPtr resource)
{
if (resource.Get() == null)
throw new ArgumentNullException(nameof(resource));
_resource = resource;
}
public void Dispose()
{
_resource.Dispose();
}
}
Когда я заменяю текущую сцену, я распоряжаю все коллекции и ресурсы, а затем загружаю новые данные сцены. В этот момент я получаю: < /p>
Код: Выделить всё
D3D11 CORRUPTION: ID3D11DeviceContext::RSSetState: First parameter corrupt
System.Runtime.InteropServices.SEHException (0x80004005): External component has thrown an exception.
Код: Выделить всё
RSSetState ptr=0x2648DE2B630 // before loading new scene
RSSetState ptr=0x2648DE2A190 // after reload → crash
Подробнее здесь: https://stackoverflow.com/questions/797 ... to-cause-c