• Advertisement
Sign in to follow this  

[SlimDX] Creating texture with shared handle crashes

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

I'm trying to create a render target texture to be shared between two devices using slimDX. Unfortunately I get the following error (Windbg) every time I try to create the texture using the August 2009 release of SlimDX. I'm using debug august 2009 directx libraries.


Direct3D9: (ERROR) :Device is not capable of sharing resource. CreateTexture fails.
Direct3D9: (ERROR) :Failure trying to create a texture
D3D9 Helper: IDirect3DDevice9::CreateTexture failed: D3DERR_INVALIDCALL
(2708.924): CLR exception - code e0434f4d (first chance)
(2708.924): CLR exception - code e0434f4d (!!! second chance !!!)


I'm having trouble finding a lot of documentation on the shared handle feature, so this is a bit frustrating. Here is my code to create the device:


            _presentParam = new PresentParameters();
            _presentParam.PresentationInterval = PresentInterval.Immediate;
            _presentParam.Windowed = true;
            _presentParam.DeviceWindowHandle = _control.Handle;

            _presentParam.SwapEffect = SwapEffect.Discard;
            _presentParam.PresentFlags = PresentFlags.LockableBackBuffer | PresentFlags.Video | PresentFlags.DiscardDepthStencil | PresentFlags.DeviceClip;
            _presentParam.BackBufferCount = 1;
            _presentParam.EnableAutoDepthStencil = true;
            _presentParam.AutoDepthStencilFormat = Format.D16;
            _presentParam.BackBufferWidth = _backbufferSize.Width;
            _presentParam.BackBufferHeight = _backbufferSize.Height;
            _presentParam.BackBufferFormat = _format;

            Direct3D _direct3D = new Direct3D();
            _device = new Device(
                CreateFlags.Multithreaded | CreateFlags.HardwareVertexProcessing,



And here is my code to create the texture.. the offending line of code that fails is _prv = new Texture(...


Width = 1024; Height = 200;

public IntPtr _ptr_prvtexture;

_prvtexture = new Texture(_device, Width, Height, 1, Usage.RenderTarget, Format.A8R8G8B8, Pool.Default, out _ptr_prvtexture);



Is it a device creation parameter error? Something wrong with the texture creation? My video card is a GeForce 9800 GT. I'm not sure what is causing the error. - Michael Tanczos

Edited by Michael Tanczos

Share this post

Link to post
Share on other sites
My only guess is that you might need a 9Ex device for sharing to work. Try changing your device creation call to "new DeviceEx(" and see if that fixes the problem.

Share this post

Link to post
Share on other sites
I can not for the life of me figure out why this is crashing.. in fact, the error messages don't even make sense to me. I switched to Direct3d9Ex and I get this:

Direct3D9: (ERROR) :Source of shared texture must be in D3DPOOL_SYSTEMMEM. CreateTexture fails.
Direct3D9: (ERROR) :Failure trying to create a texture

// Source

Width = 1024; Height = 256;
IntPtr _ptr_prvtexture = IntPtr.Zero;
_prvtexture = new Texture(_device, Width, Height, 1, Usage.RenderTarget, Format.A8R8G8B8, Pool.Default, out _ptr_prvtexture);

You'd think the obvious solution would be to put it in the system memory pool, but then I get this error:

Direct3D9: (ERROR) :*pSharedHandle must be a valid pointer to create such D3DPOOL_SYSTEMMEM texture. CreateTexture fails.
Direct3D9: (ERROR) :Failure trying to create a texture

Plus the documentation says the resource should be located in the DEFAULT pool:

To be shared, you need to designate a resource for sharing at the time of creation, and locate the resource in the default pool (D3DPOOL_DEFAULT). Once a resource is created for sharing, it can be shared across devices within a process, or shared across processes.

To enable shared resources, the resource creation APIs have an additional handle parameter. This is a HANDLE that points to the shared resource. In previous revisions of DirectX, this argument has been part of the API signature, but has been unused and must be set to NULL. Starting with Windows Vista, use pSharedHandle in the following ways:

* Set the pointer (pSharedHandle) to NULL to not share a resource. This is just like the behavior of DirectX prior to Windows Vista.
* To create a shared resource, call any resource creation API (see below) with an uninitialized handle (the pointer itself is not NULL (pSharedHandle != NULL), but the pointer points to a NULL value (*pSharedHandle == NULL)). The API will generate a shared resource and return a valid handle.
* To access a shared resource, simply use the shared resource handle.

In Windows Vista CreateTexture can create a texture from a system memory pointer allowing the application more flexibility over the use, allocation and deletion of the system memory. For example, an application could pass a GDI system memory bitmap pointer and get a Direct3D texture interface around it. Using a system memory pointer with CreateTexture has the following restrictions.

* The pitch of the texture must be equal to the width multiplied by the number of bytes per pixel.
* Only textures with a single mipmap level are supported. The Levels argument must be 1.
* The Pool argument must be D3DPOOL_SYSTEMMEM.
* The pSharedHandle argument must be a valid pointer to a buffer that can hold the system memory point; *pSharedHandle must be a valid pointer to system memory with a size in bytes of texture width * texture height * bytes per pixel of the texture format.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement