/* attempt to deal with prototype, bootstrap, jquery conflicts */ /* for dropdown menus */

Jump to content

Image of the Day

What's the best way to move your heavy stuff? Using a power loader! #spacr #screenshotsaturday 💪🤖💪 https://t.co/sOjz2XNVeq
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net's newsletters to receive the latest updates and exclusive content.

Sign up now

[SlimDX] Optimize mesh

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 jor1980   Members   


Posted 20 March 2013 - 04:55 PM

Hi, i am trying to optimize my mesh with this code, but i don´t know why i have an access violation exception whe i call mesh.GenerateAdjacency,

i don´t know if this error is because the flags used creating the mesh or the flags creating my device or i don´t know, Anyone could guide me?


SlimDX.Direct3D9.Direct3D myDirect3D= new SlimDX.Direct3D9.Direct3D();
            SlimDX.Direct3D9.PresentParameters myPresentParamters= new SlimDX.Direct3D9.PresentParameters();
            SlimDX.Direct3D9.Device myDevice= new SlimDX.Direct3D9.Device(myDirect3D,0,SlimDX.Direct3D9.DeviceType.Hardware,this.Handle,SlimDX.Direct3D9.CreateFlags.SoftwareVertexProcessing,myPresentParamters);
            int faceCount=triangleList.Count;
            int vertexCount=vertexList.Count;
            SlimDX.Direct3D9.Mesh myMesh = new SlimDX.Direct3D9.Mesh(myDevice, faceCount, vertexCount, SlimDX.Direct3D9.MeshFlags.SystemMemory, SlimDX.Direct3D9.VertexFormat.Position);

            SlimDX.DataStream indexBuffer = myMesh.LockIndexBuffer(SlimDX.Direct3D9.LockFlags.None);
            SlimDX.DataStream vertexBuffer = myMesh.LockVertexBuffer(SlimDX.Direct3D9.LockFlags.None);

            for (int i = 0; i < myMesh.VertexCount; i++)

            for (int i = 0; i < myMesh.FaceCount; i++)
                ushort index;
                index = (ushort)triangleList[i].X;

                index = (ushort)triangleList[i].Y;

                index = (ushort)triangleList[i].Z;

            SlimDX.Direct3D9.Mesh meshOptimizada = myMesh.Optimize(SlimDX.Direct3D9.MeshOptimizeFlags.StripReorder);



#2 Postie   Members   


Posted 21 March 2013 - 07:25 PM

I've seen access violations like this occur when the index buffer contains data that is out of the range of your vertices. Since you haven't unlocked your buffers after writing data to them, I'm guessing the data hasn't actually been committed yet. You'll need to call Unlock() on both of your buffers before you call any of those other functions.


Also, if your vertex and index buffer formats match the data in your lists, you should be able to use vertexBuffer.WriteRange(vertexList) and indexbuffer.WriteRange(trianglelist) instead of having to do each item individually in a loop.


Finally, its good practise to test your return values, rather than just blindly use the result that's passed back.

Currently working on an open world survival RPG - For info check out my Development blog: ByteWrangler

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.