Skip to content
This repository
Browse code

Fixed applyForce/Torque/AngForce/OffsetForce gates crashing servers w…

…hen given very high values. Thanks to gamerpaddy for finding and reporting the bug.
  • Loading branch information...
commit bec710f4580863426d9772b145d96f9d9d4135e6 1 parent 668c4dd
authored July 19, 2012

Showing 1 changed file with 21 additions and 2 deletions. Show diff stats Hide diff stats

  1. 23  lua/wire/gates/entity.lua
23  lua/wire/gates/entity.lua
@@ -4,6 +4,18 @@
4 4
 
5 5
 GateActions("Entity")
6 6
 
  7
+local function checkv( v )
  8
+	return 	-math.huge < v.x and v.x < math.huge and
  9
+			-math.huge < v.y and v.y < math.huge and
  10
+			-math.huge < v.z and v.z < math.huge
  11
+end
  12
+
  13
+local function checka( v )
  14
+	return 	-math.huge < v.p and v.p < math.huge and
  15
+			-math.huge < v.y and v.y < math.huge and
  16
+			-math.huge < v.r and v.r < math.huge
  17
+end
  18
+
7 19
 GateActions["entity_applyf"] = {
8 20
 	name = "Apply Force",
9 21
 	inputs = { "Ent" , "Vec" },
@@ -14,7 +26,9 @@ GateActions["entity_applyf"] = {
14 26
 		if !Ent:IsValid() or !Ent:GetPhysicsObject():IsValid() then return end
15 27
 		if !(E2Lib.getOwner(gate, Ent) == E2Lib.getOwner(gate, gate)) then return end
16 28
 		if !IsVector(Vec) then Vec = Vector(0, 0, 0) end
17  
-		Ent:GetPhysicsObject():ApplyForceCenter(Vec)
  29
+		if checkv(Vec) then
  30
+			Ent:GetPhysicsObject():ApplyForceCenter(Vec)
  31
+		end
18 32
 	end,
19 33
 	label = function()
20 34
 		return ""
@@ -32,7 +46,9 @@ GateActions["entity_applyof"] = {
32 46
 		if !(E2Lib.getOwner(gate, Ent) == E2Lib.getOwner(gate, gate)) then return end
33 47
 		if !IsVector(Vec) then Vec = Vector (0, 0, 0) end
34 48
 		if !IsVector(Offset) then Offset = Vector (0, 0, 0) end
35  
-		Ent:GetPhysicsObject():ApplyForceOffset(Vec, Offset)
  49
+		if checkv(Vec) and checkv(Offset) then
  50
+			Ent:GetPhysicsObject():ApplyForceOffset(Vec, Offset)
  51
+		end
36 52
 	end,
37 53
 	label = function()
38 54
 		return ""
@@ -52,6 +68,7 @@ GateActions["entity_applyaf"] = {
52 68
 		if !(E2Lib.getOwner(gate, Ent) == E2Lib.getOwner(gate, gate)) then return end
53 69
 
54 70
 		if angForce.p == 0 and angForce.y == 0 and angForce.r == 0 then return end
  71
+		if not checka(angForce) then return end
55 72
 
56 73
 		local phys = Ent:GetPhysicsObject()
57 74
 
@@ -101,6 +118,7 @@ GateActions["entity_applytorq"] = {
101 118
 		if !(E2Lib.getOwner(gate, Ent) == E2Lib.getOwner(gate, gate)) then return end
102 119
 
103 120
 		if Vec.x == 0 and Vec.y == 0 and Vec.z == 0 then return end
  121
+		if not checkv(Vec) then return end
104 122
 
105 123
 		local phys = Ent:GetPhysicsObject()
106 124
 		if not phys:IsValid() then return end
@@ -122,6 +140,7 @@ GateActions["entity_applytorq"] = {
122 140
 
123 141
 		local dir = ( tq:Cross(off) ):GetNormal()
124 142
 
  143
+		if not checkv( dir ) or not checkv( off ) then return end
125 144
 		phys:ApplyForceOffset( dir, off )
126 145
 		phys:ApplyForceOffset( dir * -1, off * -1 )
127 146
 	end,

0 notes on commit bec710f

Please sign in to comment.
Something went wrong with that request. Please try again.