• Advertisement
Sign in to follow this  

[SlimDX]access violation exception on ComputeNormals

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi first of all i want to apollogize because i did this question before on the wrong forum.

 

My problem is the next, i am creating a mesh with vertex and faceslist, then i call to compute normals and i get an access violation exception, you are trying to read or write in protected memory, i don´t know how to solve it.

 

the error is send in this line : cloneMesh.ComputeNormals();

 

This is my code:

 

SlimDX.Direct3D9.Direct3D myDirect3D= new SlimDX.Direct3D9.Direct3D();
            SlimDX.Direct3D9.PresentParameters myPresentParamters= new SlimDX.Direct3D9.PresentParameters();
            myPresentParamters.Windowed=true;
            myPresentParamters.SwapEffect=SlimDX.Direct3D9.SwapEffect.Discard;
            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.Managed, SlimDX.Direct3D9.VertexFormat.Position|SlimDX.Direct3D9.VertexFormat.Texture1|SlimDX.Direct3D9.VertexFormat.Normal);

            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++)
            {
                vertexBuffer.Write<SlimDX.Vector3>(vertexList);
                vertexBuffer.Write<SlimDX.Vector2>(uvListFifa13);
                vertexBuffer.Seek(12, SeekOrigin.Current);
            }


            for (int i = 0; i < myMesh.FaceCount; i++)
            {
                ushort index;
                index = (ushort)triangleList.X;
                indexBuffer.Write<ushort>(index);

                index = (ushort)triangleList.Y;
                indexBuffer.Write<ushort>(index);

                index = (ushort)triangleList.Z;
                indexBuffer.Write<ushort>(index);
            }

            SlimDX.Direct3D9.Mesh cloneMesh = myMesh.Clone(myDevice, SlimDX.Direct3D9.MeshFlags.Dynamic, SlimDX.Direct3D9.VertexFormat.Position|SlimDX.Direct3D9.VertexFormat.Normal|SlimDX.Direct3D9.VertexFormat.Texture1);
            cloneMesh.ComputeNormals();
            cloneMesh.GenerateAdjacency(0.5f);
            SlimDX.Direct3D9.Mesh meshOptimizada = myMesh.Optimize(SlimDX.Direct3D9.MeshOptimizeFlags.StripReorder);
Edited by jor1980

Share this post


Link to post
Share on other sites
Advertisement

include your code for ComputeNormals() you might be tring to access a value past the size of an array, which would be incorrect RAM management

Share this post


Link to post
Share on other sites

@Weeve, ComputeNormals() is actually a SlimDX API call.

 

As I posted in the other thread you created:

 

 

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.

Share this post


Link to post
Share on other sites

Hi, i have unlocked now the vertex  and index buffer and i still have the same access violation, Do you have any other clue about this?

 

Here is my actual code:

 

SlimDX.Direct3D9.Direct3D myDirect3D= new SlimDX.Direct3D9.Direct3D();
            SlimDX.Direct3D9.PresentParameters myPresentParamters= new SlimDX.Direct3D9.PresentParameters();
            myPresentParamters.Windowed=true;
            myPresentParamters.SwapEffect=SlimDX.Direct3D9.SwapEffect.Discard;
            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.Managed, SlimDX.Direct3D9.VertexFormat.Position|SlimDX.Direct3D9.VertexFormat.Texture1|SlimDX.Direct3D9.VertexFormat.Normal);

            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++)
            {
                vertexBuffer.Write<SlimDX.Vector3>(vertexList);
                vertexBuffer.Write<SlimDX.Vector2>(uvListFifa13);
                vertexBuffer.Seek(12, SeekOrigin.Current);
            }


            for (int i = 0; i < myMesh.FaceCount; i++)
            {
                ushort index;
                index = (ushort)triangleList.X;
                indexBuffer.Write<ushort>(index);

                index = (ushort)triangleList.Y;
                indexBuffer.Write<ushort>(index);

                index = (ushort)triangleList.Z;
                indexBuffer.Write<ushort>(index);
            }

            myMesh.UnlockVertexBuffer();
            myMesh.UnlockIndexBuffer();

            SlimDX.Direct3D9.Mesh cloneMesh = myMesh.Clone(myDevice, SlimDX.Direct3D9.MeshFlags.Dynamic, SlimDX.Direct3D9.VertexFormat.Position|SlimDX.Direct3D9.VertexFormat.Normal|SlimDX.Direct3D9.VertexFormat.Texture1);
            
            cloneMesh.GenerateAdjacency(0.5f);
            cloneMesh.ComputeNormals();
            
            SlimDX.Direct3D9.Mesh meshOptimizada = myMesh.Optimize(SlimDX.Direct3D9.MeshOptimizeFlags.StripReorder);

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement