port without a portdock (game crashing)

Bug #1389211 reported by TiborB
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
widelands
Fix Released
Critical
TiborB

Bug Description

When testing new seafaring AI I found that some ports might be without portdock. AI can skip such ports but the game still crashes sametimes with:

Program received signal SIGSEGV, Segmentation fault.
0x08b13ed3 in std::unique_ptr<Widelands::ExpeditionBootstrap, std::default_delete<Widelands::ExpeditionBootstrap> >::get (this=0x54)
    at /usr/include/c++/4.7/bits/unique_ptr.h:223
223 { return std::get<0>(_M_t); }
(gdb) bt
#0 0x08b13ed3 in std::unique_ptr<Widelands::ExpeditionBootstrap, std::default_delete<Widelands::ExpeditionBootstrap> >::get (this=0x54)
    at /usr/include/c++/4.7/bits/unique_ptr.h:223
#1 0x08b13148 in Widelands::PortDock::expedition_started (this=0x0) at /var/widelands/seafaring-ai/src/economy/portdock.cc:420
#2 0x08a7e727 in Widelands::MapBuildingdataPacket::write_warehouse (this=0xbfffc449, warehouse=..., fw=..., game=..., mos=...)
    at /var/widelands/seafaring-ai/src/map_io/map_buildingdata_packet.cc:1393
#3 0x08a7da34 in Widelands::MapBuildingdataPacket::write (this=0xbfffc449, fs=..., egbase=..., mos=...)
    at /var/widelands/seafaring-ai/src/map_io/map_buildingdata_packet.cc:1210
#4 0x08a975c0 in Widelands::MapSaver::save (this=0xbd24f80) at /var/widelands/seafaring-ai/src/map_io/map_saver.cc:184
#5 0x08b5cf35 in Widelands::GameMapPacket::write (this=0xbfffc53c, fs=..., game=...)
    at /var/widelands/seafaring-ai/src/game_io/game_map_packet.cc:72
#6 0x08b5f0b3 in Widelands::GameSaver::save (this=0xbfffc594) at /var/widelands/seafaring-ai/src/game_io/game_saver.cc:61
#7 0x08872758 in SaveHandler::save_game (this=0xbfffc968, game=..., complete_filename=..., error=0xbfffc5e0)
    at /var/widelands/seafaring-ai/src/logic/save_handler.cc:183
#8 0x08872252 in SaveHandler::think (this=0xbfffc968, game=..., realtime=8253468)
    at /var/widelands/seafaring-ai/src/logic/save_handler.cc:94
#9 0x08809504 in Widelands::Game::think (this=0xbfffc808) at /var/widelands/seafaring-ai/src/logic/game.cc:619
#10 0x089d880b in InteractiveBase::think (this=0xeab7de8) at /var/widelands/seafaring-ai/src/wui/interactive_base.cc:381
#11 0x0894d125 in UI::Panel::do_think (this=0xeab7de8) at /var/widelands/seafaring-ai/src/ui_basic/panel.cc:587
#12 0x0894c7a7 in UI::Panel::run (this=0xeab7de8) at /var/widelands/seafaring-ai/src/ui_basic/panel.cc:211
#13 0x08809187 in Widelands::Game::run (this=0xbfffc808, loader_ui=0xbd8b500, start_game_type=Widelands::Game::NewNonScenario,
    script_to_run=..., replay=false) at /var/widelands/seafaring-ai/src/logic/game.cc:565
#14 0x0890f7ba in NetHost::run (this=0xbfffd4e0, autorun=false) at /var/widelands/seafaring-ai/src/network/nethost.cc:911
#15 0x0874bdbe in WLApplication::mainmenu_multiplayer (this=0x92b1d00) at /var/widelands/seafaring-ai/src/wlapplication.cc:1286

Though I admit that a problem might be with my code...

When you open window of such port, you can see there 'Portdock: 0'

Related branches

Revision history for this message
TiborB (tiborb95) wrote :

