Jump to content




Stack overflow


4 replies to this topic

#1 Vattic

  • Members
  • 3 posts
  • LocationUK

Posted 17 May 2013 - 10:04 PM

The acctual error message:
main2:254: vm error: java.lang.ArrayIndexOutOfBoundsException: 256

I've not had much experience with CC before now and I'm a hobbiest programmer at best. I can't figure out what I'm doing wrong. Would anyone mind having a look for me? I know it's a bit messy in places and that there is a fair bit of it, but I'd really appreciate some help.

Lines 254 - 256 are in the checkIfFull() function which is supposed to loop through all the inventory slots that aren't being used for identifying unwanted blocks (dirt, stone, sand, gravel) and tell if they contain items. If they all do it'll place an ender chest and deposit them.

The Code:
Spoiler

Cheers,

#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 18 May 2013 - 12:37 AM

Split into new topic.

#3 tesla1889

  • Members
  • 351 posts
  • LocationSt. Petersburg

Posted 18 May 2013 - 01:32 AM

idk if you still care about this, but this could have to do with the number of global variables you are declaring. because this isn't an API file, i suggest trying it with local functions. anything to cut down on stack usage is a good thing in this case

in case you're wondering, when lua defines a new function, it pushes a string and a function to the stack before setting the string as an index in the environment to the function, sort of like this:

.const 'checkIfFull'
.function
; define checkIfFull function
.end
push 0 ; push the first constant to the stack
push 1 ; push the function to the stack
setglobal 1 0 ; set the function as a global

if you get a whole bunch of functions, the stack can get really big

#4 BigSHinyToys

  • Members
  • 1,001 posts

Posted 18 May 2013 - 03:28 AM

I would say localizing the functions / variables is a good practice but that still docent explain this error I heard soothing like this was a but and that selecting the slot before getting its content is a workaround or try the latest beta. I am using the beta and this seams to run fine.

#5 Vattic

  • Members
  • 3 posts
  • LocationUK

Posted 18 May 2013 - 08:08 AM

It turns out I missed something that should have been obvious because of how messy my code is. I have it checking if the inventory is full before each time it digs, when it is full it tries to dig out the space above it to place an ender chest, when it tries to dig it checks to see if the inventory is full. This goes around and around until it fills the stack.

View Posttesla1889, on 18 May 2013 - 01:32 AM, said:

idk if you still care about this, but this could have to do with the number of global variables you are declaring. because this isn't an API file, i suggest trying it with local functions. anything to cut down on stack usage is a good thing in this case

in case you're wondering, when lua defines a new function, it pushes a string and a function to the stack before setting the string as an index in the environment to the function, sort of like this:

.const 'checkIfFull'
.function
; define checkIfFull function
.end
push 0 ; push the first constant to the stack
push 1 ; push the function to the stack
setglobal 1 0 ; set the function as a global

if you get a whole bunch of functions, the stack can get really big
I'm going to have to look into local functions again. I only read about it breifly and had problems getting local functions calling eachother. Would it not require a large rework of what I've already got?

View PostBigSHinyToys, on 18 May 2013 - 03:28 AM, said:

I would say localizing the functions / variables is a good practice but that still docent explain this error I heard soothing like this was a but and that selecting the slot before getting its content is a workaround or try the latest beta. I am using the beta and this seams to run fine.
I forgot to mention that you have to let it fill with ores before the problem appears. I'd imagine this would be the same with the beta too.

Cheers for your help guys,





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users