Skip to content

Commit d2af619

Browse files
monsieurhberru
andauthored
fix: check for GO existence before sending message (#80)
The camera was calling `msg.post(sender, MSG_SHAKE_COMPLETED) without checking if sender is still present at that point. Since this is a callback, the shake can end at a point in time where the sender is no longer alive. Sample error produced when this happens below : `ERROR:GAMEOBJECT: Instance '/instance80' could not be found when dispatching message 'shake_completed' sent from game:/camera#script` Co-authored-by: berru <[email protected]>
1 parent afeb63e commit d2af619

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

orthographic/camera.script

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ function on_message(self, message_id, message, sender)
118118
self.viewport_bottom = message.bottom or 0
119119
elseif message_id == camera.MSG_SHAKE then
120120
camera.shake(self.id, message.intensity, message.duration, message.direction, function()
121-
msg.post(sender, camera.MSG_SHAKE_COMPLETED)
121+
if go.exists(sender) then
122+
msg.post(sender, camera.MSG_SHAKE_COMPLETED)
123+
end
122124
end)
123125
elseif message_id == camera.MSG_RECOIL then
124126
camera.recoil(self.id, message.offset, message.duration)
@@ -130,4 +132,4 @@ function on_message(self, message_id, message, sender)
130132
elseif message_id == camera.MSG_SET_AUTOMATIC_ZOOM then
131133
self.automatic_zoom = message.enabled
132134
end
133-
end
135+
end

0 commit comments

Comments
 (0)