Jump to content




[1.58] Computer crashes at certain point - no error.


2 replies to this topic

#1 Lamdax

  • Members
  • 4 posts

Posted 24 October 2014 - 11:45 PM

Hi,

I have recently started writing quite a large program for my reactor (basically gets your energy cells, RF/t output, etc and places it on a monitor).

Problem is, as soon as it gets to the point where it has to write data to the monitor, it pauses for a moment and then shuts down the computer. If I restart the computer, same thing happens.
I have set up a few 'debugging' prints where major events happen, and it seems to stall at 'displayInfo()'. It doesn't run the function, as one of the first things in 'displayInfo()' is a print, and it doesn't actually print anything so the problem occurs either:

1. Before the program runs displayInfo(), but after the print saying that displayInfo() is running (unlikely),
2. After displayInfo() is called, but before the print inside displayInfo() (maybe).

I have a hunch that it is some kind of memory error (which is likely, I'm not very good with Lua and I probably have a memory leak somewhere).

Here is the code, and also my computer output so you can see where it stalls:

CODE:
Spoiler

OUTPUT:
Spoiler

I hope I can get an answer soon (I'm guessing it will be about shortening my code).

Thank you in advance for your help, CC community!

#2 Dragon53535

  • Members
  • 973 posts
  • LocationIn the Matrix

Posted 25 October 2014 - 12:35 AM

While looking through your code (haven't found your error just yet)
while remainTimeSeconds >= 60 do
if remainTimeMinutes >= 59 then
remainTimeMinutes = 0
remainTimeHours = remainTimeHours + 1
else
remainTimeMinutes = remainTimeMinutes + 1
end
remainTimeSeconds = math.floor(remainTimeSeconds - 60)
end
You can easily use the modulus operator.
local sec = 122 --#Just to show

local min = math.floor(sec/60) --#This will be 2.

sec = sec % 60 --# This divides by 60, however the remainder is set as sec, not the actual quotient. So sec is now 2 since 122 / 60 has a 2 remainder.

Will edit post when i do find answer though :D

EDIT: Your getTimeToRefill function, add a print to see if that finishes, as i suspect the error may be in there.

Edited by Dragon53535, 25 October 2014 - 12:41 AM.


#3 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 25 October 2014 - 02:13 AM

I agree with Dragon; my best guess is that getTimeToRefill function. That loop he pointed out, specifically.

If a system fails to yield for an extended period (typically about ten seconds), ComputerCraft will attempt to crash the script. Sometimes it's unable to make it "error out", and so it instead crashes the whole computer.

So my assumption is that it's taking too long to get through that rather inefficient loop (after doing everything else leading up to it since whenever the last yield was). It wouldn't surprise me if implementing a couple of modulus operations in its place fixes the issue.

By the way, you seem to be using math.floor() an awful lot more often than you need to. For example, in the aforementioned loop, better to make sure remainTimeSeconds is an integral number before it even starts instead of repeating redundant math.floor() calls inside it.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users