Page 1 of 1
[SOLVED] Jumper exception thrown not expected
Posted: Sun Dec 25, 2016 5:37 pm
by nyenye
First of all I've created a new thread, because Jumper's thread isn't active since 2009...
Now the exception that I get is as follows
- Screenshot from 2016-12-25 18-27-55.png (27.08 KiB) Viewed 5911 times
and at line 330 we find:
- Screenshot from 2016-12-25 18-29-11.png (144.02 KiB) Viewed 5911 times
The thing is that the map that I pass on is correctly formated. See map.txt
- map.txt
- (1.93 KiB) Downloaded 155 times
Re: Jumper exception thrown not expected
Posted: Sun Dec 25, 2016 5:40 pm
by nyenye
Sorry about repost, but couldn't attach game.love on the same entry, dunno why though.
Re: Jumper exception thrown not expected
Posted: Sun Dec 25, 2016 10:33 pm
by Zeliarden
math.floor or ceil the input coordinates will fix the problem
Code: Select all
assert(startNode, ('Invalid location [%d, %d]'):format(startX, startY))
outputs the integer (12,12) value of startX, startY instead of the real value (12.5, 12.5 or something like that)
Re: Jumper exception thrown not expected
Posted: Mon Dec 26, 2016 5:55 am
by raidho36
Doesn't that generates strings every time this functions is called? Because all (assert) function arguments are evaluated before it is called. That's hugely wasteful.
Re: Jumper exception thrown not expected
Posted: Mon Dec 26, 2016 8:27 am
by Positive07
Yes it does, assert is a really inefficient function since the string is evaluated regardless of being valid or not... I usually use simple checks
Code: Select all
if not startNode then
error(('Invalid location [%d, %d]'):format(startX, startY), 1)
end
Which also lets you specify the start depth of the stack traceback
Re: Jumper exception thrown not expected
Posted: Mon Dec 26, 2016 4:42 pm
by nyenye
Thanks for the tips, I'll give it a shot. About the performance problem, I thought that Jumper was the standard library for pathfinding in Lua/Love2D. Do you have any other recomendation? Or do you make your own implementation?
Re: Jumper exception thrown not expected
Posted: Mon Dec 26, 2016 5:30 pm
by raidho36
There's no "standard" anything in Lua, because it's a "there are many ways to do this" kind of language. But sure enough, generating strings in asserts will slow things down substantially for no reason. Not only creating an unique string is not a fast operation, but also the result is immediately discarded and becomes garbage thus contributing to runtime overhead, and all of that on top of never needing to do any of it in the first place.
Re: Jumper exception thrown not expected
Posted: Tue Dec 27, 2016 1:32 pm
by nyenye
raidho36 wrote:There's no "standard" anything in Lua...
Thanks for the info. Then do you have any "better" or different implementation for Pathfinding? Or maybe just change the code of the library to do what Positive07 said?
Re: [SOLVED] Jumper exception thrown not expected
Posted: Tue Dec 27, 2016 4:38 pm
by raidho36
I don't have anything in my sights, so yes you could just replace wasteful asserts with less intensive checks, or even remove them altogether since they serve no practical function and only exist to assist debugging.