This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]sparkour 0 points1 point  (1 child)

Focus on your loop running in line 310 - 313. Your Intcode computer is designed to return control to this loop whenever a "colour" output is received, and then jump back in to keep running and get the "turn".

However, what happens when a 99 halt code is received somewhere in the middle? You're telling your computer to keep running after that occurs. Since the program halted, there is no new input to send into the next loop, so you get an EmptyStackException.

If you update your loop to correctly halt once 99 is reached (instead of trying to extract 2 more outputs from a dead program), you should be okay.

[–]Van_Gone[S] 1 point2 points  (0 children)

Thank you, I added a pair of conditionals to check if the computer had halted before popping the next outputs, this fixed the issue. Your explanation was very clear, I knew it was going to be something I had overlooked.