From 1bcdcc2419b9b4f9c64db740f71bacfb8cd02127 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Wed, 3 Oct 2018 21:17:23 +0100 Subject: mantis 8384: try to fix bullet heimap managed memory sharing with unmanaged lib --- OpenSim/Region/PhysicsModules/BulletS/BSTerrainHeightmap.cs | 1 + OpenSim/Region/PhysicsModules/BulletS/BulletSimData.cs | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/PhysicsModules/BulletS/BSTerrainHeightmap.cs b/OpenSim/Region/PhysicsModules/BulletS/BSTerrainHeightmap.cs index f72ad28..1cb948e 100755 --- a/OpenSim/Region/PhysicsModules/BulletS/BSTerrainHeightmap.cs +++ b/OpenSim/Region/PhysicsModules/BulletS/BSTerrainHeightmap.cs @@ -136,6 +136,7 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys // Frees both the body and the shape. m_physicsScene.PE.DestroyObject(m_physicsScene.World, m_mapInfo.terrainBody); } + m_mapInfo.Release(); } m_mapInfo = null; } diff --git a/OpenSim/Region/PhysicsModules/BulletS/BulletSimData.cs b/OpenSim/Region/PhysicsModules/BulletS/BulletSimData.cs index 308769b..9f4f4a6 100755 --- a/OpenSim/Region/PhysicsModules/BulletS/BulletSimData.cs +++ b/OpenSim/Region/PhysicsModules/BulletS/BulletSimData.cs @@ -27,6 +27,7 @@ using System; using System.Collections.Generic; using System.Text; +using System.Runtime.InteropServices; using OMV = OpenMetaverse; namespace OpenSim.Region.PhysicsModule.BulletS @@ -169,7 +170,7 @@ public class BulletHMapInfo public BulletHMapInfo(uint id, float[] hm, float pSizeX, float pSizeY) { ID = id; heightMap = hm; - terrainRegionBase = OMV.Vector3.Zero; + heightMapHandle = GCHandle.Alloc(heightMap, GCHandleType.Pinned); minCoords = new OMV.Vector3(100f, 100f, 25f); maxCoords = new OMV.Vector3(101f, 101f, 26f); minZ = maxZ = 0f; @@ -185,6 +186,13 @@ public class BulletHMapInfo public float minZ, maxZ; public BulletShape terrainShape; public BulletBody terrainBody; + private GCHandle heightMapHandle; + + public void Release() + { + if(heightMapHandle.IsAllocated) + heightMapHandle.Free(); + } } // The general class of collsion object. -- cgit v1.1