Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dividing by Zero in line function causes Tic-80 to crash. #1282

Closed
12buntu opened this issue Dec 28, 2020 · 5 comments
Closed

Dividing by Zero in line function causes Tic-80 to crash. #1282

12buntu opened this issue Dec 28, 2020 · 5 comments
Assignees
Labels

Comments

@12buntu
Copy link

12buntu commented Dec 28, 2020

The below code causes Tic-80 to completely crash, and in some cases it even slowed down the rest of my computer. I understand dividing by zero is impossible, but in other functions (namely print), it only throws an error.

Note: I originally discovered the problem in Wren, but discovered it also applied when using Lua, I assume it also applies in other languages.

function TIC()
    line(x/0,y0,x1,y1,color)	
end
@nesbox
Copy link
Owner

nesbox commented Dec 28, 2020

I tried to reproduce it on Windows without success, I suppose you are using Linux?

@nesbox nesbox added the bug label Dec 28, 2020
@RobLoach
Copy link
Contributor

Did some debugging. Found that when line() is passed an inf, it thinks heavily about it for a while. It doesn't crash, but does seem like it does, at least on Linux. Here is a demo case...

Screenshot at 2020-12-28 03-53-02

-- title:  game title
-- author: game developer
-- desc:   short description
-- script: lua

specialValue = 10
x = 10
instructions = "Press/hold UP to see the line"

function TIC()
	cls()
	print(instructions, math.sin(x / 50) * 50 + 50, 0)
	print("Special Value: " .. specialValue, 10, 20)
	x = x + 1

	if btn(0) then
		line(specialValue, 10, 20, 20, 13)
		print("Up is pressed!", 20, 100)
		instructions = "Press DOWN to set\n special value to 500 / 0"
	end

	if btn(1) then
		-- Set special value to inf
		specialValue = 500 / 0
		instructions = "Press UP again to use inf in line()"
	end
end

@12buntu
Copy link
Author

12buntu commented Dec 29, 2020

I tried to reproduce it on Windows without success, I suppose you are using Linux?

Yes, I am

@superogue
Copy link

i have had issues in other places with dividing by zero, so i had to add small float value to work around it.

@nesbox nesbox self-assigned this Apr 29, 2021
@nesbox
Copy link
Owner

nesbox commented Apr 29, 2021

I did a little research, and agreed with @RobLoach x / 0 == INF, which became -2147483648 inside TIC,
after that, it tries to draw a very large line with line parameters (-2147483648, y0, x1, y1, color).
I think this is not a crash or a bug, this is normal behavior, you can even hold down ESC and exit the program.
WONTFIX

@nesbox nesbox closed this as completed Apr 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants