[Commits] [wesnoth/wesnoth] 795541: Fix #1987: halo remained after killing an unit wit...

GitHub noreply at github.com
Thu Sep 14 17:14:50 UTC 2017


  Branch: refs/heads/master
  Home:   https://github.com/wesnoth/wesnoth
  Commit: 79554179e90d950b44381978c59835d7f021f777
      https://github.com/wesnoth/wesnoth/commit/79554179e90d950b44381978c59835d7f021f777
  Author: Jyrki Vesterinen <sandgtx at gmail.com>
  Date:   2017-09-14 (Thu, 14 Sep 2017)

  Changed paths:
    M src/scripting/game_lua_kernel.cpp
    M src/synced_commands.cpp
    M src/whiteboard/highlighter.hpp
    M src/whiteboard/manager.cpp
    M src/whiteboard/manager.hpp

  Log Message:
  -----------
  Fix #1987: halo remained after killing an unit with the context menu

The cause for this bug was the whiteboard.

A unit destroys its halo when the unit itself is destroyed. Makes sense,
right? Unfortunately, units are managed by shared pointers, and therefore
are not destroyed until all references to them are gone. And the whiteboard
retains a reference to the most recently selected unit.

The obvious fix would be to use a weak (non-owning) pointer in the
whiteboard, but it's sadly not possible because unit_ptr is an
intrusive_ptr. It stores the reference count right in the unit itself, and
therefore the refcount is lost when the unit is destroyed: hence weak
pointers are impossible.

Thus, what I ended up doing was explicitly notifying the whiteboard when an
unit is killed, and releasing the reference when it happens. If anyone has
suggestions about a better implementation, I'd love to hear them.





More information about the Commits mailing list