From 3aa73ae1c70c264d17e4e5b9a62d7227cabf3a1c Mon Sep 17 00:00:00 2001 From: Jeff Ames Date: Tue, 20 Nov 2007 05:05:27 +0000 Subject: fixed array range out of bounds exception and reference invalidation under load in POS --- OpenSim/Region/Physics/POSPlugin/POSPlugin.cs | 47 +++++++++++++++------------ 1 file changed, 26 insertions(+), 21 deletions(-) (limited to 'OpenSim/Region/Physics/POSPlugin') diff --git a/OpenSim/Region/Physics/POSPlugin/POSPlugin.cs b/OpenSim/Region/Physics/POSPlugin/POSPlugin.cs index 802b7b2..bdd23ab 100644 --- a/OpenSim/Region/Physics/POSPlugin/POSPlugin.cs +++ b/OpenSim/Region/Physics/POSPlugin/POSPlugin.cs @@ -156,21 +156,25 @@ namespace OpenSim.Region.Physics.POSPlugin private bool check_all_prims(POSCharacter c) { - foreach (POSPrim p in _prims) + for (int i = 0; i < _prims.Count; ++i) { - if (check_collision(c, p)) + if (check_collision(c, _prims[i])) return true; } return false; } + public override void AddPhysicsActorTaint(PhysicsActor prim) { } + public override void Simulate(float timeStep) { - foreach (POSCharacter character in _characters) + for (int i = 0; i < _characters.Count; ++i) { + POSCharacter character = _characters[i]; + float oldposX = character.Position.X; float oldposY = character.Position.Y; float oldposZ = character.Position.Z; @@ -183,6 +187,25 @@ namespace OpenSim.Region.Physics.POSPlugin bool forcedZ = false; character.Position.X = character.Position.X + (character._target_velocity.X * timeStep); character.Position.Y = character.Position.Y + (character._target_velocity.Y * timeStep); + + if (character.Position.Y < 0) + { + character.Position.Y = 0.1F; + } + else if (character.Position.Y >= 256) + { + character.Position.Y = 255.9F; + } + + if (character.Position.X < 0) + { + character.Position.X = 0.1F; + } + else if (character.Position.X >= 256) + { + character.Position.X = 255.9F; + } + float terrainheight = _heightMap[(int)character.Position.Y * 256 + (int)character.Position.X]; if (character.Position.Z + (character._target_velocity.Z * timeStep) < terrainheight + 2) { @@ -221,24 +244,6 @@ namespace OpenSim.Region.Physics.POSPlugin } } - if (character.Position.Y < 0) - { - character.Position.Y = 0.1F; - } - else if (character.Position.Y >= 256) - { - character.Position.Y = 255.9F; - } - - if (character.Position.X < 0) - { - character.Position.X = 0.1F; - } - else if (character.Position.X > 256) - { - character.Position.X = 255.9F; - } - character._velocity.X = (character.Position.X - oldposX) / timeStep; character._velocity.Y = (character.Position.Y - oldposY) / timeStep; -- cgit v1.1