Jump to content




java.lang.ArrayIndexOutOfBoundsException: 256


  • You cannot reply to this topic
4 replies to this topic

#1 X3ME

  • Members
  • 82 posts
  • LocationBeing the stereotypical kid in forums.

Posted 12 November 2016 - 07:14 PM

Hey guys, I made a quick program in 10 minutes. It works for a good time until eventually it gets this error:

"bios:139: vm error:
java.lang.ArrayIndexOutOfBoundsException :256"

Here is the pastebin: http://pastebin.com/VPt847nS

any help would be greatly appreciated!

#2 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 12 November 2016 - 07:21 PM

Looks like you're using recursion. Stop using recursion.

countdown calls itself repeatedly. Use a loop instead.

countdown calls disaster. disaster calls countdown. Use a loop instead.

display calls itself repeatedly. Use a loop instead.

terminal calls itself repeatedly. Use a loop instead.

#3 jakejakey

  • Members
  • 98 posts

Posted 12 November 2016 - 08:21 PM

What I understand is that this is a countdown program that sounds an alarm through a redstone port after a certain amount of time?

#4 Bomb Bloke

    Hobbyist Coder

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

Posted 12 November 2016 - 11:47 PM

To be more specific, when a function calls a function, the first isn't necessarily removed from the function stack - it usually stays there, so that when the second function finishes (and returns), the first can carry on from where it left off. The idea is that whatever function is on top of the stack is active - new functions get piled on top, and as they complete, they get removed.

If you never allow your functions to return, but instead have them continue to call fresh instances of themselves over and over again, eventually Lua runs out of the memory reserved for such shenanigans and the function stack overflows. In the case of LuaJ (used by ComputerCraft), this leads to the precise error you're getting.

For eg, this sort of thing:

Spoiler

... could be re-written like this:

Spoiler


#5 X3ME

  • Members
  • 82 posts
  • LocationBeing the stereotypical kid in forums.

Posted 12 November 2016 - 11:51 PM

Thanks guys! I have read up a bit more on this exact error and why it was occuring to me. Didn't know the function / memory usage worked this way, glad I got to learn before making this mistake again! Thanks once again!





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users