* Releases Pinned vertex/index list in ODE on next mesh request.

0.6.0-stable
Teravus Ovares 2008-05-25 02:39:58 +00:00
parent 86c46e92cd
commit d3b013be1c
3 changed files with 28 additions and 5 deletions

View File

@ -46,5 +46,7 @@ namespace OpenSim.Region.Physics.Manager
int[] getIndexListAsInt(); int[] getIndexListAsInt();
int[] getIndexListAsIntLocked(); int[] getIndexListAsIntLocked();
float[] getVertexListAsFloatLocked(); float[] getVertexListAsFloatLocked();
void releasePinned();
} }
} }

View File

@ -37,7 +37,8 @@ namespace OpenSim.Region.Physics.Meshing
{ {
public List<Vertex> vertices; public List<Vertex> vertices;
public List<Triangle> triangles; public List<Triangle> triangles;
GCHandle pinnedVirtexes;
GCHandle pinnedIndex;
public float[] normals; public float[] normals;
public Mesh() public Mesh()
@ -164,7 +165,7 @@ namespace OpenSim.Region.Physics.Meshing
result[3*i + 1] = v.Y; result[3*i + 1] = v.Y;
result[3*i + 2] = v.Z; result[3*i + 2] = v.Z;
} }
GCHandle.Alloc(result, GCHandleType.Pinned); pinnedVirtexes = GCHandle.Alloc(result, GCHandleType.Pinned);
return result; return result;
} }
@ -184,10 +185,17 @@ namespace OpenSim.Region.Physics.Meshing
public int[] getIndexListAsIntLocked() public int[] getIndexListAsIntLocked()
{ {
int[] result = getIndexListAsInt(); int[] result = getIndexListAsInt();
GCHandle.Alloc(result, GCHandleType.Pinned); pinnedIndex = GCHandle.Alloc(result, GCHandleType.Pinned);
return result; return result;
} }
public void releasePinned()
{
pinnedVirtexes.Free();
pinnedIndex.Free();
}
public void Append(Mesh newMesh) public void Append(Mesh newMesh)
{ {

View File

@ -69,6 +69,7 @@ namespace OpenSim.Region.Physics.OdePlugin
private float PID_G = 25f; private float PID_G = 25f;
private float m_tensor = 5f; private float m_tensor = 5f;
private int body_autodisable_frames = 20; private int body_autodisable_frames = 20;
private IMesh primMesh = null;
private bool m_usePID = false; private bool m_usePID = false;
@ -674,8 +675,13 @@ namespace OpenSim.Region.Physics.OdePlugin
disableBody(); disableBody();
} }
float[] vertexList = mesh.getVertexListAsFloatLocked(); // Note, that vertextList is pinned in memory IMesh oldMesh = primMesh;
int[] indexList = mesh.getIndexListAsIntLocked(); // Also pinned, needs release after usage
primMesh = mesh;
float[] vertexList = primMesh.getVertexListAsFloatLocked(); // Note, that vertextList is pinned in memory
int[] indexList = primMesh.getIndexListAsIntLocked(); // Also pinned, needs release after usage
int VertexCount = vertexList.GetLength(0)/3; int VertexCount = vertexList.GetLength(0)/3;
int IndexCount = indexList.GetLength(0); int IndexCount = indexList.GetLength(0);
@ -699,6 +705,13 @@ namespace OpenSim.Region.Physics.OdePlugin
m_log.Error("[PHYSICS]: MESH LOCKED"); m_log.Error("[PHYSICS]: MESH LOCKED");
return; return;
} }
if (oldMesh != null)
{
oldMesh.releasePinned();
oldMesh = null;
}
if (IsPhysical && Body == (IntPtr) 0) if (IsPhysical && Body == (IntPtr) 0)
{ {
// Recreate the body // Recreate the body