MegaMek / megamek

MegaMek is a networked Java clone of BattleTech, a turn-based sci-fi boardgame for 2+ players. Fight using giant robots, tanks, and/or infantry on a hex-based map.
http://www.megamek.org
GNU General Public License v2.0
297 stars 287 forks source link

Error for destroyed buildings "Could not find a match for Building to update" #5728

Open repligator opened 3 months ago

repligator commented 3 months ago

Environment

Master (latest PR https://github.com/MegaMek/megamek/pull/5784) Linux Java 17

Description

Error appears after buildings are destroyed.

14:47:01,879 ERROR [megamek.common.Board] {AWT-EventQueue-0} megamek.common.Board.updateBuildings(Board.java:1466) - Could not find a match for Medium Building Building #70011 to update.

Files

megamek.log building_destroyed_error.sav.gz

(Different Game) building_to_update.megamek.log

repligator commented 2 months ago

As of right now, destroyed buildings are handled thusly (see megamek/common/Board.java):

            // Handle garbage input.
            if (bldg == null) {
                LogManager.getLogger().error("Could not find a match for " + other + " to update.");
                continue;

This writes X lines to the log, every turn, with X being the number of destroyed buildings. This can make logs difficult to read and may have a performance impact on maps with lot's of destroyed buildings (nukes, artillery, fire, etc.) Is it possible to recognize that a building has been destroyed and remove it from Vector so that this only runs once per each destroyed building per game?