If you want to test it, you might use my branch seafaring-ai, watch the output to console for text ' port without portdock at ...x...', so you can pause and investigate the port.
It starts to appear after couple of hours of gameplay, and then after some time game crashes.
You can use new version of soutfall islands map in map section on the website, because there is not enough good maps for seafaring. One reason is that AI cannot work with maps with multiple waters.

Revision history for this message
GunChleoc (gunchleoc) wrote :

Cann you attach a savegame, so we won't have to run the game for several hours when we start investigating the problem?

Revision history for this message
TiborB (tiborb95) wrote :

of course, I just dont have one now as it miraculously behaves well during latest tests...

tags: added: computerplayer crash seafaring
Revision history for this message
TiborB (tiborb95) wrote :

Is it possible to resume network game with all players computer players?
It crashed again, I want to load autosaved file and resume but there is no way to do this - it seems.

Revision history for this message
SirVer (sirver) wrote :

start a new network game, select save (instead of map), set all players to computer and yourself as observer. start the game.

Revision history for this message
TiborB (tiborb95) wrote :

Allright, the option is there, only it crashes :)

Program received signal SIGSEGV, Segmentation fault.
0x0878d3e4 in Widelands::Player::player_number (this=0x0) at /var/widelands/own_bzr/widelands-repo/seafaring-ai/src/logic/player.h:112
112 PlayerNumber player_number() const {return m_plnum;}

Revision history for this message
GunChleoc (gunchleoc) wrote :

We have a couple of bugs related to loading savegames. I have already fixed some, but there are more.

Revision history for this message
SirVer (sirver) wrote :

#6: please always post the full backtrace. This one is hardly useful.

A port without a portdock must never happen. It is one of the invariants the logic works with, some places in the code even use that as the definition of a port (i.e. a Warehouse with a portdock). Something is seriously broken.

Changed in widelands:
status: New → Confirmed
importance: Undecided → Critical
milestone: none → build19-rc1
Revision history for this message
TiborB (tiborb95) wrote :
Download full text (4.0 KiB)

@SirVer re #6

Program received signal SIGSEGV, Segmentation fault.
0x087972a4 in Widelands::Player::player_number (this=0x0) at /var/widelands/BZR/widelands/src/logic/player.h:112
112 PlayerNumber player_number() const {return m_plnum;}
(gdb) bt
#0 0x087972a4 in Widelands::Player::player_number (this=0x0) at /var/widelands/BZR/widelands/src/logic/player.h:112
#1 0x08b1f6fd in DefaultAI::DefaultAI(Widelands::Game&, unsigned char, unsigned char)::{lambda(Widelands::NoteImmovable const&)#2}::operator()(Widelands::NoteImmovable const&) const () at /var/widelands/BZR/widelands/src/ai/defaultai.cc:126
#2 0x08b2c5c5 in std::_Function_handler<void(const Widelands::NoteImmovable&), DefaultAI::DefaultAI(Widelands::Game&, Widelands::PlayerNumber, uint8_t)::<lambda(const Widelands::NoteImmovable&)> >::_M_invoke(const std::_Any_data &, const Widelands::NoteImmovable &) (
    __functor=..., __args#0=...) at /usr/include/c++/4.9.1/functional:2039
#3 0x088046d3 in std::function<void (Widelands::NoteImmovable const&)>::operator()(Widelands::NoteImmovable const&) const (
    this=0xaa2f3a4, __args#0=...) at /usr/include/c++/4.9.1/functional:2439
#4 0x08802c91 in Notifications::NotificationsManager::publish<Widelands::NoteImmovable> (
    this=0x8fceb20 <Notifications::NotificationsManager::get()::instance>, message=...)
    at /var/widelands/BZR/widelands/src/notifications/notifications_impl.h:75
#5 0x0880175c in Notifications::publish<Widelands::NoteImmovable> (message=...)
    at /var/widelands/BZR/widelands/src/notifications/notifications.h:51
