KnuckleCracker / CW4-bug-tracker

The gathering point for bugs and supporting information, or suggestions about additional features.
Creative Commons Attribution Share Alike 4.0 International
13 stars 1 forks source link

[Bug] Stack Overflow when Destroying Custom Scripted Unit #923

Closed RealArgonwolf closed 3 years ago

RealArgonwolf commented 3 years ago

Help us help you.

  1. It is very important that you NOT restart the game before you save the output log

Player.log and error.log:

error.log

Player.log

  1. If the error persists over a save and reload of the game, please provide the save file as well (You may have to zip it up, as the .cw4 file type is not supported as a direct upload in GitHub)

Here's the entire custom map folder, with cpacks and save file:

PAC Again.zip

  1. Screenshots help us to seethe problem. There isn't really anything to see. I destroy the unit, and the game crashes to desktop.

  2. Describe the bug When destroying the Spore Launcher custom unit, the game crashes. The unit uses the CreeperUnit.4rpl script, which itself communicates with the EnergyManager.4rpl and PreUpdateStuff.4rpl global scripts via messages. The scripts nonetheless compile without error.

Additional context Occasionally it doesn't crash when I destroy the unit.

knucracker commented 3 years ago

Looks like there was an infinite "Destroyed" loop going on. Custom units did not properly handle DestroyUnit(self ...) being called from within :Destroyed. I did not investigate the scripts in the mission closely enough to see if there was a chain of calls that lead to the recursive loop (like one unit destroying another that in turn destroys the original unit, or some such chain created with messages). I just guessed there might be an issue with destruction and recreated the crash with a simple script on a unit like this: :Destroyed DestroyUnit(self false false false)

That's enough to get the crash. I had addressed the issue by checking for "already did it" status in the overidden CModUnitManager's DestroyUnit call. That call was responsible for going through attached scripts and invoking their :Destroyed callbacks. That call also was not properly aborting in the case of a recursive loop.

RealArgonwolf commented 3 years ago

I see exactly what you mean. The unit and its second UI page sub-unit destroy each other when destroyed. I can't believe I didn't realize that's what caused the problem.

I'll tell you what Virgil, by the time I'm done reporting bugs CW4 may very well be idiot-proof, because it seems I can break anything if I'm determined enough. Thank you for humoring my embarrassingly sophomoric error nonetheless.