MantisBT - VCMI
View Issue Details
0001142VCMIGUI - Battlespublic2012-10-11 17:012014-05-30 17:41
beegee 
beegee 
normalminoralways
closedfixed 
 
0.91 
0001142: Game crashes after starting battle if folder /usr/share/vcmi/Mods is not owned by root
The game crashes after starting a battle if the folder /usr/share/vcmi/Mods is not owned by the user root. The folder /Mods has the following access rights: 755 (no write access for others, group). The error message doesn't contain useful information.

If we soft-link /Mods folder from the user directory for development purposes, then battles should work. (same as for /config).
Console output:

terminate called after throwing an instance of 'std::out_of_range'
  what(): array::at
sh: Zeile 1: 5353 Abgebrochen (Speicherabzug geschrieben) /usr/bin/vcmiserver 3030 > /home/bge/.vcmi/server_log.txt
Error: server failed to close correctly or crashed!
Lost connection to server, ending listening thread!
read: End of file
Something wrong, lost connection while game is still ongoing...
terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::system::system_error> >'
  what(): read: End of file
Abgebrochen (Speicherabzug geschrieben)
No tags attached.
txt VCMI_Server_log.txt (129,592) 2012-10-12 12:39
https://bugs.vcmi.eu/file_download.php?file_id=1150&type=bug
Issue History
2012-10-11 17:01beegeeNew Issue
2012-10-11 17:33IvanNote Added: 0003176
2012-10-11 17:57IvanNote Edited: 0003176bug_revision_view_page.php?bugnote_id=3176#r2016
2012-10-11 17:58beegeeNote Added: 0003177
2012-10-11 17:59IvanNote Edited: 0003176bug_revision_view_page.php?bugnote_id=3176#r2017
2012-10-11 17:59beegeeNote Edited: 0003177bug_revision_view_page.php?bugnote_id=3177#r2019
2012-10-11 18:00IvanNote Added: 0003178
2012-10-11 18:01IvanNote Edited: 0003178bug_revision_view_page.php?bugnote_id=3178#r2021
2012-10-11 19:18beegeeNote Added: 0003179
2012-10-12 12:39beegeeFile Added: VCMI_Server_log.txt
2012-10-12 13:15beegeeNote Added: 0003180
2012-10-12 13:31beegeeNote Edited: 0003180bug_revision_view_page.php?bugnote_id=3180#r2023
2012-10-12 13:33beegeeNote Added: 0003181
2012-10-12 18:02beegeeNote Added: 0003182
2012-10-19 13:28beegeeNote Added: 0003183
2012-10-19 14:29IvanNote Added: 0003184
2012-10-19 15:36beegeeNote Added: 0003185
2012-10-21 16:16beegeeNote Added: 0003186
2012-10-21 16:21beegeeNote Edited: 0003186bug_revision_view_page.php?bugnote_id=3186#r2025
2012-10-22 19:07TowNote Added: 0003187
2012-10-24 15:32beegeeNote Added: 0003188
2012-10-24 15:32beegeeStatusnew => resolved
2012-10-24 15:32beegeeFixed in Version => 0.91
2012-10-24 15:32beegeeResolutionopen => fixed
2012-10-24 15:32beegeeAssigned To => beegee
2014-05-30 17:41beegeeStatusresolved => closed

Notes
(0003176)
Ivan   
2012-10-11 17:33   
(edited on: 2012-10-11 17:59)
Strange. I have whole /usr/share/vcmi directory owned by me - everything OK.

Looks like crash on server. Can you upload logs?

EDIT:

copied vcmi directory without symlinks, changed owner to root/root.
Got some "permission denied" crashes. (log is different from yours)
Fixed by "chmod -R a+rx /usr/share/vcmi"

Changing owner does not changes anything in game.

(0003177)
beegee   
2012-10-11 17:58   
(edited on: 2012-10-11 17:59)
This is the server log located in .vcmi/server_log.txt. Those cryptic codes come from the console coloring(should be removed...)

 Initialization: 0
 Data loading: 60
 Found mod filesystem: ALL/MODS/VCMI/FILESYSTEM
 Found mod filesystem: ALL/MODS/WOG/FILESYSTEM
 Mod filesystems: 0
