pioneerspacesim/pioneer — Issue #887: onShipHit event can cause crashes
Author: Brianetta
Created: 2012-01-08 19:00:39+00:00
State: open
Labels: Crash or hang

Code like this (first line is line 23):
```lua
local onShipHit = function (ship, attacker)
if attacker:isa('Ship') and attacker:IsPlayer() then
PlayerDamagedShips[ship]=true
end
end

EventQueue.onShipHit:Connect(onShipHit)
```

can cause errors like this:
```
Error: data/modules/StatsTracking/Statstracking.lua:24: attempt to index local 'attacker' (a nil value)
stack traceback:
data/modules/StatsTracking/Statstracking.lua:24: in function
Error: data/modules/StatsTracking/Statstracking.lua:24: attempt to index local 'attacker' (a nil value)
stack traceback:
data/modules/StatsTracking/Statstracking.lua:24: in function
```

I've seen this happen when I have fired a missile at a ship, and when an AI ship has been shooting with a laser at another AI ship.