aardappel / lobster

The Lobster Programming Language

Home Page:http://strlen.com/lobster

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Shooter tutorial fails at Step 3

sgraham opened this issue · comments

I was just following http://aardappel.github.io/lobster/shooter_tutorial.html to get a feel for Lobster and noticed that on "Step 3" it doesn't match the desired output (the "ship" disappears).

Taking this as an opportunity to see how debugging would go :) I believe it's because when no WASD is pressed dir is a zero-vec which normalize then turns into NaNs.

It looks like this might have broken fairly recently in b9e79da#diff-7cc745b151e18e0112b4f542bc3566974bacb4448af236d24c7a50ecab856a83R706 as previously a zero-length vector was maintained by normalize.

Not sure if it makes sense for normalize to special case 0... I guess the tutorial code should probably check instead. (A debugging mode that panics on NaNs might be a nice wishlist thing too. :)

Wow, nice you found the root cause!

In the past, Lobster was a more high level language than today, and this special casing made sense.
It is a good question what really it should be doing ideally.
If you do an actual scalar divide by zero, you get a runtime error... certainly I don't think a NaN here is desirable.
So it may make sense that normalize should follow this pattern and runtime error, forcing the programmer to check.

That said, for vector ops, Lobster tries to follow glsl where possible, and there implementations just return a zero vector. That is kind of useful, as you see here.
The reason the scalar divide doesn't just give a zero result is because it may mask bugs, and it is not clear that zero would be a good default anyway (infinity makes more sense), but in the case of normalize, which is used typically for graphics, a zero vector (or color) actually is likely much more helpful.

So I'd vote to keep the previous behavior :)
Do you want to make a PR, since you found it?