# [SlimDX] Problem trying to render a triangle in WPFSample project

This topic is 2921 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi there,

I'm using SlimDX (March 2011) and I'm trying to render a triangle in the WPFSample (WPF Interop folder) application that comes with the SlimDX. The code to render the triangle was copied from the example SimpleTirangle9 but I get an exception when trying to create the vertex buffer.

In the file MyRenderEngine.cs in its constructor I just added the following line to create the vertex buffer

 vertices = new VertexBuffer(device, Marshal.SizeOf(typeof(Vertex)) * 3, Usage.WriteOnly, VertexFormat.None, Pool.Managed); 

I've added a break point there and when I execute that statement I get the exception.

However when I run the SimpleTriangle9 project it works fine.

Can someone explain me why is this happening?

Thank you,

Michelle.

##### Share on other sites
Welcome to the forum.

I for one can't tell from that line alone, and directly asking to download and debug your project is a bit impolite, especially for a new poster.

You can do yourself a favor by learning about the DirectX Debug Runtime. My guess that exception (what kind of exception) is an DX API call failure. The debug runtimes should tell you what it is. Then come back again, if you can't solve it yourself.

##### Share on other sites

Welcome to the forum.

I for one can't tell from that line alone, and directly asking to download and debug your project is a bit impolite, especially for a new poster.

You can do yourself a favor by learning about the DirectX Debug Runtime. My guess that exception (what kind of exception) is an DX API call failure. The debug runtimes should tell you what it is. Then come back again, if you can't solve it yourself.

Hi Unbird and thank you for your cordiality,

Here's the exception I get when running the project: "D3DERR_INVALIDCALL: Invalid call (-2005530516)"

and here's the StackTrace

at SlimDX.Result.Throw[T](Object dataKey, Object dataValue)
at SlimDX.Result.Record[T](Int32 hr, Boolean failed, Object dataKey, Object dataValue)
at SlimDX.Direct3D9.VertexBuffer..ctor(Device device, Int32 sizeInBytes, Usage usage, VertexFormat format, Pool pool)
at WpfSample.MyRenderEngine..ctor(MyDataModel dataModel) in D:\Projects\WPF Interop - Copy\WpfSample\MyRenderEngine.cs:line 63
at WpfSample.WpfWindow..ctor() in D:\Projects\WPF Interop - Copy\WpfSample\WpfWindow.xaml.cs:line 71

I don't have any idea why it's happening because the same code in the project [color="#1C2837"]SimpleTirangle9 run well however when adding the same code to the [color="#1C2837"]WPFSample then I get that exception.
[color="#1C2837"] [color="#1C2837"]Any idea about how to solve this?
[color="#1C2837"]
[color="#1c2837"]Thank you,

[color="#1c2837"]Michelle

[color="#1c2837"]PD: I sent the whole project because it's very small and because the most of the people in any forum ask for the source code to see what's the problem.

##### Share on other sites
You're closer, but not close enough. The DirectX debug runtimes tells you even more (mostly and hopefully) than what you just posted. DirectX API call failures (the exception) will - unfortunately - only tell you, well, that they failed, but not why. D3DERR_INVALIDCALL is not very conclusive, is it ?

Read the article I linked to carefully and do what it tells. What you posted is not from the DirectX debug runtime, but just the usual debug log from visual studio.

I actually do know already what it is, but I want to guide you through the process, because you really should learn to use the DX debug runtimes. Programming DirectX without them is just too painful.

PD: I sent the whole project because it's very small and because the most of the people in any forum ask for the source code to see what's the problem.
[/quote]

It's fine when you have been asked for, yes, but not as a original post IMO. First, you have to show what you have done already.

##### Share on other sites

I actually do know already what it is, but I want to guide you through the process, because you really should learn to use the DX debug runtimes. Programming DirectX without them is just too painful.

OK, I'll download the SDK today so tomorrow I'll install it and I'll see how that debug works and if I can't solve the problem by myself I'll ask you to guide me and if I can solve it I'll let you know anyways.

It's fine when you have been asked for, yes, but not as a original post IMO. First, you have to show what you have done already.
[/quote]

You're right! I'll have it into account for the next time.

Thank you once again.

Michelle

##### Share on other sites
Hi Unbird,

I’ve downloaded the DirectX SDK and DebugView and finally I solved the problem I had. Here’s the error

[5780] Direct3D9: (ERROR) :D3DPOOL_MANAGED is not valid withIDirect3DDevice9Ex

So I changed the parameter Pool.Managed in the statement

 vertices = new VertexBuffer(device, Marshal.SizeOf(typeof(Vertex)) * 3, Usage.WriteOnly, VertexFormat.None, Pool.Managed); 

With Pool.Default and now it works, I can see the triangle :-)

But I've a question, why Pool.Managed doesn’t work with WPF?

Also, in the DirectX Control Panel if I check the option "Breakon D3D9 Error" then the same app become stunned and I see the following messagesin the DebugView

.....

[828] Direct3D9: :DoneExclusiveMode

[828] Direct3D9: (ERROR) :Invalid iBackBuffer parameterpassed to GetBackBuffer

Why can this be happening?

Thank you once again

Michelle

##### Share on other sites
Just as the error says, the managed pool is not available for IDirect3DDevice9Ex. You don't need it as devices aren't lost like they used to be, and resources are not destroyed when you call Reset for example.
Some changes in the new version here: http://msdn.microsoft.com/en-us/library/windows/desktop/bb219800(v=vs.85).aspx

##### Share on other sites
Hi Erik,

Thank you for your help. I read the article and I see the changes in the DirectX for Windows Vista. I didn't know about these new features added to DirectX9 for Vista.

Can you tell me why this messages is shown in DebugView in the WPF example when I add the triangle to the scene?

[color="#1C2837"].....

[828] Direct3D9: (ERROR) :Invalid iBackBuffer parameterpassed to GetBackBuffer
[color="#1C2837"][/quote]
[color="#1C2837"]
[color="#1C2837"]I realized that it only happens in the WPF example from SlimDX because I tested the example SimpleTriangle9 and that messages doesn't appear in the DebugView.
[color="#1C2837"]
[color="#1C2837"]Thank you,
[color="#1C2837"]
[color="#1C2837"]Michelle

##### Share on other sites
Looks like an attempt is made to get a back-buffer from the D3D device that fails because there are fewer back-buffers than requested. If the program works and you don't call any such functions yourself, perhaps SlimDX works behind the scenes by attempting to request a back-buffer and then handling the error or something like that, but the debug output is still displayed. Just a guess.

##### Share on other sites
Hi Ereik,

Looks like an attempt is made to get a back-buffer from the D3D device that fails because there are fewer back-buffers than requested. If the program works and you don't call any such functions yourself, perhaps SlimDX works behind the scenes by attempting to request a back-buffer and then handling the error or something like that, but the debug output is still displayed. Just a guess.

Yes the application works and I don't call any such functions so I think you're right with your guess anyways I'll see how can I ask directly to the SlimDX's developers.

Thank you very much for your help.

Thank you guys

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 12
• 30
• 9
• 16
• 12