• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML [SOLVED] Having issues with buffer_get_surface

Alabard

Member
Greetings, I'm having problems using a buffer filled by buffer_get_surface, I'm trying to save the buffer data for later use but I can't seem to find a way to do it, if I try to save the buffer to a file the resulting file is empty, if I use buffer_base64_encode it returns the string "AA==", if I try to compress the buffer it returns a buffer of size 9 which upon decompression returns a buffer of size 1.

The buffer is properlly getting the surface data, since I can use buffer_set_surface to print the buffer back into a new surface, and if I try to use data other than the one adquired from the surface, say strings for example, the functions behave correctly. It's when trying to use the mentioned functions with a surface filled buffer that the buffer behaves as if it was empty.

Is this behaviour a bug? am I doing something wrong? or is what I'm trying to do simply not supported?

For reference, this is the code with which I'm performing my tests:

Code:
_surface = surface_create(320,240);
surface_set_target(_surface);
draw_clear(c_black);
draw_sprite(sprite0,0,0,0)
surface_reset_target();

_buffer = buffer_create(320*240*4,buffer_grow,1);
buffer_get_surface(_buffer,_surface,0,0,0);

surface_free(_surface);

buffer_save(_buffer,"savefile_buffer"); //The file is empty
_string = buffer_base64_encode(_buffer,0,buffer_get_size(_buffer)); //The string is AA==
c_buffer = buffer_compress(_buffer,0,buffer_get_size(_buffer)); //The size of the compressed buffer is 9
d_buffer = buffer_decompress(c_buffer); //The size of the decompressed buffer is 1

_surface_new = surface_create(320,240);
buffer_set_surface(_buffer,_surface_new,0,0,0); //The buffer is properly printed in the surface
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Is this in the DRAW event or elsewhere? Not saying it'll fix the issue, but if you are working with surfaces, it should always be done in the draw event as that's the recommended procedure, and using any other event can lead to undocumented (and erroneous) behaviour.
 

Alabard

Member
No, at the time of testing this was done on a create event, however moving the code to a draw event doesn't change anything, buffer_save still creates an empty file, buffer_base64_encode still creates the string "AA=" and buffer_compress and buffer_decompress still results in an buffer of size 1.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
THen I'd suggest you file a bug... If you can, please supply a link to a YYZ that shows the issue too when you file it. You can file the bug from the "Help" menu in the IDE.
 

Alabard

Member
Alright, I just sent the bug report, I guess I'll just have save the surface as an png image for the time being.

Thanks for the help.
 

Alabard

Member
Nope, even with an extension the created file is still empty. Thanks for the suggestion though, it was worth a try.

Edit: Ok, I just found a way around it, according to the bug report made for the issue (https://bugs.yoyogames.com/view.php?id=31536), the problem is that the "used size" of the buffer is not properlly being set.

So by simply writing something at the end of the buffer its used size is corrected and the buffer works again as it should for buffer_save, buffer_base64_encode/decode and buffer_compress/decompress.

Basically, after using buffer_get_surface I use:
Code:
buffer_poke(_buffer,buffer_get_size(_buffer)-1,buffer_u8,buffer_peek(_buffer,buffer_get_size(_buffer)-1,buffer_u8))
To rewrite the final value of the buffer.

Thanks for the help.
 
Last edited:
Top