#6 0x087fee17 in Widelands::PlayerImmovable::cleanup (this=0xaaa99d8, egbase=...)
    at /var/widelands/BZR/widelands/src/logic/immovable.cc:1411
#7 0x088b98a3 in Widelands::Building::cleanup (this=0xaaa99d8, egbase=...) at /var/widelands/BZR/widelands/src/logic/building.cc:439
#8 0x08886e26 in Widelands::Warehouse::cleanup (this=0xaaa99d8, egbase=...) at /var/widelands/BZR/widelands/src/logic/warehouse.cc:550
#9 0x08808bb6 in Widelands::MapObject::remove (this=0xaaa99d8, egbase=...) at /var/widelands/BZR/widelands/src/logic/instances.cc:369
#10 0x088081e8 in Widelands::ObjectManager::cleanup (this=0xbfffcd74, egbase=...)
    at /var/widelands/BZR/widelands/src/logic/instances.cc:161
#11 0x08756534 in Widelands::EditorGameBase::cleanup_objects (this=0xbfffcd60)
    at /var/widelands/BZR/widelands/src/logic/editor_game_base.h:180
#12 0x087e374d in Widelands::EditorGameBase::cleanup_for_load (this=0xbfffcd60)
    at /var/widelands/BZR/widelands/src/logic/editor_game_base.cc:496
#13 0x087f1536 in Widelands::Game::cleanup_for_load (this=0xbfffcd60) at /var/widelands/BZR/widelands/src/logic/game.cc:640
#14 0x08854978 in Widelands::ReplayWriter::ReplayWriter (this=0xaa31de0, game=..., filename="replays/2014-11-09T21.35.10.wrpl")
    at /var/widelands/BZR/widelands/src/logic/replay.cc:242
#15 0x087f0ffc in Widelands::Game::run (this=0xbfffcd60, loader_ui=0x98a22b8, start_game_type=Widelands::Game::Loaded, script_to_run="",
    replay=false) at /var/widelands/BZR/widelands/src/logic/game.cc:541
#16 0x088fabf6 in NetHost::run (this=0xbfffd8c0, autorun=false) at /var/widelands/BZR/widelands/src/netwo...

Read more...

Revision history for this message
TiborB (tiborb95) wrote :

I moved forward with the bug, please look at this function:
http://bazaar.launchpad.net/~widelands-dev/widelands/seafaring-ai/view/head:/src/logic/warehouse.cc#L480

it seems that if game fails to find 'dock' fields close to the port, no portdock is created - and game goes on.

I will test it and hope I will encounter such situation again - to be sure, but this seems to be a cause. Also it would explain why it crashes on some maps only.

It can be some discrepancy between editor and game itself, editor being more tolerant when identifying port-able fields.

One of solution might be to remove every single port in editor that has this problem - solution for my maps, I mean.

Also I would modify the log (error notification) to be more specific (including coordinates of such problematic port).

What do you think?

Revision history for this message
TiborB (tiborb95) wrote :

Update:
upon some testing maybe the things are different. I had a case when port was created with portdock properly, but after some time portdock dissapeared. I go on with testing....

Revision history for this message
TiborB (tiborb95) wrote :

Update 2:

Well, I got bt from removing portdock from warehouse:

#0 Widelands::PortDock::cleanup (this=0xd3ce8b0, egbase=...) at /var/widelands/seafaring-ai/src/economy/portdock.cc:187
#1 0x08823baf in Widelands::MapObject::remove (this=0xd3ce8b0, egbase=...) at /var/widelands/seafaring-ai/src/logic/instances.cc:369
#2 0x08823be2 in Widelands::MapObject::destroy (this=0xd3ce8b0, egbase=...) at /var/widelands/seafaring-ai/src/logic/instances.cc:386
#3 0x08822b5f in Widelands::CmdDestroyMapObject::execute (this=0xd20c978, game=...)
    at /var/widelands/seafaring-ai/src/logic/instances.cc:50
