Crash when calling objDestroy in Mod
Posted: Thu Jan 22, 2009 5:18 am
Hi George, hi all,
I now report a crash cause that occurs on my Stars of Call Adventure Mod and bugged me for some time before I was finally able to pinpoint it.
I still don't know if it is simply a misuse of the objDestroy function or a bug with save/load system and space objects. Surely you could help me on it, George.
Here are the facts !
First, everything happens in the following function so it could be useful to know how it is made :
This function instructs a ship to go to a random waypoint. First it destroys any pre-existing waypoint. Then it creates a random waypoint and stores its ID on the ship so it can be destroyed when the waypoint has been reached and the function is called again. I already know that objDestroy called on Nil just does nothing, that's why I don't test anything before calling it.
Crashes occur when I save a game then restore it. They occur on the (objDestroy oldWaypoint) line. They seem not to occur before saving the game, but this point is still subject to further testing. By reading on, you'll learn it can change the possible causes I'm looking for...
I debugged by logging all variables line by line. So I know that, when it crashes, it's on the objDestroy line and that the oldWaypoint passed to objDestroy has a number value. What lies behind this value I don't know...
So to the main question now... When you save a game, does the saved game include Markers ? It should, but that seems a possible scenario : you create a Marker object, you save, then you restore, the Marker hasn't been saved so when you refer to its ID, the game crashes.
I still have to thoroughly check that the function actually works OK before saving/reloading. If it works, then the crash is related to saving/reloading. If it crashes, then it would rather be related to using objDestoy on a Marker object. I'll check and let you know.
Thanks in advance for any hint that could help me to check my code more accurately !
I now report a crash cause that occurs on my Stars of Call Adventure Mod and bugged me for some time before I was finally able to pinpoint it.
I still don't know if it is simply a misuse of the objDestroy function or a bug with save/load system and space objects. Surely you could help me on it, George.
Here are the facts !
First, everything happens in the following function so it could be useful to know how it is made :
Code: Select all
<!--
socOnTimerSetNextWaypoint
When ?
Called by OnTimerSetNextWaypoint Event
What ?
Update ship status
Choose a random waypoint destination
-->
(setq socOnTimerSetNextWaypoint
(lambda (sourceShip)
<!-- Function code itself : begin -->
(block (message oldStatus newStatus nextWaypoint oldWaypoint angle distance)
; Log beginning of function
(setq message (cat "(" (unvGetTick) ") Ship " (objGetName sourceShip) " #" sourceShip " : Entering socOnTimerSetNextWaypoint"))
(dbglog "")
(dbglog message)
; Set variables
(setq oldStatus (objGetData sourceShip "status"))
(setq newStatus "statusToWaypoint")
(setq oldWaypoint (objGetData sourceShip "waypoint"))
; Destroy older waypoint if it exists
(objDestroy oldWaypoint)
; Find next waypoint
(setq nextWaypoint
(sysCreateMarker
""
(sysVectorPolarOffset (objGetPos sourceShip) (random 0 359) (random 400 800))
(objGetSovereign sourceShip)
)
)
; Logging new waypoint
(setq angle (sysVectorAngle (objGetPos nextWaypoint)))
(setq distance (sysVectorDistance Nil (objGetPos nextWaypoint)))
(setq message (cat " Setting new waypoint [" angle "°;" distance "ls]"))
(dbglog message)
; Store new destination into ship data
(objSetData sourceShip "waypoint" nextWaypoint)
; Remove any attacker from the ship's data
; and cancel the associated event
(objSetData sourceShip "attacker" Nil)
(sysCancelTimerEvent sourceShip "OnCheckEndStrikeBack")
; Set new orders
(shpCancelOrders sourceShip)
(shpOrderGoto sourceShip nextWaypoint)
; Set new status
(objSetData sourceShip "status" newStatus)
; Log end of function
(setq message (cat "(" (unvGetTick) ") Ship " (objGetName sourceShip) " #" sourceShip " : Exiting socOnTimerSetNextWaypoint"))
(dbglog message)
)
<!-- Function code itself : end -->
)
)
<!-- Function end -->
Crashes occur when I save a game then restore it. They occur on the (objDestroy oldWaypoint) line. They seem not to occur before saving the game, but this point is still subject to further testing. By reading on, you'll learn it can change the possible causes I'm looking for...
I debugged by logging all variables line by line. So I know that, when it crashes, it's on the objDestroy line and that the oldWaypoint passed to objDestroy has a number value. What lies behind this value I don't know...
So to the main question now... When you save a game, does the saved game include Markers ? It should, but that seems a possible scenario : you create a Marker object, you save, then you restore, the Marker hasn't been saved so when you refer to its ID, the game crashes.
I still have to thoroughly check that the function actually works OK before saving/reloading. If it works, then the crash is related to saving/reloading. If it crashes, then it would rather be related to using objDestoy on a Marker object. I'll check and let you know.
Thanks in advance for any hint that could help me to check my code more accurately !