Sign in to follow this  
JustMe1984

[Solved][SlimDX] "Invalid Call" when trying to render a mesh

Recommended Posts

Hi, I'm experiencing some problems trying to render a mesh. The application fails with "Invalid Call" at .drawsubset(0). I can view the mesh in the meshviewer that comes with the DXSDK. I'm using a real simple effect at the moment, however the mesh contains normals and such which the effect does not use, could this be a cause? I have also tried rendering other meshes without success. Also, how do you make custom vertices in SlimDX, used to be something like vertex = new customvertex.PositionTextured(...) but I can not find it now, just wanted to see if I can render anything at all. Thanks for looking. Here's the whole application:

Imports SlimDX
Imports SlimDX.Direct3D9

Public Class Form1

    Private D3DDevice As Device
    Private DefaultEffect As Effect

    Private GameRunning As Boolean = True

    Private TestMesh As Mesh

    Private WorldMatrix As Matrix = Matrix.Identity
    Private ProjMatrix As Matrix = Matrix.PerspectiveFovLH(Math.PI / 4, 1, 10, 1000)
    Private ViewMatrix As Matrix = Matrix.LookAtLH(New Vector3(0, 500, -500), New Vector3(0, 0, 0), New Vector3(0, 1, 0))

    Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        If e.KeyCode = Keys.Escape Then
            GameRunning = False
        End If
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Me.Show()
        Me.Focus()

        Direct3D.Initialize()

        Dim D3DPP As New PresentParameters
        With D3DPP
            .Windowed = True
            .SwapEffect = SwapEffect.Discard
            .AutoDepthStencilFormat = Format.D24X8
            .EnableAutoDepthStencil = True
        End With

        D3DDevice = New Device(0, DeviceType.Hardware, Me.Handle, CreateFlags.HardwareVertexProcessing, D3DPP)
        With D3DDevice
            .SetTransform(TransformState.Projection, ProjMatrix)
            .SetTransform(TransformState.View, ViewMatrix)
            .SetTransform(TransformState.World, WorldMatrix)
            .SetRenderState(RenderState.ZEnable, True)
        End With

        DefaultEffect = Effect.FromFile(D3DDevice, "defaulteffect.fx", Nothing, Nothing,_
 ShaderFlags.Debug, ShaderFlags.None, Nothing, Nothing)
        DefaultEffect.Technique = "simple"
        DefaultEffect.SetValue("worldViewProj", WorldMatrix * ViewMatrix * ProjMatrix)
        DefaultEffect.CommitChanges()

        TestMesh = Mesh.FromFile(D3DDevice, "spaceship.x", MeshFlags.Managed)

        While GameRunning = True
            Application.DoEvents()

            D3DDevice.Clear(ClearFlags.Target Or ClearFlags.ZBuffer, Color.Black, 1, 0)
            DefaultEffect.Begin(FX.None)
            DefaultEffect.BeginPass(0)

            TestMesh.DrawSubset(0)

            DefaultEffect.EndPass()
            DefaultEffect.End()
            D3DDevice.Present()

        End While

        If DefaultEffect.Disposed = False Then
            DefaultEffect.Dispose()
        End If
        If TestMesh.Disposed = False Then
            TestMesh.Dispose()
        End If
        If D3DDevice.Disposed = False Then
            D3DDevice.Dispose()
        End If
        End
    End Sub
End Class




And here's the effect, from MDXInfo
float4x4 worldViewProj : WORLDVIEWPROJ; //our world view projection matrix

//application to vertex structure
struct a2v
{ 
    float4 position : POSITION0;
};

//vertex to pixel processing structure
struct v2p
{
    float4 position : POSITION0;
};
//VERTEX SHADER
void vs( in a2v IN, out v2p OUT ) 
{
    //transforming our position from object space to screen space.
    OUT.position = mul(IN.position, worldViewProj);
}
technique simple
{
    pass p0
    {
        vertexshader = compile vs_1_1 vs();
    }
}




[Edited by - JustMe1984 on August 5, 2007 2:59:31 AM]

Share this post


Link to post
Share on other sites
INVALID_CALL isn't an error message, it is simply a return value. Enable the Debug Runtimes (Start -> Programs -> DirectX SDK -> Utilities -> DX Control Panel) to get a detailed error message.

Once you enable the debug runtimes, you should be able to view the debug messages in the Output window of Visual Studio (if you don't use express) by enabling "unmanaged debugging" in the project properties.

If you are using VS Express, you can use DebugView (just google the app name for a free download) to catch the debug output from your application.

The debug output should detail exactly what is going wrong, and tell you what it is you're doing incorrectly.

Hope this helps.

Share this post


Link to post
Share on other sites
Also, make sure to enable Unmanaged debugging in your project properties, or you may not see the output that DirectX generates.

Share this post


Link to post
Share on other sites
Thanks for helping, thought express showed errors the same way VS did, anyways problem solved now, I had forgotten device.beginscene(). Thanks again

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