Wargus / stratagus

The Stratagus strategy game engine
GNU General Public License v2.0
619 stars 119 forks source link

Crash to desktop when upgrading/morphing unit that is carrying resources into one that cannot #599

Open Kaitrei opened 7 months ago

Kaitrei commented 7 months ago

This is one I've been running into for a while and I didn't think to report it as I had a less than ideal workaround. The prototype I'm working on is heavily dependent on the idea of your main ground units being able to upgrade/train into every other job as it's a hybrid RTS/colony sim. Being able to turn your workers into militia or fighters.

As of 3.3.2 and earlier, when you try to upgrade a unit that is currently carrying resources into one that cannot carry the resource it's carrying, the game immediately crashes to desktop and produces an error log I cannot make sense of.

My current workaround has been to set all resource harvesters to drop their resources once they stop their current order and to make it so the upgrade buttons are unavailable if a unit is acting on any other order. (They have to stand still to upgrade.) I don't like that I have to set "lose-resources" for every resource on my workers, so I'd like to propose one of two changes to fix this:

  1. Add a check at the end of a unit upgrade/morph that checks if the new unit can carry the resources the current unit is carrying. If not, clear carried resources. (I know enough C/C++ that I might be able to implement this solution if someone can point me in the right .cpp files to add this in, but I'm not set up to compile.)
  2. Add flag that you can set in Buttons.lua that lets you enable/disable a button only if a unit is/isn't carrying any resources, taking away the ability to upgrade the unit while it's carrying resources or limiting it to upgrade paths that can carry resources.