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

Java Error in my Lua Program!?

Started by jaffacakesareamazing, 07 June 2014 - 10:25 AM
jaffacakesareamazing #1
Posted 07 June 2014 - 12:25 PM
I have modified the chat program slightly to act as a real life system that is like iMessage. (I DO NOT PLAN ON DISTRIBUTING THE CODE AS THIS IS COPYRIGHT BREAKING) I have added a signal bar at the top like any phone and also a wifi bar for when near wifi networks (the user needs to connect to them first in a different program) and it seems to work fine until a Java error appears, breaking/stopping the program!

I have downloaded a big city map to run this whole 'internet' system in and the error seems to be happening when the chat program is 'supposedly' out of range of a transmitter/computer (i have the main chat server in the center and repeaters going around nearly the whole map) and the signal bar updates automatically as you move around. If you are out of range of a repeater/transmitter the program will not allow you to send/receive any messages.

However a Java error appears randomly I think, it displays this:

window: 277: vm error: java.lang.ArrayIndexOutOfBoundsException

and then it just disconnects. When I then try and connect again, it just constantly searches for a transmitter(computer) to connect to (even if you go and stand right next to one!) Can anyone help with this error? Thanks :)/>
theoriginalbit #2
Posted 07 June 2014 - 12:32 PM
If you had of read the Read This Before Asking Questions sticky thread you'd have noticed that this error is covered in the 'Common Errors' section.

Basically it is caused by a stack overflow due to use of recursion.
MKlegoman357 #3
Posted 07 June 2014 - 12:34 PM
We can't help you with your code if we cannot see it.

EDIT: just had a read through window API's code. This kind of error could have happened because of some kind of window-parent function recursion:

window1 has a child window2. window2 has a child window3. window1's parent is window3. window1 calls isColor which is invoked on window3 which calls isColor on it's parent - window2, and then window2 calls isColor on window1, because it is his parent. Recursion begins. Although, I don't really understand how could that happen…

The line on which the error occurs is as follows:


updateCursorColor()

And the source of updateCursorColor is:


local function updateCursorColor()
  parent.setTextColor( nTextColor )
end
Edited on 07 June 2014 - 10:47 AM
Bomb Bloke #4
Posted 08 June 2014 - 03:07 AM
Although, I don't really understand how could that happen…

It can't. A window must always be defined as having a parent which already exists, and it can't be switched to a different parent afterwards.

Odds are RandomGuyDom has built infinite recursion into his own code, and as that code likely makes additional calls to other functions (eg the ones in the window API, among others), it'd be quite unpredictable as to which call would finally blow the stack.

Edit: Kinda worth pointing out that under CC 1.6+, all advanced systems automatically fire up multishell on boot, which uses the window API to render pretty much everything - including any scripts you run. Thus any script which overflows the function stack has the potential to do so within the window API, if it involves any rendering to the system's inbuilt display.
Edited on 08 June 2014 - 01:11 AM