question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"index out of range" with dynamic array size

See original GitHub issue

I add new elements to the data i read in but on save i get the “index out of range” error when i call writeAll(data).

“array(baseType, @length) - array of given type and length, reads/writes to the end of binary if length is not given.” I did not specify length. So i assumed it would be able to still save if i add more entries to the array than there was before - but it only works if i remove or keep the number the same.

    file: {
        recordNum: "int32",
        fieldNum: "int32",
        recordSize: "int32",
        data: ["array", dataFld"]
    }

RangeError: Index out of range
    at checkInt (buffer.js:1187:11)
    at Buffer.writeInt32LE (buffer.js:1375:5)

I store the jbinary object:

            loadedJBinary = binary;
            resolve({ data: loadedJBinary.readAll() });

And use it again to write: loadedJBinary.writeAll(data);

Because i saw no way to use a existing js object to create a new jBinary object to save. But this does not work with the increasing array size.

Nether did i find any way to update the size of arrays before writeall.

Can just hope this project isn’t dead, it’s the only one in existence that i could find that allows use of a C++ like struct approach.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Keteccommented, Aug 19, 2018

Found a way around the issue. I forgot the file had a header that specified each block size and count so i could calculate new buffer size from it.

0reactions
Keteccommented, Aug 19, 2018

I do not know the byte size of a js object (because the null terminated strings are shorter and do not include the 00 bytes - so the string may only be 2 bytes in object but it should be 64 bytes in final data).

I found binary.view.byteLength to get the current length from another issue - but i still lack away to get the value to increase it by. Is there a way to calculate it / get the byte size of a type ( ex. dataFld.byteLength so i can just add x number of that value)?

Read more comments on GitHub >

github_iconTop Results From Across the Web

IndexError: list index out of range on python dynamic variable ...
When you assign a value to an array in python, the element must already exist. ... you are assigning values out of the...
Read more >
What happens if dynamic array index is out of range?
The transaction will revert. If I remember right, the execution emits a panic code which reverts everything. But, regardless of how the ...
Read more >
Limiting the length of results from Dynamic / Spill Arrays
I am trying to figure out a way to limit the number of results returned from a dynamic array such as =UNIQUE or...
Read more >
Controlling out of bound in static arrays - 4Js
By default, when an array index is out of range, fglrun raises error -1326. This is only the case for static arrays: When...
Read more >
Arrays — Pine Script™ v5 User Manual v5 documentation
Index xx is out of bounds. Array size is yy; Cannot call array methods when ID of array is 'na'; Array is too...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found