Segfault in battle

Bug #1636966 reported by Notabilis
22
This bug affects 2 people
Affects Status Importance Assigned to Milestone
widelands
Fix Released
Critical
Unassigned

Bug Description

Sorry to disturb the rc1 party but I found a bug. :-(

When soldiers are fighting a segfault can occur when the battle only consists of one soldier.
To be more specific:

In src/logic/map_objects/tribes/soldier.cc :
1256 Soldier& opponent = *battle_->opponent(*this);

The call might return nullptr when the other soldier is no longer part of the battle (in my cases it was the first_ soldier in battle_ who was missing / pointed to 0x0). The description of the method contains "Can return nullptr, but I have no idea what that means." which is what is happening here.

Since someone was aware of (part of) the issue there might be a check for nullptr missing in soldier.cc. Otherwise there is probably some cancel-battle-code somewhere which is missing the part of removing the other soldier. Does anyone has an idea which of the cases applies?
Sadly I can not provide any more information about what was happening since I wasn't observing the game. However, GDB is still running if that is any use.

Edit: Happens in build-19-rc1

Tags: crash

Related branches

Notabilis (notabilis27)
description: updated
Revision history for this message
GunChleoc (gunchleoc) wrote :

A backtrace could help.

Do you have an autosave too?

tags: added: crash
Changed in widelands:
importance: Undecided → Critical
milestone: none → build19
assignee: nobody → GunChleoc (gunchleoc)
GunChleoc (gunchleoc)
Changed in widelands:
status: New → In Progress
Revision history for this message
SirVer (sirver) wrote : Re: [Bug 1636966] Re: Segfault in battle

Is this a regression? If this was in b18 already it should not go into b19.

> Am 27.10.2016 um 08:15 schrieb GunChleoc <email address hidden>:
>
> A backtrace could help.
>
> Do you have an autosave too?
>
> ** Tags added: crash
>
> ** Changed in: widelands
> Importance: Undecided => Critical
>
> ** Changed in: widelands
> Milestone: None => build19
>
> ** Changed in: widelands
> Assignee: (unassigned) => GunChleoc (gunchleoc)
>
> --
> You received this bug notification because you are subscribed to
> widelands.
> https://bugs.launchpad.net/bugs/1636966
>
> Title:
> Segfault in battle
>
> Status in widelands:
> New
>
> Bug description:
> Sorry to disturb the rc1 party but I found a bug. :-(
>
> When soldiers are fighting a segfault can occur when the battle only consists of one soldier.
> To be more specific:
>
> In src/logic/map_objects/tribes/soldier.cc :
> 1256 Soldier& opponent = *battle_->opponent(*this);
>
> The call might return nullptr when the other soldier is no longer part
> of the battle (in my cases it was the first_ soldier in battle_ who
> was missing / pointed to 0x0). The description of the method contains
> "Can return nullptr, but I have no idea what that means." which is
> what is happening here.
>
> Since someone was aware of (part of) the issue there might be a check for nullptr missing in soldier.cc. Otherwise there is probably some cancel-battle-code somewhere which is missing the part of removing the other soldier. Does anyone has an idea which of the cases applies?
> Sadly I can not provide any more information about what was happening since I wasn't observing the game. However, GDB is still running if that is any use.
>
> Edit: Happens in build-19-rc1
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/widelands/+bug/1636966/+subscriptions

Revision history for this message
GunChleoc (gunchleoc) wrote :

I have no idea where the bug comes from or how to trigger it, so I don't know if it's a regression or not.

Revision history for this message
Notabilis (notabilis27) wrote :
Download full text (4.4 KiB)

Sadly I have no savegame. I was running multiple games in parallel so they were overwritten. Since I wasn't participating in the games (7 AIs + passiv player) I don't know what was happening. But at least I can offer a backtrace:

Forcing flag at (64, 104)
Cmd_EnemyFlagAction::execute player(7): flag->owner(8) number=11
Cmd_EnemyFlagAction::execute player(8): flag->owner(7) number=1

Thread 1 "widelands" received signal SIGSEGV, Segmentation fault.
0x000000000119091e in Widelands::Coords::operator== (this=0x48, other=...) at ../src/logic/widelands_geometry.cc:31
31 return x == other.x && y == other.y;

(gdb) bt
#0 0x000000000119091e in Widelands::Coords::operator== (this=0x48, other=...) at ../src/logic/widelands_geometry.cc:31
#1 0x0000000001190973 in Widelands::Coords::operator!= (this=0x48, other=...) at ../src/logic/widelands_geometry.cc:35
#2 0x0000000000dc155a in Widelands::Soldier::battle_update (this=0x99e3ef0, game=...) at ../src/logic/map_objects/tribes/soldier.cc:1257
#3 0x0000000000d58e90 in Widelands::Bob::do_act (this=0x99e3ef0, game=...) at ../src/logic/map_objects/bob.cc:193
#4 0x0000000000d58d5d in Widelands::Bob::act (this=0x99e3ef0, game=..., data=3472) at ../src/logic/map_objects/bob.cc:179
#5 0x0000000000d7736c in Widelands::CmdAct::execute (this=0xc209220, game=...) at ../src/logic/map_objects/map_object.cc:98
#6 0x0000000000e204f9 in Widelands::CmdQueue::run_queue (this=0x7fffffffa090, interval=67, game_time_var=@0x7fffffff9ec8: 19081447) at ../src/logic/cmd_queue.cc:123
#7 0x0000000000d137eb in Widelands::Game::think (this=0x7fffffff9ec0) at ../src/logic/game.cc:555
#8 0x0000000000f34fb5 in InteractiveBase::think (this=0x311fa40) at ../src/wui/interactive_base.cc:306
#9 0x0000000000f48a54 in InteractivePlayer::think (this=0x311fa40) at ../src/wui/interactive_player.cc:169
#10 0x0000000000e9ad13 in UI::Panel::do_think (this=0x311fa40) at ../src/ui_basic/panel.cc:441
#11 0x0000000000e9a5dd in UI::Panel::do_run (this=0x311fa40) at ../src/ui_basic/panel.cc:183
#12 0x0000000000c0c6b6 in UI::Panel::run<UI::Panel::Returncodes> (this=0x311fa40) at ../src/ui_basic/panel.h:96
#13 0x0000000000d134dc in Widelands::Game::run (this=0x7fffffff9ec0, loader_ui=0x7fffffff9e30, start_game_type=Widelands::Game::NewNonScenario, script_to_run="", replay=false,
    prefix_for_replays="single_player") at ../src/logic/game.cc:525
#14 0x0000000000c06ebe in WLApplication::new_game (this=0x18c7690) at ../src/wlapplication.cc:1228
#15 0x0000000000c064b2 in WLApplication::mainmenu_singleplayer (this=0x18c7690) at ../src/wlapplication.cc:1088
#16 0x0000000000c05eb6 in WLApplication::mainmenu (this=0x18c7690) at ../src/wlapplication.cc:994
#17 0x0000000000c02a1e in WLApplication::run (this=0x18c7690) at ../src/wlapplication.cc:441
#18 0x0000000000c010c1 in main (argc=1, argv=0x7fffffffd738) at ../src/main.cc:49

(gdb) display &opponent
9: &opponent = (Widelands::Soldier *) 0x0
(gdb) display battle_
10: battle_ = (Widelands::Battle *) 0xe02cb50
(gdb) display *battle_
11: *battle_ = {<Widelands::MapObject> = {_vptr.MapObject = 0x125b368 <vtable for Widelands::Battle+16>, removed = warning: RTTI symbol not found for class 'bo...

Read more...

Revision history for this message
GunChleoc (gunchleoc) wrote :

It would be interesting to find out why battle_->first_ is nullptr, and if that's a bug. I think for now checking for nullptr should at least prevent the segfault.

GunChleoc (gunchleoc)
Changed in widelands:
status: In Progress → Confirmed
milestone: build19-rc2 → build20-rc1
GunChleoc (gunchleoc)
Changed in widelands:
status: Confirmed → In Progress
GunChleoc (gunchleoc)
Changed in widelands:
status: In Progress → Fix Committed
assignee: GunChleoc (gunchleoc) → nobody
Revision history for this message
Klaus Halfmann (klaus-halfmann) wrote :

GUn: I tried a Multiplayer game with
bzr8872[fri-portraits] on OSX
and
_widelands_dev_widelands_fri_portraits-3917_Debug_x64 on windows

Hosting on Windows (Barbarians, pass thorugh te mountains, Endless agme)
client OSX (Imperial) crashed immediately, actual reason masked by this bug

Playing the other way round, worked.

I will try some other Version (without this bug) and / or try to debug on OSX,

Revision history for this message
GunChleoc (gunchleoc) wrote :

Fixed in build20-rc1

Changed in widelands:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.