File system handler: 60
Port 3030 will be used.
 Mod handler: 0
 General text handler: 0
 Hero handler: 20
 Artifact handler: 0
 Creature handler: 30
 Town handler: 20
 Object handler: 0
 Def information handler: 30
 Spell handler: 10
CVCMIServer created!
Listening for connections at port 3030
We've accepted someone... 
Established connection with VCMI 0.9 (client)
Got connection!
Gamestate created!
 Using random seed: 1349973848
Opening map file: MAPS/FOR SALE done.
 Our map checksum: 446597263
 Reading header: 0
 Reading rumors: 0
 Reading predefined heroes: 0
 Reading terrain: 0
 Reading defs info: 10
 Reading objects: 10
 Reading events: 0
 Calculating blocked/visitable tiles: 0
 Map initialization done!
Map loaded!
 Our checksum for the map: 446597263
Initialization: Picking grail position Picking random factions for players Randomizing objects Creating player entries in gs Giving starting hero Replacing hero placeholders Setting up resources Setting up heroes Fog of war Starting bonuses Towns Object initialization Checking objectivesSeed after init is 1715710325 (before was 1349973848)
Gamestate initialized!
Connection 1 will handle 4 player: 0 1 2 255 
const PlayerState* CGameInfoCallback::getPlayer(int, bool) const: Cannot find player 3info!
const PlayerState* CGameInfoCallback::getPlayer(int, bool) const: Cannot find player 4info!
const PlayerState* CGameInfoCallback::getPlayer(int, bool) const: Cannot find player 5info!
const PlayerState* CGameInfoCallback::getPlayer(int, bool) const: Cannot find player 6info!
const PlayerState* CGameInfoCallback::getPlayer(int, bool) const: Cannot find player 7info!
const PlayerState* CGameInfoCallback::getPlayer(int, bool) const: Cannot find player 3info!
const PlayerState* CGameInfoCallback::getPlayer(int, bool) const: Cannot find player 4info!
const PlayerState* CGameInfoCallback::getPlayer(int, bool) const: Cannot find player 5info!
const PlayerState* CGameInfoCallback::getPlayer(int, bool) const: Cannot find player 6info!
const PlayerState* CGameInfoCallback::getPlayer(int, bool) const: Cannot find player 7info!
Saving to Saves/Newgame_Autosave_1
Ordering clients to serialize...
Serializing game info...
Serializing server info...
Game has been successfully saved!
const PlayerState* CGameInfoCallback::getPlayer(int, bool) const: Cannot find player 3info!
const PlayerState* CGameInfoCallback::getPlayer(int, bool) const: Cannot find player 4info!
const PlayerState* CGameInfoCallback::getPlayer(int, bool) const: Cannot find player 5info!
const PlayerState* CGameInfoCallback::getPlayer(int, bool) const: Cannot find player 6info!
const PlayerState* CGameInfoCallback::getPlayer(int, bool) const: Cannot find player 7info!
Creating a query for player 0 with ID=1
Creating a query for player 0 with ID=2


VCMI_Server_Log.txt(just the last part):

