Crash on starting with trading outpost without first player

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

Bug Description

When starting a game without a player on the first position, the game crashes when a player selects "trading outpost" as start condition.

Steps to reproduce:
- Create a new (single player) game
- Switch to another position for the human player
- Disable the AI at the first position
- Select "Trading Outpost" as starting condition for any active player
- Start the game

Encountered in bzr8141[trunk].

Error message:

Error in Lua Coroutine
[../src/scripting/lua_errors.cc:22] [string "tribes/scripting/starting_conditions/barbaria..."]:104: attempt to index a nil value (local 'plr')
Send message to all players and pause game
Thread 1 "widelands" received signal SIGSEGV, Segmentation fault.
0x0000000000d3f1f0 in std::_Rb_tree<Widelands::MessageId, std::pair<Widelands::MessageId const, Widelands::Message*>, std::_Select1st<std::pair<Widelands::MessageId const, Widelands::Message*> >, std::less<Widelands::MessageId>, std::allocator<std::pair<Widelands::MessageId const, Widelands::Message*> > >::size (this=0x48) at /usr/include/c++/6/bits/stl_tree.h:921
921 { return _M_impl._M_node_count; }

Related branches

Revision history for this message
Notabilis (notabilis27) wrote :

Sorry, I have been to quick with my "Steps to reproduce". Seems it crashes in some strange combinations. The first position does not have to be empty in every case.

Anyway, the crash-output and probably the fix should always be the same.

New steps to reproduce:
- Single player game on the map "The Nile"
- Human player on position 4 (green) with starting condition "Trading Outpost"
- Remove all other players from the game.

Very strange. Also crashes:
- Human on position 1, Headquarters
- AI with Trading Outpost on position 4
- AI with Headquarters on position 8
- Rest empty

But when adding another AI on 5-7 the game starts. Fascinating...

Revision history for this message
Notabilis (notabilis27) wrote :

Okay, I think I understand the behavior. The problematic line is:

> local plr = wl.Game().players[player.number]

player.number is 4 since the player on position 4 should receive the trading outpost.
But wl.Game().players is simply enumerating the players which are present in the game:

> 1 Player(1)
> 2 Player(4)
> 3 Player(5)

So it will crash if the player receiving the outpost has a higher start position number as there are players in the game.
I am not sure what is happening if the position is less or equal than the number of players. The correct player receives the building but I couldn't find out where the wares are going to.

GunChleoc (gunchleoc)
Changed in widelands:
status: New → Triaged
importance: Undecided → Critical
milestone: none → build19-rc1
assignee: nobody → GunChleoc (gunchleoc)
Revision history for this message
GunChleoc (gunchleoc) wrote :

That line was completely unnecessary, I just used the "player" variable. That seems to fix it.

GunChleoc (gunchleoc)
Changed in widelands:
status: Triaged → Fix Committed
assignee: GunChleoc (gunchleoc) → nobody
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.