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

NullPointerException

Started by delusionallogic, 15 May 2012 - 08:58 PM
delusionallogic #1
Posted 15 May 2012 - 10:58 PM
Computercraft doesn't seem to like it when i try to use infinite while loops in parallel functions.

Simplified code:

running = true
function threadOne()
	while running do
		--Logic here
	end
end
function threadTwo()
	while running
		--logic here
	end
end
parallel.waitForAny(threadOne, threadTwo)

it runs for a few seconds, then it crashes with a JVM NullPointerException error
MysticT #2
Posted 15 May 2012 - 11:04 PM
There should be no problem with doing that, maybe it's another part of the code wich cause it. I use coroutines (like parallel) a lot all of them running in an infinite loop (I had almost 30 running) and never crashed.
delusionallogic #3
Posted 16 May 2012 - 03:57 PM
Turns out that not having a sleep/processing made one of the functions hog all the emulator time, causing in NullPointer from the other threads.
kazagistar #4
Posted 11 June 2012 - 02:06 AM
Parallel is just a wrapper around coprocess. You need to call a function that internally does a yield, such as a pull, sleep, queue, or just an interface command, in order to not freeze the processor.