Jump to content

  • Log In with Google      Sign In   
  • Create Account


[SlimDX]access violation exception on ComputeNormals


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
4 replies to this topic

#1 jor1980   Members   -  Reputation: 142

Like
0Likes
Like

Posted 21 March 2013 - 09:53 AM

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[i]);
                vertexBuffer.Write<SlimDX.Vector2>(uvListFifa13[i]);
                vertexBuffer.Seek(12, SeekOrigin.Current);
            }


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

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

                index = (ushort)triangleList[i].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, 21 March 2013 - 10:06 AM.


Sponsor:

#2 Weeve   Members   -  Reputation: 110

Like
0Likes
Like

Posted 22 March 2013 - 01:11 PM

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



#3 Postie   Members   -  Reputation: 930

Like
0Likes
Like

Posted 22 March 2013 - 05:45 PM

@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.


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

#4 jor1980   Members   -  Reputation: 142

Like
0Likes
Like

Posted 23 March 2013 - 09:43 AM

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[i]);
                vertexBuffer.Write<SlimDX.Vector2>(uvListFifa13[i]);
                vertexBuffer.Seek(12, SeekOrigin.Current);
            }


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

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

                index = (ushort)triangleList[i].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);


#5 jor1980   Members   -  Reputation: 142

Like
0Likes
Like

Posted 24 March 2013 - 10:51 AM

Now is solved, the problem was at mi index buffer it had wrog data






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.



PARTNERS