const PlayerState* CGameInfoCallback::getPlayer(int, bool) const: Cannot find player 3info!
const PlayerState* CGameInfoCallback::getPlayer(int, bool) const: Cannot find player 4info!
const PlayerState* CGameInfoCallback::getPlayer(int, bool) const: Cannot find player 5info!
const PlayerState* CGameInfoCallback::getPlayer(int, bool) const: Cannot find player 6info!
const PlayerState* CGameInfoCallback::getPlayer(int, bool) const: Cannot find player 7info!
Sending to all clients a package of type 9HeroVisit
Blocking visit at 15 6 0
Message successfully applied (result=1)!
Received client message (request 5 by player 0) of type with ID=163 (8MoveHero).
Player 0 wants to move hero 221 from 15 6 0 to 16 6 0
Sending to all clients a package of type 11TryMoveHero
Moved to 16 6 0
Movement end!
Message successfully applied (result=1)!
Received client message (request 6 by player 0) of type with ID=163 (8MoveHero).
Player 0 wants to move hero 221 from 16 6 0 to 17 5 0
Sending to all clients a package of type 11TryMoveHero
Moved to 17 5 0
Movement end!
Message successfully applied (result=1)!
Received client message (request 7 by player 0) of type with ID=163 (8MoveHero).
Player 0 wants to move hero 221 from 17 5 0 to 18 5 0
Sending to all clients a package of type 11TryMoveHero
Moved to 18 5 0
Movement end!
Message successfully applied (result=1)!
Received client message (request 8 by player 0) of type with ID=163 (8MoveHero).
Player 0 wants to move hero 221 from 18 5 0 to 19 5 0
Sending to all clients a package of type 11TryMoveHero
Moved to 19 5 0
Sending to all clients a package of type 9HeroVisit
Creating a query for player 0 with ID=1
Sending to all clients a package of type 14BlockingDialog
Sending to all clients a package of type 9HeroVisit
Movement end!
Message successfully applied (result=1)!
Received client message (request 9 by player 0) of type with ID=177 (10QueryReply).
Creating a query for player 0 with ID=2
Sending to all clients a package of type 14BlockingDialog
Message successfully applied (result=1)!
Received client message (request 10 by player 0) of type with ID=177 (10QueryReply).
Sending to all clients a package of type 17SetObjectProperty
Sending to all clients a package of type 15RebalanceStacks
Stack of 0 of Centaur Captains #attached to# "Centaur Captains"
Stack of 4 of Centaur Captains #attached to# Bonus system node of type 10CGCreature
Sending to all clients a package of type 15RebalanceStacks
Stack of 0 of Centaur Captains #attached to# "Centaur Captains"
Stack of 4 of Centaur Captains #attached to# Bonus system node of type 10CGCreature
Sending to all clients a package of type 15RebalanceStacks
Stack of 0 of Centaur Captains #attached to# "Centaur Captains"
Stack of 5 of Centaur Captains #attached to# Bonus system node of type 10CGCreature
Sending to all clients a package of type 15RebalanceStacks
Stack of 0 of Centaur Captains #attached to# "Centaur Captains"
Stack of 5 of Centaur Captains #attached to# Bonus system node of type 10CGCreature
Sending to all clients a package of type 15RebalanceStacks
Stack of 0 of Centaur Captains #attached to# "Centaur Captains"
Stack of 5 of Centaur Captains #attached to# Bonus system node of type 10CGCreature
Sending to all clients a package of type 13PlayerBlocked
Sending to all clients a package of type 13PlayerBlocked
Message successfully applied (result=1)!

VCMI_Client_Log.txt (last part as well):

Listening... received server message of type 15RebalanceStacks
    Made first apply on cl
Stack of 0 of Centaur Captains #attached to# "Centaur Captains"
Stack of 5 of Centaur Captains #attached to# Bonus system node of type 10CGCreature
    Applied on gs
    Made second apply on cl
Listening... received server message of type 15RebalanceStacks
    Made first apply on cl
Stack of 0 of Centaur Captains #attached to# "Centaur Captains"
Stack of 5 of Centaur Captains #attached to# Bonus system node of type 10CGCreature
    Applied on gs
    Made second apply on cl
Listening... received server message of type 13PlayerBlocked
    Made first apply on cl
    Applied on gs
    Made second apply on cl
Listening... received server message of type 13PlayerBlocked
    Made first apply on cl
    Applied on gs
    Made second apply on cl
Listening... received server message of type 14PackageApplied
    Made first apply on cl
    Applied on gs
    Made second apply on cl
Listening... Error: server failed to close correctly or crashed!
Lost connection to server, ending listening thread!
read: End of file
Something wrong, lost connection while game is still ongoing...

--------------------------------------
PS: What's the difference between vcmi_server.log and VCMI_Server_Log.txt? (Why are there two logs?)

(0003178)
Ivan   
2012-10-11 18:00   
(edited on: 2012-10-11 18:01)
Can you upload whole VCMI_Server_Log.txt?
There may be some access errors during initialization.

VCMI_Server_Log.txt - everything that goes through logging system
vcmiserver_log.txt - redirected output from vcmiserver