#4 0x088daea9 in Widelands::CmdQueue::run_queue (this=0xbfffc950, interval=120, game_time_var=@0xbfffc818: 26272168)
    at /var/widelands/seafaring-ai/src/logic/cmd_queue.cc:125
#5 0x08809995 in Widelands::Game::think (this=0xbfffc808) at /var/widelands/seafaring-ai/src/logic/game.cc:613
#6 0x089d8d87 in InteractiveBase::think (this=0x9a116e0) at /var/widelands/seafaring-ai/src/wui/interactive_base.cc:381
#7 0x0894d6a1 in UI::Panel::do_think (this=0x9a116e0) at /var/widelands/seafaring-ai/src/ui_basic/panel.cc:587

I dont know what command was run by queue, perhaps attack, but the game destroyed portdock and left the port without it.

After some time it led to a crash.

Revision history for this message
SirVer (sirver) wrote :

That's it. A portdocks livetime and it's warehouse must be linked. If one is destroyed, the other one must be too.

That said, a portdock must never be destroyed through expansion or warfare - the field is not usable for the conqueror anyways.

Revision history for this message
TiborB (tiborb95) wrote :

Maybe a strong military building of enemy is enough to conquer fields that happen to be a portdock....

There must be a code that say how a military influence of military buildings is applied to ownership of field, but I know nothing about where it is and how it works.

What I could perhaps code is that if a portdock is to be removed, remove also port.

Revision history for this message
SirVer (sirver) wrote :

That is a reasonable approach to take as well. Certainly better than crashing :).

Revision history for this message
wl-zocker (wl-zocker) wrote :

If I put together what you say, are the following statements correct?
- Every port has a portdock somewhere in the vicinity, but not on the same field.
- When the field on which the portdock is placed is conquered by an enemy, the portdock is destroyed (like normal buildings burn down).
- Tibor's plan: "What I could perhaps code is that if a portdock is to be removed, remove also port."
- Conclusion: A port could be destroyed by destroying the portdock, i.e. conquerering the field in its vicinity, and not the port itself.

If yes, that is not the way it should work. Is it possible that portdock ignore the owner of the field?

Revision history for this message
TiborB (tiborb95) wrote :

@wl-zocker

you are right, only a portdock can consist of 1 - ~6 fields.

I want to change the code so it first try to restore a portdock (with reduced size), and if not succesful, destroy the port. But I am not familiar with this code, so I am struggling... :(

portdock cannot ignore the owner of field, but perhaps it could prevent the change of the owner - but this is far beyond my coding capabilities... :)

Revision history for this message
TiborB (tiborb95) wrote :

Well, I implemented automatical restoration of portdock - and run into problem when shutting the game - it locked up, started periodically remove and restore the same portdock...

So I will stay with design that port is removed when portdock is gone.

I can say, this is not a big problem anyway, it happens very rarely, I run to this problem on my spider lake map, where rivers are narrow, there was a military building on the other bank and it destroyed a port on the other bank.

Also a player can mitigate a problem if he builds a military building near a port.

Revision history for this message
GunChleoc (gunchleoc) wrote :

The game class has an enum member gs_ending, maybe you can test for the game state before regenerating the portdock.

Revision history for this message
TiborB (tiborb95) wrote :

I will test it

Revision history for this message
TiborB (tiborb95) wrote :

Should be fixed in seafaring-ai. The game now tries to restore a portdock and if it fails it tears down the port itself.

Changed in widelands:
assignee: nobody → TiborB (tiborb95)
Revision history for this message
TiborB (tiborb95) wrote :

seafaring-ai merged in rev 7399

Changed in widelands:
status: Confirmed → Fix Committed
GunChleoc (gunchleoc)
tags: added: ai
removed: computerplayer
GunChleoc (gunchleoc)
Changed in widelands:
status: Fix Committed → Fix Released
Revision history for this message
GunChleoc (gunchleoc) wrote :

Fixed in build19-rc1.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

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