k82l0804 / slimdx

Automatically exported from code.google.com/p/slimdx
MIT License
0 stars 0 forks source link

System.ArgumentException: There is already an element with the given key. #634

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I have with 70% chance on starting my application this error:

Unbehandelte Ausnahme: System.ArgumentException: Ein Element mit dem
gleichen Schlüssel wurde bereits hinzugefügt. (This means: There is already
an element with the given key.)
   bei System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
   bei System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue
value, Boolean add)
   bei SlimDX.ObjectTable.Add(ComObject comObject, ComObject owner) in
dev\slimdx\source\objecttable.cpp:Zeile 105.
   bei SlimDX.ComObject.Construct(IUnknown* pointer, ComObject owner) in
dev\slimdx\source\comobject.cpp:Zeile 116.
   bei SlimDX.Direct3D11.DeviceContext..ctor(ID3D11DeviceContext* pointer,
ComObject owner) in dev\slimdx\source\direct3d11\devicecontext11.cpp:Zeile 73.
   bei
SlimDX.ComObject.ConstructFromPointer<SlimDX::Direct3D11::DeviceContext,ID3D11De
viceContext>(ID3D11DeviceContext*
pointer, ComObject owner, ComObjectFlags flags) in
dev\slimdx\source\comobject.h:Zeile 94.
   bei SlimDX.Direct3D11.Device.get_ImmediateContext() in
dev\slimdx\source\direct3d11\device11.cpp:Zeile 113.

For some reason all was ok, after I enabled/disabled/enabled... the DX 11
debug layer. Now it is disabled again. I've also rebooted my OS. With 30%
chance the application starts and runs then without problems.

Using current SVN version SlimDX x86 target, C#, Win7 64bit, 5870 with
newest Radeon.

Original issue reported on code.google.com by remi2...@googlemail.com on 11 Mar 2010 at 6:53

GoogleCodeExporter commented 9 years ago
Please provide the code for your device creation process up to the first time 
you use
the device's ImmediateContext property.

Original comment by josh.petrie on 11 Mar 2010 at 10:27

GoogleCodeExporter commented 9 years ago
I debugged this problem a little bit and I know now, why it occurs:

I have to synchronize the device in my code, if I'm getting the 
ImmediateContext,
because I need to do this in two threads. The call to device.ImmediateContext 
calls
the ConstructFromPointer-Function in the SlimDX code, but only, if there is no 
such
context already. Because the check is before the creation, and there is no 
critical
section defined for this, it is called twice.

If you want, you can implement a double checked synchronizing, means first 
check (the
old one) if there is no context, then enter a crit section, check again if 
there is
no context (double check), and if not, create it, then leave the crit section. 
For
the case, there is a context (which should be the most of the time) the code 
remains
the same: fast. BUT I think, that you already know this pattern ^^ I only want 
to
help, hehe.

Again thx for your great work.

Original comment by remi2...@googlemail.com on 11 Mar 2010 at 11:31

GoogleCodeExporter commented 9 years ago
We don't make guarantees that the properties are thread-safe in this fashion. 

May want to follow up on this for v2.0.

For now you will need to synchronize access to the property in client code; 
it's too 
costly in general for us to do internally.

Original comment by josh.petrie on 13 Mar 2010 at 9:11