Home » PLAYER'S HQ 1.13 » JA2 Complete Mods & Sequels » Stracciatella Project (Platform Independent JA2) » Crash when going into tactical screen on mine sectors
Crash when going into tactical screen on mine sectors[message #248222] Wed, 31 March 2010 11:33 Go to next message
bbun is currently offline bbun

 
Messages:74
Registered:April 2004
Location: Amsterdam
For some reason my compiled version on OSX would crash when going into tactical view on maps with mines (at least for drassen mine and alma mine), but only the 2nd time I entered them (and had already captured them).

I tracked this down to a Bus Error in SET_MOVEMENTCOST, triggered from:

StrategicMap.cc -> SetCurrentWorldSector
Keys.cc -> UpdateDoorGraphicsFromStatus
Keys.cc -> SyncronizeDoorStatusToStructureData
WorldDef.cc -> RecompileLocalMovementCosts
WorldDef.cc -> CompileTileMovementCosts

seems like some problem calculating movement costs for mine entrances.

Anyhow, for people running into the same problem, I fixed this by replacing

SET_MOVEMENTCOST( usGridNo, ubDirLoop,  0, TRAVELCOST_OFF_MAP );
SET_MOVEMENTCOST( usGridNo, ubDirLoop,  1, TRAVELCOST_OFF_MAP );


with

FORCE_SET_MOVEMENTCOST( usGridNo, ubDirLoop,  0, TRAVELCOST_OFF_MAP );
FORCE_SET_MOVEMENTCOST( usGridNo, ubDirLoop,  1, TRAVELCOST_OFF_MAP );


at lines 426-427 of TileEngine/WorldDef.cc

Hope this helps others.

Report message to a moderator

Corporal
Re: Crash when going into tactical screen on mine sectors[message #249843] Wed, 21 April 2010 23:34 Go to previous messageGo to next message
bbun is currently offline bbun

 
Messages:74
Registered:April 2004
Location: Amsterdam
I came across another CTD when entering a San Mona sector without mines. I've now tracked this down to the code calling CompileTileMovementCosts(-1), which seems like an invalid gridNo.

Instead of the previous patch, I tried the following, which seems cleaner, and more right:

Line 1101 in WorldDef.cc
if (usGridNo < WORLD_MAX)

changed into
if (usGridNo < WORLD_MAX && usGridNo != -1)

Report message to a moderator

Corporal
Re: Crash when going into tactical screen on mine sectors[message #249845] Thu, 22 April 2010 00:00 Go to previous messageGo to next message
mgl is currently offline mgl

 
Messages:255
Registered:December 2007
Location: France
But why does it happen on OSX only ??

And the "u" in usGridNo means, in their notation, that the variable is unsigned (i.e can't be negative), no ? I think I would read it as an unsigned integer on 16 bits. How can it be "-1" on OSX ?

I don't know if the types definitions of the game are linked to the SDL ones or not, but if it is the case, there could be an error in the SDL headers on OSX.

Report message to a moderator

Master Sergeant
Re: Crash when going into tactical screen on mine sectors[message #249942] Thu, 22 April 2010 21:57 Go to previous messageGo to next message
bbun is currently offline bbun

 
Messages:74
Registered:April 2004
Location: Amsterdam
I didnt know about the u-prefix for unsigned, but it makes sense. However, such a serious bug would have more effect than just the above issue?

Either way, it seems I'm the only one running stracciatella on OSX here. If someone else does, I would be very interested in their story.

Bottom line: my JA2 runs smoothly now, with some personal modifications and the great 800x600 mod for strac. I am happy Smile

Report message to a moderator

Corporal
Re: Crash when going into tactical screen on mine sectors[message #249949] Thu, 22 April 2010 23:57 Go to previous messageGo to next message
mgl is currently offline mgl

 
Messages:255
Registered:December 2007
Location: France
No, "u" doesn't mean unsigned in this case, "usGridNo" is defined as signed at the beginning of the function "void RecompileLocalMovementCosts(INT16 sCentreGridNo)"
INT16		usGridNo;


While in several other places, it's unsigned, like in:
Build/TileEngine/SaveLoadMap.h: UINT16  usGridNo;
Build/TileEngine/Exit_Grids.h:  UINT16 usGridNo;


After a quick look only, I strongly believe that it's a bug to define "usGridNo" as a signed integer in the "RecompileLocalMovementCosts()" function: The macro on the line before the line you changed returns a gridno value of FFFFh (i.e -1 in a signed 16 bits world) if the coordinates are out of bounds. the unsigned value FFFFh is greater than WORLD_MAX and the test would fail without needing a comparison to -1 if "usGridNo" was unsigned too.

It should not happen on OSX only.

The same thing happens in the function "RecompileLocalMovementCostsFromRadius()", where the code will even use the gridno value of -1 as an index in an array.

It's strange that it had never been noticed.

Report message to a moderator

Master Sergeant
Re: Crash when going into tactical screen on mine sectors[message #249968] Fri, 23 April 2010 07:18 Go to previous messageGo to next message
usrbid is currently offline usrbid

 
Messages:1506
Registered:December 2008
Headrock found some issues in an earlier version of HAM for 1.13 with "invalid" sector IDs, like sector x and y coordinates which don't exist or are out of scope, something along those lines, I don't remember the *exact* details, I just know he found basically bugs which existed since Vanilla.

That's also the reason why I posted here, as you guys may have inherited those bugs and might be able to benefit from talking to Heardock. But then I don't know much about Stracciatella and I could be completely off, in that case please ignore my post. Smile

Report message to a moderator

Sergeant Major

Re: Crash when going into tactical screen on mine sectors[message #250010] Fri, 23 April 2010 14:15 Go to previous messageGo to next message
bbun is currently offline bbun

 
Messages:74
Registered:April 2004
Location: Amsterdam
Interesting finds. Can we come up with a final solution for this? Just redefining usGridNo as unsigned will not solve this, it seems?

Will be very helpful to document this here.

Report message to a moderator

Corporal
Re: Crash when going into tactical screen on mine sectors[message #250039] Fri, 23 April 2010 18:55 Go to previous messageGo to next message
SpaceViking is currently offline SpaceViking

 
Messages:751
Registered:January 2004
Location: Rochester, Minnesota, USA
Dieter
Headrock found some issues in an earlier version of HAM for 1.13 with "invalid" sector IDs, like sector x and y coordinates which don't exist or are out of scope, something along those lines, I don't remember the *exact* details, I just know he found basically bugs which existed since Vanilla.


Those bugs were all over the place. I fixed many of them but doubtlessly there are still a few more. It came from the stupid way they handled sector IDs and sector coordinates.

Report message to a moderator

First Sergeant

Re: Crash when going into tactical screen on mine sectors[message #250170] Sat, 24 April 2010 12:03 Go to previous messageGo to next message
mgl is currently offline mgl

 
Messages:255
Registered:December 2007
Location: France
Thank you, people from 1.13. It promises to be annoying.

@bbun
I changed all the "usGridno" variables involved in a call to the MAPROWCOLTOPOS() macro in this source file to be unsigned, so that the MAPROWCOLTOPOS() macro and the test "if (usGridNo < WORLD_MAX)" are used in the spirit in which they seem to have been originally written. It's not clear why they changed it in some places and there are still some signed gridno variables in that file, but they aren't used with the macro.

Try this instead of your fix, please, because I have never seen this bug myself and can't reproduce it. The crash may be linked to the fact that a signed gridno value of -1 is used as an index to an array, which may violate a memory policy on OSX but not on other OSes.

unsigned_gridno.diff (it's only 3 extra "U"):
Index: Build/TileEngine/WorldDef.cc
===================================================================
--- Build/TileEngine/WorldDef.cc	(revision 7059)
+++ Build/TileEngine/WorldDef.cc	(working copy)
@@ -1067,7 +1067,7 @@
 
 void RecompileLocalMovementCosts( INT16 sCentreGridNo )
 {
-	INT16		usGridNo;
+	UINT16		usGridNo;
 	INT16		sGridX, sGridY;
 	INT16		sCentreGridX, sCentreGridY;
 	INT8		bDirLoop;
@@ -1109,7 +1109,7 @@
 
 void RecompileLocalMovementCostsFromRadius( INT16 sCentreGridNo, INT8 bRadius )
 {
-	INT16		usGridNo;
+	UINT16		usGridNo;
 	INT16		sGridX, sGridY;
 	INT16		sCentreGridX, sCentreGridY;
 	INT8		bDirLoop;
@@ -1204,7 +1204,7 @@
 
 void RecompileLocalMovementCostsInAreaWithFlags( void )
 {
-	INT16		usGridNo;
+	UINT16		usGridNo;
 	INT16		sGridX, sGridY;
 	INT8		bDirLoop;

Report message to a moderator

Master Sergeant
Re: Crash when going into tactical screen on mine sectors[message #250280] Sun, 25 April 2010 16:39 Go to previous messageGo to next message
bbun is currently offline bbun

 
Messages:74
Registered:April 2004
Location: Amsterdam
Thanks for the suggestion, mgl.

I undid my own patch, and tried to crash the game, but "unfortunately", it doesn't crash on me anymore.

I did change all usGridNo into UINT16 though, and assume it a definate fix. If anything happens, I will get back here to keep everyone updated.

Report message to a moderator

Corporal
Re: Crash when going into tactical screen on mine sectors[message #250604] Wed, 28 April 2010 22:48 Go to previous messageGo to next message
bbun is currently offline bbun

 
Messages:74
Registered:April 2004
Location: Amsterdam
So this fix works, but my game crashed again today, entering a sector (meduna airport).

HOWEVER, it seems this is because of a TOTALLY DIFFERENT issue. Would love someone's idea about this.

Stack:

The game crashes in the function
FloorAtGridNo [WorldDef.cc]
called from
LoadRottingCorpsesFromTempCorpseFile [Tactical_Save.cc]
called from
LoadCurrentSectorsInformationFromTempItemsFile [Tactical_Save.cc]

bool FloorAtGridNo(UINT32 const map_idx)
{
	DebugMsg(TOPIC_JA2, DBG_LEVEL_0, String("MAP_IDX: %d", map_idx));
	for (LEVELNODE const* i = gpWorldLevelData[map_idx].pLandHead; i;)
	{
		DebugMsg(TOPIC_JA2, DBG_LEVEL_0, String("i->usIndex: %d", i->usIndex));


The DebugMsg calls are mine. Game crashes between those, so I assume gpWorldLevelData[map_idx].pLandHead causes the Segmentation Fault by faulty access.

This happens for map_idx 25601 => gpWorldLevelData[25601].pLandHead => Crash


Anyone? Idea's?

Report message to a moderator

Corporal
Re: Crash when going into tactical screen on mine sectors[message #250706] Fri, 30 April 2010 01:22 Go to previous messageGo to next message
bbun is currently offline bbun

 
Messages:74
Registered:April 2004
Location: Amsterdam
As I expected, simply validating the range of map_idx solves this. Problem is I don't know what's the maximum. I took the value that crashed my game (25601) to quickfix my version.

What's the theoretical range of this? (equals amount of tiles on a map I assume?)

Temporary fix:

bool FloorAtGridNo(UINT32 const map_idx)
{
	if (map_idx >= 25601) return false;
	for (LEVELNODE const* i = gpWorldLevelData[map_idx].pLandHead; i;)
	{
		if (i->usIndex == NO_TILE) continue;


I wonder what's at the basis of this invalid index...

Report message to a moderator

Corporal
Re: Crash when going into tactical screen on mine sectors[message #250719] Fri, 30 April 2010 10:34 Go to previous messageGo to next message
mgl is currently offline mgl

 
Messages:255
Registered:December 2007
Location: France
I haven't looked at this problem yet, but ...

From What I know, the NODEs are structures, objects, things like floor, roofs, boulders... lying on the tiles (gridnos) of the map. They shouldn't try to scan gridnos greater than WORLD_MAX.

I looked at its value last week for the GridNo bug and I think it's 25600.

I think it would be better if the caller does the "gridno < WORLD_MAX" test itself and calls the function "FloorAtGridNo()" only if the GridNo is valid. The spirit of your current fix is that the function "FloorAtGridNo()" answers that there's no floor on this invalid GridNo (map_idx), not that the GridNo is invalid. And it's not its job to tell that the gridno is invalid. The GridNo should have been acknowledged as invalid earlier in the caller's code and the caller shouldn't try to do anything with it.

Report message to a moderator

Master Sergeant
Re: Crash when going into tactical screen on mine sectors[message #250723] Fri, 30 April 2010 12:28 Go to previous messageGo to next message
mgl is currently offline mgl

 
Messages:255
Registered:December 2007
Location: France
The function "FindNearestAvailableGridNoForCorpse()" in 'Build/Tactical/Tactical_Save.cc' returns a gridno or the value "NOWHERE" (= WORLD_MAX + 1) if it can't find one.

Its caller, the function "LoadRottingCorpsesFromTempCorpseFile()", which is the caller of the function "FloorAtGridNo()" too, has a comment which says that they will force their way through the code to the function which adds a corpse on the map despise an invalid gridno because that function could do interesting things with it anyway. Indeed, if that function sees "NOWHERE" as a gridno, it returns immediately!

This is the change I suggest:
Index: Build/Tactical/Tactical_Save.cc
===================================================================
--- Build/Tactical/Tactical_Save.cc	(revision 7059)
+++ Build/Tactical/Tactical_Save.cc	(working copy)
@@ -720,9 +720,19 @@
 			def.sGridNo = FindNearestAvailableGridNoForCorpse(&def, 5);
 			if (def.sGridNo == NOWHERE)
 				def.sGridNo = FindNearestAvailableGridNoForCorpse(&def, 15);
-			/* ATE: Here we still could have a bad location, but send in NOWHERE to
-			 * corpse function anyway, 'cause it will iwth not drop it or use a map
-			 * edgepoint */
+				/* ATE: Here we still could have a bad location, but send in NOWHERE to
+				 * corpse function anyway, 'cause it will iwth not drop it or use a map
+				 * edgepoint */
+
+				/* 2010-04-29:
+				 * The corpse func does nothing from NOWHERE.
+				 * No need to force our way to it as the
+				 * comment above suggests.
+				 * NOWHERE is (WORLD_MAX + 1), and would
+				 * fail the next test but I leave this line
+				 * for clarity.
+				 */
+				if (def.sGridNo == NOWHERE) { continue; }
 		}
 		else if (def.usFlags & ROTTING_CORPSE_USE_NORTH_ENTRY_POINT)
 		{
@@ -741,6 +751,9 @@
 			def.sGridNo = gMapInformation.sWestGridNo;
 		}
 
+		/* 2010-04-29: Don't add a corpse on an invalid gridno */
+		if (def.sGridNo >= WORLD_MAX || def.sGridNo < 0)  { continue; }
+
 		/* ATE: Don't place corpses if not loading a savegame, in town, indoors and
 		 * the corpse is too old */
 		if (maybe_dont_add &&

I have added a line to stop trying to add a corpse on a "NOWHERE" gridno value and, later, a general check on the gridno obtained from the savegame or from the map north/south/east/west entry points because I don't trust them. Since the gridno is signed in this file, it needs to be compared to 0 as well as the usual WORLD_MAX.

The way the gridnos are managed is really confusing: sometimes signed, sometimes not, sometimes on 16 bits, sometimes on 32... A general function to check the validity of a gridno would be welcome.

Edit: You are in the NOWHERE case, bbun. No suitable gridno was found on a radius of 15 tiles around the original location chosen for the corpse. How can it be possible ?

Report message to a moderator

Master Sergeant
Re: Crash when going into tactical screen on mine sectors[message #250727] Fri, 30 April 2010 14:20 Go to previous messageGo to next message
bbun is currently offline bbun

 
Messages:74
Registered:April 2004
Location: Amsterdam
I can confirm your suggestion fixes the issue, mgl. Thanks for that.
The inconsistency of gridno's is terrible indeed... Smile

We're getting to a point where we should really manage code in a repository again.

This is the 3rd bugfix on top of r7059. Either we ask Tron for write access on the repository, or we create a new one in something like Google Code.


BTW: Nowhere case: I have no idea how I got there. It's sector N5, meduna aiport. Last enemy encounter I stacked around 12 bodies in the same spot (!!), a doorway, which may have caused this...?

[Updated on: Fri, 30 April 2010 14:27] by Moderator

Report message to a moderator

Corporal
Re: Crash when going into tactical screen on mine sectors[message #250742] Fri, 30 April 2010 19:31 Go to previous messageGo to next message
mgl is currently offline mgl

 
Messages:255
Registered:December 2007
Location: France
bbun
We're getting to a point where we should really manage code in a repository again.

This is the 3rd bugfix on top of r7059. Either we ask Tron for write access on the repository, or we create a new one in something like Google Code.

3 bugs fixed in 5 months isn't that impressive. Tron fixes more of them while sleeping!

I sent an email to him, but I don't know if he will even answer. I haven't mailed him since october I think.

I'm not very interested in maintaining a fork of stracciatella myself.


bbun
BTW: Nowhere case: I have no idea how I got there. It's sector N5, meduna aiport. Last enemy encounter I stacked around 12 bodies in the same spot (!!), a doorway, which may have caused this...?

I don't know but I have never done that.


Edit:
Hey, someone edited my profile to show my badges and added one!!
What's that skull ?

[Updated on: Fri, 30 April 2010 19:45] by Moderator

Report message to a moderator

Master Sergeant
Re: Crash when going into tactical screen on mine sectors[message #250744] Fri, 30 April 2010 20:13 Go to previous messageGo to next message
bbun is currently offline bbun

 
Messages:74
Registered:April 2004
Location: Amsterdam
mgl
bbun
We're getting to a point where we should really manage code in a repository again.

This is the 3rd bugfix on top of r7059. Either we ask Tron for write access on the repository, or we create a new one in something like Google Code.

3 bugs fixed in 5 months isn't that impressive. Tron fixes more of them while sleeping!

I sent an email to him, but I don't know if he will even answer. I haven't mailed him since october I think.

I'm not very interested in maintaining a fork of stracciatella myself.


Agree. Just committing the 3 fixes to the existing repo would be ideal.

Report message to a moderator

Corporal
Re: Crash when going into tactical screen on mine sectors[message #250944] Tue, 04 May 2010 10:47 Go to previous messageGo to next message
Tron

 
Messages:225
Registered:August 2007
Location: Germany
Please provide a savegame, which demonstrates this problem.

Report message to a moderator

Sergeant 1st Class
Re: Crash when going into tactical screen on mine sectors[message #250949] Tue, 04 May 2010 13:28 Go to previous messageGo to next message
bbun is currently offline bbun

 
Messages:74
Registered:April 2004
Location: Amsterdam
Tron, first of all: great to see you around, and thanks so much for all your work on Stracciatella!

Secondly: I just overwrote my savegame last night (!) when starting a new game Sad Can't believe the timing. Sorry. I can only say that this fix solved it.

(BTW there are 2 bugs & fixes in this thread, I assume you saw this)

Report message to a moderator

Corporal
Re: Crash when going into tactical screen on mine sectors[message #250967] Wed, 05 May 2010 00:08 Go to previous messageGo to next message
mgl is currently offline mgl

 
Messages:255
Registered:December 2007
Location: France
I looked (here) at what the 1.13 team did with the "MAPROWCOLTOPOS()" and its use in the function "RecompileLocalMovementCosts()" from the file 'WorldDef.cpp' when they compare it to WORLD_MAX. They have exactly the same bug ported to 32 bits instead of 16 in stracciatella.

"MAPROWCOLS()" return the hexadecimal "FF.FF.FF.FF" value as an invalid gridno id.
Store this in an UINT32 and it's the biggest possible number. It's bigger than WORLD_MAX and the test fails as expected.
Store it in an INT32 and it reads "-1" (2's complement arithmetic). It's lesser than WORLD_MAX and passes the test successfully instead of failing.

Unless I'm losing my mind, don't use signed variables in a macro call which returns hexadecimal values. If its author had wanted to return -1, he would have written it as "-1", not as "FF.FF" on 16 bits or "FF.FF.FF.FF" on 32 bits. The only exception would be if the macro returned "7F.FF" on 16 bits and "7F.FF.FF.FF": the highest possible positive value.

Report message to a moderator

Master Sergeant
Re: Crash when going into tactical screen on mine sectors[message #250983] Wed, 05 May 2010 13:49 Go to previous message
Helios is currently offline Helios

 
Messages:25
Registered:April 2010

mgl check your messages under 'my stuff' when you have the time

Report message to a moderator

Private 1st Class
Previous Topic: Bus Error @ Tactical screen
Next Topic: Bug: looking for enemies in adjacent sectors
Goto Forum:
  


Current Time: Sat Jan 25 20:01:00 GMT+2 2025

Total time taken to generate the page: 0.01331 seconds