2
\$\begingroup\$

Below is a small section of code that is meant to draw a multicolored triangle to the middle of the screen in a MonoGame game. This uses the basic function DrawUserPrimitives to draw the triangle. This works fine in XNA, but the moment i try to use it in a MonoGame DX game (Which compiles using SharpDX) it will crash with the following error:

An unhandled exception of type 'SharpDX.SharpDXException' occurred in SharpDX.dll

Additional information: HRESULT: [0x80070057], Module: [General], ApiCode: [E_INVALIDARG/Invalid Arguments], Message: The parameter is incorrect.

Below is the code that is causing the error.

private void SetUpVertices() {
        vertices = new VertexPositionColor[3];

        vertices[0].Position = new Vector3(-0.5f, -0.5f, 0f);
        vertices[0].Color = Color.Red;
        vertices[1].Position = new Vector3(0, 0.5f, 0f);
        vertices[1].Color = Color.Green;
        vertices[2].Position = new Vector3(0.5f, -0.5f, 0f);
        vertices[2].Color = Color.Yellow;
    }

    public void Draw(GameTime gameTime) {
        gDevice.DrawUserPrimitives(PrimitiveType.TriangleList, vertices, 0, 1, VertexPositionColor.VertexDeclaration);
    }

Has anyone ever come across simillar errors using the DirectX version on MonoGame and SharpDX when dealing with primatives? And do you know of a way I can fix this issue?

\$\endgroup\$

closed as off-topic by Josh Oct 7 '14 at 16:29

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about debugging a problem in your project must present a concise selection of code and context so as to allow a reader to diagnose the issue without needing to read all of your code or to engage in extensive back-and-forth dialog. For more information, see this meta thread." – Josh
If this question can be reworded to fit the rules in the help center, please edit the question.

-1
\$\begingroup\$

I had this all the time when building my engine core code it means you passed something to directx that isn't correct.

At a glance it appears you are passing a vertex array to a draw call .. this doesn't seem right to me although I haven't used monogame in some time (my code is sitting on the raw SharpDX API) so they may have done some wizardry to allow this but my get feel is that you need to put your vertices in to a buffer first then call draw on the buffer.

That said ... This question seems to imply that its fine and that actually you are missing your effect ...

Drawing simple geometric figures with DrawUserPrimitives?

\$\endgroup\$
  • \$\begingroup\$ Awesome thanks, looks like this will solve the issue. Ill try this tomorrow when I'm more awake! \$\endgroup\$ – Lex Webb Sep 17 '14 at 23:05
  • \$\begingroup\$ Did it work? do you need more help? \$\endgroup\$ – War Sep 22 '14 at 10:12
  • \$\begingroup\$ Unfortunately it did not. But appears to be an issue with monogame and sharpdx, in the end I have switched to opened rendering and it has no issues :/ \$\endgroup\$ – Lex Webb Sep 22 '14 at 10:14
  • \$\begingroup\$ Hmmm ... ok if you could update your question maybe I can provide something else to help solve the problem ... or we should perhaps close the question ... I know this is how I solved my last problem with it but it may be that your problem is slightly different as that error covers just about anything in DX \$\endgroup\$ – War Sep 22 '14 at 10:16

Not the answer you're looking for? Browse other questions tagged or ask your own question.