This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
jv110's profile picture

VertexGL crash related to Z values

Started by jv110, 23 May 2016 - 04:40 PM
jv110 #1
Posted 23 May 2016 - 06:40 PM
It simply crashes when rendering, but if I add some number to the Z, it renders (farther, of course).

It already checks if the Z is 0. I really don't understand why it's happening.

https://github.com/jv110/VertexGL
SquidDev #2
Posted 23 May 2016 - 07:11 PM
When you say crashes do you mean times out (screen goes back, computer has to be restarted/too long without yielding error)?

At a guess this is because z is a very small value (such as 1x10-9). As a result, when you divide by w you get a very large number. This means you might be rendering a triangle from -1x106 to 1x106 which takes a long time and times out the computer.

Instead you can clip the coordinates so the triangle stops on the boundary of the screen. Check each axis is between -w and w and, if it isn't, interpolate between two points on the triangle/line to ensure it is.
Edited on 23 May 2016 - 05:11 PM
jv110 #3
Posted 23 May 2016 - 07:37 PM
Nope. The screen just goes black without any error.
Bomb Bloke #4
Posted 24 May 2016 - 02:08 AM
When a computer/turtle starts running code, ComputerCraft starts a ten second timer. If that code doesn't yield before that timer ends then ComputerCraft will either crash the script or the whole computer (depending on the nature of the functions your script is calling). After each yield, any other systems waiting to run code may do so, then after they've all yielded, processing continues with a new time limit.

The reason why is that running your code chews up valuable server processing power, and so it shouldn't be able to monopolise it. In fact, only ONE CC device can run code at a time: While one is doing something, none of the others can do anything until it yields.

Whether or not it takes more than ten seconds for your code to execute has a little to do with the power of the Minecraft server it's running on, and a lot to do with how often you allow your code to yield. Pulling events (eg getting typed characters or checking timers) triggers a yield, and many commands (eg turtle movements, sleeping, or getting text input from the user) have to pull events to work anyway. Basically, anything that triggers a pause is pulling an event in order to do it, and in order to pull an event the code yields.

In short, if you try to crunch too many numbers without yielding, your computer may turn off.
jv110 #5
Posted 24 May 2016 - 11:15 AM
I can't use my computer until about 8h from now, can someone try it for me?