(0003179)
beegee   
2012-10-11 19:18   
The error is really disgusting, it happens to appear only sometimes. 2 of 5 tests it crashes when starting a battle. Now I don't know if it depends on the access rights of the /Mods folder:)

More tests tomorrow...
(0003180)
beegee   
2012-10-12 13:15   
(edited on: 2012-10-12 13:31)
I've uploaded VCMI_Server_Log.txt. This is really confusing: VCMI tag 0.9 release crashes sometimes, while tag 0.9 debug doesn't. Move on with further tests...

(0003181)
beegee   
2012-10-12 13:33   
Tag 0.9 release in /usr/local crashes too. It seems to be that the crash doesn't appear on debug build on my system. Can it be a race condition(threading)?
(0003182)
beegee   
2012-10-12 18:02   
I noticed the crash while debugging. In CGameHandler::startBattleI at line 1997 a new thread is created for initializing battle: boost::thread(boost::bind(&CGameHandler::startBattle, this, armies, tile, heroes, creatureBank, cb, town));

Now stop somewhere in CGameState::setupBattle(line 769) execution by a breakpoint. Now switch to the thread which created the upper thread, debug step-by-step forward and you should see a crash message.
(0003183)
beegee   
2012-10-19 13:28   
Bug fixed in Rev. 2988.

After spending a few hours in testing how the crash occured, I've found out that any battle with double-wide creatures lead to the program termination. I wonder why nobody didn't noticed this bug as it's critical. @Ivan: Could you confirm this please? Thanks.

The bug was introduced with Rev 2956 from the 29th September. The method AccessibilityInfo::accessible checks whether the tile is accessible for the stack to cover. Before the change there was a check if the hex is valid(0 < x > B_SIZE). This check has been moved after an array access.(which resulted to out_of_index exception)

Should I commit this bug fix to tag 0.9 as well? Then we should consider if re-releasing 0.9 is valuable? Otherwise this release seems not to be really playable.
(0003184)
Ivan   
2012-10-19 14:29   
This is certainly not *any* battle - no crashes after several battles where both sides have 2-hex creatures. Without your fix of course.
(0003185)
beegee   
2012-10-19 15:36   
Now this is very strange. Without my fix it seems to crash every battle with 2-hex creatures. With the fix applied it works...
(0003186)
beegee   
2012-10-21 16:16   
(edited on: 2012-10-21 16:21)
Finally I've found out why the mysterious crash occurs. The const method at(size_type n) of the std:array struct in the gcc implementation contains a bug. (The first bug which I found in a compiler or std lib...^^) This is the affected method: http://en.cppreference.com/w/cpp/container/array/at [^]
There exists a thread about that bug on StackOverflow here: http://stackoverflow.com/questions/12136394/issue-with-bounds-checking-a-member-stdarray-inside-a-const-function [^]
Here the bug report on the bug tracker database of GCC: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54388 [^]
The bug was fixed on the 9th September 2012. The newly released GCC 4.7.2 contains that bugfix.

This means there was no problem with the vcmi server/lib code. In debug versions of VCMI better said if VCMI has been compiled with -O0 or no optimization at all, the bug didn't appear. Otherwise with a release build the at(...) method returned random numbers. (they could lead to a crash, or not)

Should we refactor the code to use the unchecked []-operator which works(it can be troublesome to find all references...) or suggest that devs/users should update to GCC 4.7.2?

(0003187)
Tow   
2012-10-22 19:07   
The bug apparently affects only the 4.7 series and my understanding is that all Linux distribution should update GCC to 4.7.2 (if they do have GCC 4.7 at all). So I believe this issue should not affect many developers.

My suggestion would be to leave the code as but add some kind of diagnostic (pseudocode):
#if GCC 4.7.0 || GCC 4.7.1
#error This GCC version has buggy std::array::at version and should not be used. Please update to 4.7.2 or use 4.6.x.
#endif

Alternative:
* replace std::array with boost::array — less cumbersome than forbidding calling array::at().
(0003188)
beegee   
2012-10-24 15:32   
Fixed in Rev. 2992