Page 1 of 1

Anonymous Inline Valuator Function Crash

Posted: 13 Jun 2008 18:16
by Zutty
Hi guys. Another crash report for you.

If I use an anonymous inline function to describe a valuator the game crashes. The code I used is as follows..

Code: Select all

	...
	// Get a list of tiles to search in
	local searchRadius = 10;
	local tileList = AITileList();
	tileList.AddRectangle(townTile - AIMap.GetTileIndex(searchRadius, searchRadius)
				, townTile + AIMap.GetTileIndex(searchRadius, searchRadius));
	
	// Rank those tiles by their suitability for a station
	local radius = AIStation.GetCoverageRadius(AIStation.STATION_BUS_STOP);
	tileList.Valuate(function (_tile, _town, _cargo, _radius) {
		local sl = AITile.GetSlope(_tile);
		local level = (sl == AITile.SLOPE_FLAT || sl == AITile.SLOPE_NWS
				|| sl == AITile.SLOPE_WSE || sl == AITile.SLOPE_SEN || sl == AITile.SLOPE_ENW);
		local acceptable = AITile.IsBuildable(_tile) && !AIRoad.IsRoadTile(_tile) 
				&& (AIRoad.GetNeighbourRoadCount(_tile) > 0) 
				&& AITown.IsWithinTownInfluence(_town, _tile) && level;
		local acceptance = AITile.GetCargoAcceptance(_tile, _cargo, 1, 1, _radius);
		return (acceptable) ? acceptance : 0;
	}, town, paxCargo, radius);
	tileList.RemoveBelowValue(8);
	...
The attached screenshot (1680x1050) shows the crash. The text in the box is here...

Code: Select all

Problem signature:
  Problem Event Name:	APPCRASH
  Application Name:	openttd.exe
  Application Version:	0.7.0.13487
  Application Timestamp:	48514871
  Fault Module Name:	StackHash_f3b5
  Fault Module Version:	0.0.0.0
  Fault Module Timestamp:	00000000
  Exception Code:	c0000005
  Exception Offset:	1bab0cab
  OS Version:	6.0.6001.2.1.0.768.3
  Locale ID:	2057
  Additional Information 1:	f3b5
  Additional Information 2:	67157acfc10691bf1c01accd62406c5a
  Additional Information 3:	b4f4
  Additional Information 4:	686b80d14c6be7494511e7ba36846343

Read our privacy statement:
  http://go.microsoft.com/fwlink/?linkid=50163&clcid=0x0409
 
All functions in Squirrel are higher order so this should work. For instance, the following works perfectly...

Code: Select all

local arr = [7,4,9,2,3];
arr.sort(function (a, b) {
    return (a > b) ? -1 : ((a < b) ? 1 : 0);
});
But even if it was unsupported I would expect to get an error rather than have the game crash.

Do you need any more info to look into this? How do I get a crash report? Plus if you want me to log this on Flyspray just say so.

Thanks guys :)

Re: Anonymous Inline Valuator Function Crash

Posted: 13 Jun 2008 19:58
by TrueBrain
Fixed in latest revision. In nightlies which compile in 20 hours (long wait ;)).

The problem was that the garbage collector kicked in before we were done using the lambda-function ;) That should be fixed now, together with other potential (equal) problems.

Re: Anonymous Inline Valuator Function Crash

Posted: 13 Jun 2008 20:17
by Zutty
TrueLight wrote:Fixed in latest revision. In nightlies which compile in 20 hours (long wait ;)).

The problem was that the garbage collector kicked in before we were done using the lambda-function ;) That should be fixed now, together with other potential (equal) problems.
That was bloody quick!! :D

Thanks TrueLight.

Re: Anonymous Inline Valuator Function Crash

Posted: 13 Jun 2008 20:21
by TrueBrain
You ask, we compile :)

Or in this case:

You ask, we compile, find a problem, debug, solve one part, find an other problem, debug again, get inconsistent results, runs tons of checks, debugs internals you don't want to know about, gets crazy, debugs again, find a possible solution, complete failure, restarts from scratch, looks again, finds nothing, has an idea, finds a problem, adds some lines on several places, solves solution, compiles, runs regression, tests, looks over diff, checks again, makes sure everything is consistent, commits, and posts a forum post :p