Jump to content




[FIXED] Custom fs.open: java.lang.ArrayIndexOutOfBoundsException: 256


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

#1 Blue

  • Members
  • 309 posts
  • LocationGlass/UX/main.lua

Posted 15 May 2016 - 06:39 AM

Hi, I've been trying to make a custom fs.open() to upload and download files automatically,but when I try to use it,it errors:

CCEmuRedux:
11: vm error: java.lang.ArrayIndexOutOfBoundsException: 256

Mimic:
11: stack overflow

Code:
(Pastebin)

Does anybody know how to fix this?

Edited by Blue, 15 May 2016 - 08:22 AM.


#2 Bomb Bloke

    Hobbyist Coder

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

Posted 15 May 2016 - 07:09 AM

Remember that you can't assign tables to variables - you're instead assigning pointers which lead to tables. Same goes for functions and coroutines.

So because "newHandle" and "oldHandle" each point to the same table, when you tell newHandle.close() to call oldHandle.close(), you're really telling the function to call itself. The resulting infinite loop of calls blows up the function stack - this causes a Java error within LuaJ, and a similar error message from Mimic.

If you want to create a new table with the same content as an existing one, you'll need to specifically make a new table and copy that content over.

Alternatively, you could just preserve your old close() pointer in a local variable:

local oldClose = handle.close

function handle.close()
  oldClose()
  etc...

Edited by Bomb Bloke, 15 May 2016 - 07:11 AM.


#3 Blue

  • Members
  • 309 posts
  • LocationGlass/UX/main.lua

Posted 15 May 2016 - 07:28 AM

View PostBomb Bloke, on 15 May 2016 - 07:09 AM, said:

Remember that you can't assign tables to variables - you're instead assigning pointers which lead to tables. Same goes for functions and coroutines.

So because "newHandle" and "oldHandle" each point to the same table, when you tell newHandle.close() to call oldHandle.close(), you're really telling the function to call itself. The resulting infinite loop of calls blows up the function stack - this causes a Java error within LuaJ, and a similar error message from Mimic.

If you want to create a new table with the same content as an existing one, you'll need to specifically make a new table and copy that content over.

Alternatively, you could just preserve your old close() pointer in a local variable:

local oldClose = handle.close

function handle.close()
  oldClose()
  etc...
Thanks,it works! :D I've almost spent a week trying to fix this





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users