findPath crash me

17 views
Skip to first unread message

Gaël Roussel

unread,
Dec 7, 2015, 12:21:13 AM12/7/15
to HaxeFlixel
Hello everybody,

I've got a little problem with the findPath function.
I do a mix of two tutorials (one from this site, and the second on haxecoder) and the second one use CSV instead Ogmo and use a findPath when we click.
But when i click, the game crash, nice.


The probleme is on the 86th line : "var nodes:Array<FlxPoint> = _mWalls.findPath(FlxPoint.get(_player.x + 16 / 2, _player.y + 16 / 2), FlxPoint.get(tileCoordX * 16 + 16 / 2, tileCoordY * 16 + 16 / 2));"


If anybody know what happend, i'm still here haha.

Thanks :)

Jeru Sanders

unread,
Dec 7, 2015, 3:18:40 PM12/7/15
to haxef...@googlegroups.com
You should trace the FlxPoint, it's likely pointing to a tile set to a negative number or 0. You can't path over those tiles.
You also might attempt to set the tile properties on whatever tile's are causing the error via setTileProperties().

Also that usage of FlxPoint.get() causes memory to leak. You're meant to use FlxPoint.put() when the point is done being used so it's recycled for future uses of FlxPoint.get(). If there are no more point in the pool then a new one is generated.
var a:FlxPoint = FlxPoint.get();
// Doing stuff with a
a
.put();
This avoids the overhead from allocating memory with "new FlxPoint()", but if you must write your code that compact then I recommend you use "new FlxPoint()" anyways to avoid clogging up the pool.
compactFunction(new FlxPoint(0, 0)); // Not optimal, but doesn't destroy the pool.
Reply all
Reply to author
Forward
0 new messages