Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Tao memory access violation  (Read 2421 times)

0 Members and 1 Guest are viewing this topic.

Afr0

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • http://www.afr0games.com
Tao memory access violation
« on: March 07, 2012, 05:01:34 pm »
Trying to draw with Tao gives me a memory access violation exception!

Code: [Select]
                   unsafe
                    {
                        fixed (Vector3* Ptr = &Sim.BodyMesh.TransformedVertices[0])
                            Gl.glVertexPointer(3, Gl.GL_FLOAT, (int)((int)Marshal.OffsetOf(typeof(Vector3), "m_Y") -
                                (int)Marshal.OffsetOf(typeof(Vector3), "m_X") - sizeof(float)), (IntPtr)Ptr);
                        fixed (Vector2* Ptr = &Sim.BodyMesh.TransformedTexVertices[0])
                            Gl.glTexCoordPointer(2, Gl.GL_FLOAT, (int)((int)Marshal.OffsetOf(typeof(Vector3), "m_X") -
                                (int)Marshal.OffsetOf(typeof(Vector3), "m_Y") - sizeof(float)), (IntPtr)Ptr);
                        Gl.glDrawElements(Gl.GL_TRIANGLES, Sim.BodyMesh.FaceCount * 3, Gl.GL_UNSIGNED_INT,
                            Sim.BodyMesh.FaceIndexes);
                    }


The exception occurs when I'm calling glDrawElements()... does anyone know why?
I was thinking of using OpenTK, but I found a post where Laurent wrote that it was difficult (impossible?) to use it with SFML. :(

Please help!

Afr0

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • http://www.afr0games.com
Tao memory access violation
« Reply #1 on: March 07, 2012, 05:12:57 pm »
Specifically, the error I'm getting is AccessViolationException;

Code: [Select]
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Tao memory access violation
« Reply #2 on: March 07, 2012, 07:50:40 pm »
You must disable the color component for vertex arrays, SFML internally leaves it enabled (that is, if you're using SFML 2).
Laurent Gomila - SFML developer

Afr0

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • http://www.afr0games.com
Tao memory access violation
« Reply #3 on: March 10, 2012, 06:38:27 pm »
I'm not sure my vertex-arrays even have color components... how do I disable 'em?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Tao memory access violation
« Reply #4 on: March 10, 2012, 07:18:01 pm »
Quote
I'm not sure my vertex-arrays even have color components... how do I disable 'em?

They don't, that's why you must disable it.

Code: [Select]
glDisableClientState(GL_COLOR_ARRAY);
Laurent Gomila - SFML developer

Afr0

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • http://www.afr0games.com
Tao memory access violation
« Reply #5 on: March 10, 2012, 07:45:26 pm »
Thanks!

 

anything