StreamPeerBuffer.seek() always print an Error

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Legorel

I one of my script, I am working on bytes of a StreamPeerBuffer. This is how my loop looks like:

# not my actual bytes, just for the exemple
var bytes := [2, 32, 15, 17, 20, 23, 55, 11, 9]
# I have to convert the array to a StreamPeerBuffer, if there is a better way to do it tell me
var stream := StreamPeerBuffer.new()
for i in range(8):
  stream.put_u8(bytes[i])

var available_bytes := stream.get_available_bytes()
for _i in range(available_bytes):
  # running tests and other things

Then at some point in the loop, I want to go to a certain spot in the stream, so I use the seekfunction:

# next_pos is defined inside my loop
stream.seek(next_pos + 4)

But every time the seek function is called, the debugger prints an error: seek: Condition "p_pos > data.size()" is true
It still works without problem (the cursor of the stream is moved to the right location) but i don’t understand why i always get this error.
Is it normal or am I doing something wrong ?

I have to convert the array to a StreamPeerBuffer, if there is a better way to do it tell

You can set stream.data_array directly, so stream.data_array = bytes should work.

Also, can you print what next_pos is? It seems like it is out of range.

Jummit | 2021-04-18 15:52

:bust_in_silhouette: Reply From: Legorel

I have to convert the array to a StreamPeerBuffer, if there is a better way to do it tell

Also, can you print what next_pos is? It seems like it is out of range.

After printing the var, yes it was definitely out of range. The problem was that the variable next_pos is calculated with data i read in the stream, but my data is in big-endian and I didn’t set the big-endian var to true. For exemple, istead of reading the number 13, i would read 218103808 (big problem xD).