463 posts
Location
Germany
Posted 18 March 2013 - 02:10 AM
I discovered a bug of CC when running this program:
function test()
r=0
while true do
r=r+1
end
end
a, b = pcall(test)
print(r)
It gives me the following error:
Error resuming bios.lua
Check you have installed ComputerCraft correctly.
and then after about 0.01 seconds, the computer screen gets black. (I only could read that message by recording the screen with a ScreenCapture Program (for Windows, not for CC))
But I think I installed ComputerCraft correctly, because Im using a mod pack for a server…
EDIT: And it can't be a program bug, because I ran the test function in pcall, and if its an program bug, it wouldn't crash the whole computer
2088 posts
Location
South Africa
Posted 18 March 2013 - 04:54 AM
What happens if you add a sleep(1) after r=r+1
463 posts
Location
Germany
Posted 18 March 2013 - 05:31 AM
then nothing happens… (and it also takes about 5 secs that the message comes in the program without sleep(1), so thats like the "cannot resume bios.lua" error is fired instead of "Too long without yielding")
But I made this "program" for testing how long it takes that the too long without yieldin error comes, and compare r with a result from a other pc…
EDIT: When I terminated the program, there was a "437" instead of "Terminated."… This bug seems to be really odd
EDIT2: Tried in CCEmu now, same problem there.
[indent=1]BUT: I fixed it. There's no problem with the code, but I added an function that writes the number in a file, that I can see "r" independent of a computer crash. BTW: r is between 2000 and 2700 with me :)/> (used CCEmu)[/indent]
[indent=1]New code:[/indent]
function wr(txt)
w=fs.open("tlog", "w")
w.writeLine(tostring(txt))
w.close()
end
function test()
r=0
while true do
wr(r)
r=r+1
end
end
a, b=pcall(test)
print(r)[/indent]
1604 posts
Posted 18 March 2013 - 06:58 AM
It's not a bug, it's just that you never yield in the loop, so it causes an error. Now, the way the "too long without yielding" works is that the api functions (the java ones), throw the error if the computer hasn't yielded in some time. So, if you don't call any api functions, there's no way to throw the error, and this happens.
463 posts
Location
Germany
Posted 18 March 2013 - 07:02 AM
It's not a bug, it's just that you never yield in the loop, so it causes an error. Now, the way the "too long without yielding" works is that the api functions (the java ones), throw the error if the computer hasn't yielded in some time. So, if you don't call any api functions, there's no way to throw the error, and this happens.
Ah thanks :)/>
I think this thread can now be locked.
2447 posts
Posted 18 March 2013 - 07:03 AM
Nah, we throw it Java side now. If you catch the error it will die anyway, just not nicely.
2088 posts
Location
South Africa
Posted 18 March 2013 - 07:13 AM
I got r as these for 3 tests xD
1802
2788
2814
What's up with the first one being so out?
463 posts
Location
Germany
Posted 18 March 2013 - 07:38 AM
I got r as these for 3 tests xD
1802
2788
2814
What's up with the first one being so out?
Don't know… But with me it was soo too :D/>
EDIT: WOW got 6245 now!!! :D/>