fix a null ref in ubOde character

0.9.0-post-fixes
UbitUmarov 2017-05-20 23:37:14 +01:00
parent 046ec66ff9
commit a5e3aab575
1 changed files with 34 additions and 36 deletions

View File

@ -138,7 +138,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
); );
// we do land collisions not ode | CollisionCategories.Land); // we do land collisions not ode | CollisionCategories.Land);
public IntPtr Body = IntPtr.Zero; public IntPtr Body = IntPtr.Zero;
private ODEScene _parent_scene; private ODEScene m_parent_scene;
private IntPtr capsule = IntPtr.Zero; private IntPtr capsule = IntPtr.Zero;
public IntPtr collider = IntPtr.Zero; public IntPtr collider = IntPtr.Zero;
@ -169,6 +169,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
{ {
m_uuid = UUID.Random(); m_uuid = UUID.Random();
m_localID = localID; m_localID = localID;
m_parent_scene = parent_scene;
timeStep = parent_scene.ODE_STEPSIZE; timeStep = parent_scene.ODE_STEPSIZE;
invtimeStep = 1 / timeStep; invtimeStep = 1 / timeStep;
@ -187,13 +188,10 @@ namespace OpenSim.Region.PhysicsModule.ubOde
} }
else else
{ {
_position = new Vector3(((float)_parent_scene.WorldExtents.X * 0.5f), ((float)_parent_scene.WorldExtents.Y * 0.5f), parent_scene.GetTerrainHeightAtXY(128f, 128f) + 10f); _position = new Vector3(((float)m_parent_scene.WorldExtents.X * 0.5f), ((float)m_parent_scene.WorldExtents.Y * 0.5f), parent_scene.GetTerrainHeightAtXY(128f, 128f) + 10f);
m_log.Warn("[PHYSICS]: Got NaN Position on Character Create"); m_log.Warn("[PHYSICS]: Got NaN Position on Character Create");
} }
_parent_scene = parent_scene;
m_size.X = pSize.X; m_size.X = pSize.X;
m_size.Y = pSize.Y; m_size.Y = pSize.Y;
m_size.Z = pSize.Z; m_size.Z = pSize.Z;
@ -213,7 +211,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
// force lower density for testing // force lower density for testing
m_density = 3.0f; m_density = 3.0f;
mu = parent_scene.AvatarFriction; mu = m_parent_scene.AvatarFriction;
walkDivisor = walk_divisor; walkDivisor = walk_divisor;
runDivisor = rundivisor; runDivisor = rundivisor;
@ -437,11 +435,11 @@ namespace OpenSim.Region.PhysicsModule.ubOde
{ {
if (value.Z > 9999999f) if (value.Z > 9999999f)
{ {
value.Z = _parent_scene.GetTerrainHeightAtXY(127, 127) + 5; value.Z = m_parent_scene.GetTerrainHeightAtXY(127, 127) + 5;
} }
if (value.Z < -100f) if (value.Z < -100f)
{ {
value.Z = _parent_scene.GetTerrainHeightAtXY(127, 127) + 5; value.Z = m_parent_scene.GetTerrainHeightAtXY(127, 127) + 5;
} }
AddChange(changes.Position, value); AddChange(changes.Position, value);
} }
@ -704,7 +702,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
{ {
if (pushforce) if (pushforce)
{ {
AddChange(changes.Force, force * m_density / (_parent_scene.ODE_STEPSIZE * 28f)); AddChange(changes.Force, force * m_density / (m_parent_scene.ODE_STEPSIZE * 28f));
} }
else else
{ {
@ -751,9 +749,9 @@ namespace OpenSim.Region.PhysicsModule.ubOde
AvaAvaSizeYsq = 0.5f * sy; AvaAvaSizeYsq = 0.5f * sy;
AvaAvaSizeYsq *= AvaAvaSizeYsq; AvaAvaSizeYsq *= AvaAvaSizeYsq;
_parent_scene.waitForSpaceUnlock(_parent_scene.CharsSpace); m_parent_scene.waitForSpaceUnlock(m_parent_scene.CharsSpace);
collider = d.HashSpaceCreate(_parent_scene.CharsSpace); collider = d.HashSpaceCreate(m_parent_scene.CharsSpace);
d.HashSpaceSetLevels(collider, -4, 3); d.HashSpaceSetLevels(collider, -4, 3);
d.SpaceSetSublevel(collider, 3); d.SpaceSetSublevel(collider, 3);
d.SpaceSetCleanup(collider, false); d.SpaceSetCleanup(collider, false);
@ -772,10 +770,10 @@ namespace OpenSim.Region.PhysicsModule.ubOde
d.MassSetBoxTotal(out ShellMass, m_mass, m_size.X, m_size.Y, m_size.Z); d.MassSetBoxTotal(out ShellMass, m_mass, m_size.X, m_size.Y, m_size.Z);
PID_D = basePID_D * m_mass / _parent_scene.ODE_STEPSIZE; PID_D = basePID_D * m_mass / m_parent_scene.ODE_STEPSIZE;
PID_P = basePID_P * m_mass / _parent_scene.ODE_STEPSIZE; PID_P = basePID_P * m_mass / m_parent_scene.ODE_STEPSIZE;
Body = d.BodyCreate(_parent_scene.world); Body = d.BodyCreate(m_parent_scene.world);
_zeroFlag = false; _zeroFlag = false;
m_pidControllerActive = true; m_pidControllerActive = true;
@ -795,7 +793,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
// The purpose of the AMotor here is to keep the avatar's physical // The purpose of the AMotor here is to keep the avatar's physical
// surrogate from rotating while moving // surrogate from rotating while moving
Amotor = d.JointCreateAMotor(_parent_scene.world, IntPtr.Zero); Amotor = d.JointCreateAMotor(m_parent_scene.world, IntPtr.Zero);
d.JointAttach(Amotor, Body, IntPtr.Zero); d.JointAttach(Amotor, Body, IntPtr.Zero);
d.JointSetAMotorMode(Amotor, 0); d.JointSetAMotorMode(Amotor, 0);
@ -854,8 +852,8 @@ namespace OpenSim.Region.PhysicsModule.ubOde
//kill the Geoms //kill the Geoms
if (capsule != IntPtr.Zero) if (capsule != IntPtr.Zero)
{ {
_parent_scene.actor_name_map.Remove(capsule); m_parent_scene.actor_name_map.Remove(capsule);
_parent_scene.waitForSpaceUnlock(collider); m_parent_scene.waitForSpaceUnlock(collider);
d.GeomDestroy(capsule); d.GeomDestroy(capsule);
capsule = IntPtr.Zero; capsule = IntPtr.Zero;
} }
@ -1049,20 +1047,20 @@ namespace OpenSim.Region.PhysicsModule.ubOde
fixbody = true; fixbody = true;
localpos.X = 0.1f; localpos.X = 0.1f;
} }
else if (localpos.X > _parent_scene.WorldExtents.X - 0.1f) else if (localpos.X > m_parent_scene.WorldExtents.X - 0.1f)
{ {
fixbody = true; fixbody = true;
localpos.X = _parent_scene.WorldExtents.X - 0.1f; localpos.X = m_parent_scene.WorldExtents.X - 0.1f;
} }
if (localpos.Y < 0.0f) if (localpos.Y < 0.0f)
{ {
fixbody = true; fixbody = true;
localpos.Y = 0.1f; localpos.Y = 0.1f;
} }
else if (localpos.Y > _parent_scene.WorldExtents.Y - 0.1) else if (localpos.Y > m_parent_scene.WorldExtents.Y - 0.1)
{ {
fixbody = true; fixbody = true;
localpos.Y = _parent_scene.WorldExtents.Y - 0.1f; localpos.Y = m_parent_scene.WorldExtents.Y - 0.1f;
} }
if (fixbody) if (fixbody)
{ {
@ -1107,7 +1105,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
posch.Y += vel.Y * ftmp; posch.Y += vel.Y * ftmp;
} }
float terrainheight = _parent_scene.GetTerrainHeightAtXY(posch.X, posch.Y); float terrainheight = m_parent_scene.GetTerrainHeightAtXY(posch.X, posch.Y);
if (chrminZ < terrainheight) if (chrminZ < terrainheight)
{ {
if (ctz.Z < 0) if (ctz.Z < 0)
@ -1119,7 +1117,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
m_haveLastFallVel = true; m_haveLastFallVel = true;
} }
Vector3 n = _parent_scene.GetTerrainNormalAtXY(posch.X, posch.Y); Vector3 n = m_parent_scene.GetTerrainNormalAtXY(posch.X, posch.Y);
float depth = terrainheight - chrminZ; float depth = terrainheight - chrminZ;
vec.Z = depth * PID_P * 50; vec.Z = depth * PID_P * 50;
@ -1215,7 +1213,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
break; break;
case PIDHoverType.GroundAndWater: case PIDHoverType.GroundAndWater:
float waterHeight = _parent_scene.GetWaterLevel(); float waterHeight = m_parent_scene.GetWaterLevel();
if (terrainheight > waterHeight) if (terrainheight > waterHeight)
m_targetHoverHeight = terrainheight + m_PIDHoverHeight; m_targetHoverHeight = terrainheight + m_PIDHoverHeight;
else else
@ -1381,7 +1379,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
vec.Y += (ctz.Y - vel.Y) * PID_D * 0.833f; vec.Y += (ctz.Y - vel.Y) * PID_D * 0.833f;
// hack for breaking on fall // hack for breaking on fall
if (ctz.Z == -9999f) if (ctz.Z == -9999f)
vec.Z += -vel.Z * PID_D - _parent_scene.gravityz * m_mass; vec.Z += -vel.Z * PID_D - m_parent_scene.gravityz * m_mass;
} }
} }
} }
@ -1407,7 +1405,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
if (flying || hoverPIDActive) if (flying || hoverPIDActive)
{ {
vec.Z -= _parent_scene.gravityz * m_mass; vec.Z -= m_parent_scene.gravityz * m_mass;
if(!hoverPIDActive) if(!hoverPIDActive)
{ {
@ -1585,7 +1583,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
public override void UnSubscribeEvents() public override void UnSubscribeEvents()
{ {
m_eventsubscription = 0; m_eventsubscription = 0;
_parent_scene.RemoveCollisionEventReporting(this); m_parent_scene.RemoveCollisionEventReporting(this);
lock(CollisionEventsThisFrame) lock(CollisionEventsThisFrame)
CollisionEventsThisFrame.Clear(); CollisionEventsThisFrame.Clear();
} }
@ -1594,7 +1592,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
{ {
lock(CollisionEventsThisFrame) lock(CollisionEventsThisFrame)
CollisionEventsThisFrame.AddCollider(CollidedWith, contact); CollisionEventsThisFrame.AddCollider(CollidedWith, contact);
_parent_scene.AddCollisionEventReporting(this); m_parent_scene.AddCollisionEventReporting(this);
} }
public void SendCollisions(int timestep) public void SendCollisions(int timestep)
@ -1645,14 +1643,14 @@ namespace OpenSim.Region.PhysicsModule.ubOde
AvatarGeomAndBodyCreation(_position.X, _position.Y, _position.Z); AvatarGeomAndBodyCreation(_position.X, _position.Y, _position.Z);
_parent_scene.actor_name_map[collider] = (PhysicsActor)this; m_parent_scene.actor_name_map[collider] = (PhysicsActor)this;
_parent_scene.actor_name_map[capsule] = (PhysicsActor)this; m_parent_scene.actor_name_map[capsule] = (PhysicsActor)this;
_parent_scene.AddCharacter(this); m_parent_scene.AddCharacter(this);
} }
else else
{ {
_parent_scene.RemoveCollisionEventReporting(this); m_parent_scene.RemoveCollisionEventReporting(this);
_parent_scene.RemoveCharacter(this); m_parent_scene.RemoveCharacter(this);
// destroy avatar capsule and related ODE data // destroy avatar capsule and related ODE data
AvatarGeomAndBodyDestroy(); AvatarGeomAndBodyDestroy();
} }
@ -1699,8 +1697,8 @@ namespace OpenSim.Region.PhysicsModule.ubOde
// Velocity = Vector3.Zero; // Velocity = Vector3.Zero;
m_targetVelocity = Vector3.Zero; m_targetVelocity = Vector3.Zero;
_parent_scene.actor_name_map[collider] = (PhysicsActor)this; m_parent_scene.actor_name_map[collider] = (PhysicsActor)this;
_parent_scene.actor_name_map[capsule] = (PhysicsActor)this; m_parent_scene.actor_name_map[capsule] = (PhysicsActor)this;
} }
m_freemove = false; m_freemove = false;
m_pidControllerActive = true; m_pidControllerActive = true;
@ -2008,7 +2006,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
public void AddChange(changes what, object arg) public void AddChange(changes what, object arg)
{ {
_parent_scene.AddChange((PhysicsActor)this, what, arg); m_parent_scene.AddChange((PhysicsActor)this, what, arg);
} }
private struct strAvatarSize private struct strAvatarSize