GML Trouble with buffers

R

Rackover

Guest
Hi, i'm getting trouble with the buffers. I've read the documentation but to no avail.
I only made a little test, to experiment, but it doesn't even work and I do not understand why.

Here is the code :

Code:
msgBuffer = buffer_create(1024, buffer_fixed, 1);

buffer_poke(msgBuffer, 0, buffer_string, "A");
buffer_poke(msgBuffer, 1, buffer_string, "B");
buffer_poke(msgBuffer, 2, buffer_string, "C");
buffer_save(msgBuffer, "savedBuffer.bin");

show_debug_message(buffer_peek(msgBuffer, 0, buffer_string));
show_debug_message(buffer_peek(msgBuffer, 1, buffer_string));
show_debug_message(buffer_peek(msgBuffer, 2, buffer_string));

show_debug_message(buffer_peek(msgBuffer, 0, buffer_u8));
show_debug_message(buffer_peek(msgBuffer, 1, buffer_u8));
show_debug_message(buffer_peek(msgBuffer, 2, buffer_u8));

I expect it to debug something like :

A
B
C
65
66
67
But the output is :

0
0
0
65
66
67
Why can't it read back the strings ?
 
I had originally wrote here something about strings being more than 1 byte in size, implying that you are overwriting parts of your strings.

However, doing this simple test seems to reveal that buffer_peek does not work correctly with string types. The first show_message will show "0", the second one "A".

Tested with GMS1.4.1772 on windows platform.

b = buffer_create(1024,buffer_fixed,1);
buffer_poke(b,0,buffer_string,"A");
var _str = buffer_peek(b,0,buffer_string);
show_message(_str);
buffer_seek(b,buffer_seek_start,0);
var _str = buffer_read(b,buffer_string);
show_message(_str);
 
Last edited:
R

Rackover

Guest
These strings are too short to exceed a byte, and also I checked with HxD and the .bin is correctly written with the corresponding characters at the right place. Are you sure buffer_peek is incapable of reading strings ? The doc says otherwise.
 
I don't see how that test could be made any more conclusive.

Starting at position zero, buffer_read gets correct result, but peeking at position zero does not.

I would say, you have discovered a bug.
 
I read the manual entry for buffer_peek as well. But I don't see what we could possibly be doing wrong at this point.

I can imagine using buffer_peek to read strings is an uncommon thing to do anyway, since strings are usually random length. So maybe it wasn't even tested.

edit: and while I've been working on this, I discovered something else. While you can use buffer_peek to read out bits of strings as buffer_u8, you can't do the same thing with buffer_read. Weird.
 
Last edited:

TheouAegis

Member
The manual isn't perfect. It was written by Nocturne, or someone else by now - who knows. And a lot of the manual uses stuff from previous entries just copy and pasted. Just because the manual says something should work doesn't mean it necessarily does work. There are lots of entries in the manual that need to be changed and that simply haven't because they don't feel it's worth their time.

@flyingsaucerinvasion 's code shows that peeking is indeed bugged. Plain and simple.
 

The-any-Key

Member
Seems buffer_string don't work with peek so that is a bug. But it write the correct data to the buffer:

Code:
msgBuffer = buffer_create(10, buffer_grow, 1);
for (var i=0; i<buffer_get_size(msgBuffer); i+=1)
{
    buffer_poke(msgBuffer, i, buffer_u8, 1);
}
buffer_poke(msgBuffer, 0, buffer_string, "A");
buffer_poke(msgBuffer, 2, buffer_string, "B");
buffer_poke(msgBuffer, 4, buffer_string, "C");
for (var i=0; i<buffer_get_size(msgBuffer); i+=1)
{
    show_debug_message(buffer_peek(msgBuffer, i, buffer_u8));
}
Code:
65
0
66
0
67
0
1
1
1
1
 
R

Rackover

Guest
Hi,
No, I didn't fill a bug report, sorry. Can someone here do it ? I do not know how to do it and the only moment I come to this forum is when I need help (and here I have returned, because I need help for something else). Or maybe can you tell me very quick how to do it ?
Thank you !
 
Top