Sign in to follow this  
dessler.michelle

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

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

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

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?

Here you can download the modified source code [url="http://hotfile.com/dl/132045310/01363a3/WPF_Interop_-_Copy.zip.html"]http://hotfile.com/d...-_Copy.zip.html[/url]

Thank you,

Michelle.

Share this post


Link to post
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 [url="http://legalizeadulthood.wordpress.com/2009/06/28/direct3d-programming-tip-5-use-the-debug-runtime/"]DirectX Debug Runtime[/url]. My guess that exception ([i]what[/i] 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 this post


Link to post
Share on other sites
[quote name='unbird' timestamp='1318353881' post='4871509']
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 [url="http://legalizeadulthood.wordpress.com/2009/06/28/direct3d-programming-tip-5-use-the-debug-runtime/"]DirectX Debug Runtime[/url]. My guess that exception ([i]what[/i] 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.
[/quote]

Hi Unbird and thank you for your cordiality,

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

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"][size="2"]SimpleTirangle9 run well however when adding the same code to the [/size][/color][color="#1C2837"][size="2"]WPFSample then I get that exception.[/size][/color]
[color="#1C2837"] [/color][color="#1C2837"][size="2"]Any idea about how to solve this?[/size][/color]
[color="#1C2837"] [/color]
[size="2"][color="#1c2837"]Thank you,[/color][/size]
[size="2"] [/size]
[size="2"][color="#1c2837"]Michelle[/color][/size]
[size="2"] [/size]
[size="2"][color="#1c2837"]PD: [/color][/size]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 this post


Link to post
Share on other sites
You're closer, but not close enough. The [b]DirectX[/b] 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 [i]why[/i]. 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.

[quote]
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 this post


Link to post
Share on other sites
[quote name='unbird' timestamp='1318361743' post='4871562']
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.
[/quote]

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.

I like your style.


[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.
[/quote]

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

Thank you once again.

Michelle

Share this post


Link to post
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

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

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 this post


Link to post
Share on other sites
Just as the error says, the managed pool is not available for IDirect3DDevice9[b]Ex[/b]. 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: [url="http://msdn.microsoft.com/en-us/library/windows/desktop/bb219800(v=vs.85).aspx"]http://msdn.microsoft.com/en-us/library/windows/desktop/bb219800(v=vs.85).aspx[/url]

Share this post


Link to post
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?

[quote]
[color="#1C2837"][size="2"].....

[828] Direct3D9: (ERROR) :Invalid iBackBuffer parameterpassed to GetBackBuffer[/size][/color]
[color="#1C2837"][size="2"][/quote][/size][/color]
[color="#1C2837"] [/color]
[color="#1C2837"][size="2"]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.[/size][/color]
[color="#1C2837"] [/color]
[color="#1C2837"][size="2"]Thank you,[/size][/color]
[color="#1C2837"] [/color]
[color="#1C2837"][size="2"]Michelle[/size][/color]

Share this post


Link to post
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 this post


Link to post
Share on other sites
Hi Ereik,

[quote name='Erik Rufelt' timestamp='1318519999' post='4872219']
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.
[/quote]


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 [img]http://public.gamedev.net/public/style_emoticons/default/biggrin.gif[/img]

Share this post


Link to post
Share on other sites
@Erik: Thank for helping out here, I couldn't until now.

@Michelle: Congrats on your successful application of the DX Debug runtimes.

Now for that "invalid iBackBuffer parameterpassed" error. Trying your code my system (Win7, VS 2010 Express), I don't get a freeze nor a proper break but a silent shutdown of the app, and it's [i]only[/i] triggered by enabling the Break on D3D9 Error. Could not even locate it with "breakpoint binary search". Not sure (such lower-level stuff still eludes me), but I think in managed context it's less helpful, if at all. My guess the break gets triggered within the SlimDX lib, which the C# debugger can't get to, unfortunately. I actually never use that feature myself (probably tried once without success and forgot about it).

But you have other means: One you already experienced: SlimDX can throw a proper exception for API call failures. Have a closer look at the SlimDX.Configuration class and the [url="http://slimdx.org/docs/#Debugging_Tips"]SlimDX programming tips[/url].

Also: Get yourself familiar with PIX, a very helpful tool. Though I could not use it in conjunction with WPF when I helped someone else out lately, it usually works fine for "normal" Direct X apps.

Share this post


Link to post
Share on other sites
[quote]
Now for that "invalid iBackBuffer parameterpassed" error. Trying your code my system (Win7, VS 2010 Express), I don't get a freeze nor a proper break but a silent shutdown of the app, and it's [i]only[/i] triggered by enabling the Break on D3D9 Error.
[/quote]

Right, the same is happening to me and I'm using Win7 VS2010 Ultimate. The app works well but I get that silent error from DX9 and I wanna know what is causing that. Of course without DebugView I wouldn't know about it but now that I know it existence I can't overlook it.


[quote]
But you have other means: One you already experienced: SlimDX can throw a proper exception for API call failures. Have a closer look at the SlimDX.Configuration class and the [url="http://slimdx.org/docs/#Debugging_Tips"]SlimDX programming tips[/url].
[/quote]

Yes, I'll check for the Configuration class and the link

[quote]
Also: Get yourself familiar with PIX, a very helpful tool. Though I could not use it in conjunction with WPF when I helped someone else out lately, it usually works fine for "normal" Direct X apps.
[/quote]

I've checked the PIX app and it's great

Thank you once again Unbird. As you can see I'm a novice with DirectX so any other TIP will be welcomed.

Than you,

Michelle.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this