An item with the same key has already been added. at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource) at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add) at SlimDX.ObjectTable.Add(ComObject comObject, ComObject owner) at SlimDX.ComObject.Construct(IUnknown* pointer) at SlimDX.DXGI.KeyedMutex..ctor(IComObject resource) at Craft.SpriteFont.Initialize() in D:\Documents\Visual Studio 2010\Projects\Craft\Craft\Game\Renderer\SpriteFont.cs:line 57 at Craft.Engine.InitializeSubSystems() in D:\Documents\Visual Studio 2010\Projects\Craft\Craft\Game\Main\Engine.cs:line 89 at Craft.Engine.Initialize() in D:\Documents\Visual Studio 2010\Projects\Craft\Craft\Game\Main\Engine.cs:line 81 at Craft.Program.Main(String[] args) in D:\Documents\Visual Studio 2010\Projects\Craft\Craft\Game\Main\Program.cs:line 9
Line 57:
d3d11Mutex = new KeyedMutex(d3d11Texture);
With PIX, I get a different error:
Attempted to read or write protected memory. This is often an indication that other memory is corrupt. at SlimDX.Direct2D.RenderTarget.FromDXGI(Factory factory, Surface surface, RenderTargetProperties properties) at Craft.SpriteFont.Initialize() in D:\Documents\Visual Studio 2010\Projects\Craft\Craft\Game\Renderer\SpriteFont.cs:line 71 at Craft.Engine.InitializeSubSystems() in D:\Documents\Visual Studio 2010\Projects\Craft\Craft\Game\Main\Engine.cs:line 89 at Craft.Engine.Initialize() in D:\Documents\Visual Studio 2010\Projects\Craft\Craft\Game\Main\Engine.cs:line 81 at Craft.Program.Main(String[] args) in D:\Documents\Visual Studio 2010\Projects\Craft\Craft\Game\Main\Program.cs:line 9
Line 71:
dwRenderTarget = RenderTarget.FromDXGI(d2Factory, surface, rtp);
Both are occurring in SpriteFont.Initialize, so here's the code for that:
public static void Initialize()
{
Factory1 factory1 = new Factory1();
Adapter1 adapter1 = factory1.GetAdapter1(0);
SlimDX.Direct3D10_1.Device1 device10_1 = new SlimDX.Direct3D10_1.Device1(adapter1, SlimDX.Direct3D10.DriverType.Hardware, SlimDX.Direct3D10.DeviceCreationFlags.BgraSupport, SlimDX.Direct3D10_1.FeatureLevel.Level_10_1);
d3d11Texture = new Texture2D(Engine.Device, new Texture2DDescription
{
Width = (int)Engine.Viewport.Width,
Height = (int)Engine.Viewport.Height,
MipLevels = 1,
ArraySize = 1,
Format = Format.B8G8R8A8_UNorm,
SampleDescription = new SampleDescription(1, 0),
Usage = ResourceUsage.Default,
BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,
CpuAccessFlags = CpuAccessFlags.None,
OptionFlags = ResourceOptionFlags.KeyedMutex
});
Resource sharedResource = new Resource(d3d11Texture);
SlimDX.Direct3D10.Texture2D d3d10Texture = device10_1.OpenSharedResource<SlimDX.Direct3D10.Texture2D>(sharedResource.SharedHandle);
d3d10Mutex = new KeyedMutex(d3d10Texture);
d3d11Mutex = new KeyedMutex(d3d11Texture);
SlimDX.Direct2D.Factory d2Factory = new SlimDX.Direct2D.Factory(SlimDX.Direct2D.FactoryType.SingleThreaded, DebugLevel.None);
DirectWriteFactory = new SlimDX.DirectWrite.Factory(SlimDX.DirectWrite.FactoryType.Isolated);
Surface surface = d3d10Texture.AsSurface();
RenderTargetProperties rtp = new RenderTargetProperties
{
MinimumFeatureLevel = SlimDX.Direct2D.FeatureLevel.Direct3D10,
Type = RenderTargetType.Hardware,
Usage = RenderTargetUsage.None,
PixelFormat = new PixelFormat(Format.Unknown, AlphaMode.Premultiplied)
};
dwRenderTarget = RenderTarget.FromDXGI(d2Factory, surface, rtp);
DefaultFont = new TextFormat(DirectWriteFactory, "Arial", FontWeight.Normal, FontStyle.Normal, FontStretch.Normal, 24, "en-US")
{
TextAlignment = SlimDX.DirectWrite.TextAlignment.Center,
ParagraphAlignment = ParagraphAlignment.Center
};
WhiteBrush = new SolidColorBrush(dwRenderTarget, Color.White);
BlendStateDescription bsd = new BlendStateDescription();
bsd.RenderTargets[0].BlendEnable = true;
bsd.RenderTargets[0].BlendEnable = true;
bsd.RenderTargets[0].SourceBlend = BlendOption.SourceAlpha;
bsd.RenderTargets[0].DestinationBlend = BlendOption.InverseSourceAlpha;
bsd.RenderTargets[0].BlendOperation = BlendOperation.Add;
bsd.RenderTargets[0].SourceBlendAlpha = BlendOption.One;
bsd.RenderTargets[0].DestinationBlendAlpha = BlendOption.Zero;
bsd.RenderTargets[0].BlendOperationAlpha = BlendOperation.Add;
bsd.RenderTargets[0].RenderTargetWriteMask = ColorWriteMaskFlags.All;
blendStateTransparent = BlendState.FromDescription(Engine.Device, bsd);
var vertices = new DataStream(VertexPositionTexture.SizeInBytes * 4, true, true);
vertices.Write(new VertexPositionTexture(new Vector3(-1, 1, 0), new Vector2(0, 0)));
vertices.Write(new VertexPositionTexture(new Vector3(1, 1, 0), new Vector2(1, 0)));
vertices.Write(new VertexPositionTexture(new Vector3(-1, -1, 0), new Vector2(0, 1)));
vertices.Write(new VertexPositionTexture(new Vector3(1, -1, 0), new Vector2(1, 1)));
vertices.Position = 0;
effect = ContentLoader.LoadEffect(@"Content\Effects\FontShader.fx");
layout = new InputLayout(Engine.Device, effect.GetTechniqueByIndex(0).GetPassByIndex(0).Description.Signature, VertexPositionTexture.inputElements);
vertexBuffer = new Buffer(Engine.Device, vertices, (int)vertices.Length, ResourceUsage.Default, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);
vertices.Close();
}
Any ideas?






