SOLVED Illegal buffer index error when using gif_save() function

mbeytekin

Member
I'm trying to save animated gif in GM2.

I'm using GM 2.2.5.378 and sometimes I get an error when I use gif_save() function;

___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Step Event0
for object obj_MAIN:

Illegal Buffer Index 6
at gml_Script_UI_Exporting_GIF (line 40) - var res=gif_save(global.gif_image,global.exportfilename)
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Script_UI_Exporting_GIF (line 40)
called from - gml_Object_obj_MAIN_Step_0 (line 118) - if global.GIFExport {UI_Exporting_GIF();}

normally this code works but sometimes it gives this error.
I use some other buffers in my program and I suspect gif buffer corrupts before saving.
Any idea?
 
Last edited:

FrostyCat

Redemption Seeker
Make sure you have not deleted the buffer before that line runs. Look for buffer_delete(global.gif_image); in your project, and think over in what situations those occurrences might occur before the line cited in the error.
 

mbeytekin

Member
Is there any way in GM2 buffers can be deleted or corrupted without buffer_delete(global.gif_image) ? Because I add some images to Gif buffer without an error and buffer_delete function is always run after gif_save in my code. But I use imguigml GUI extension which is uses some buffers and I suspect it corrupts gif buffer. Is this possible?
 

TheouAegis

Member
The variable you save is just a pointer to the buffer. If your variable has the same value as one used by the extension, they could be both inadvertently targeting the same buffer. But no, I have never seen any instance of buffers being volatile. Surfaces, yes. Buffers, no.
 

mbeytekin

Member
Thank you for your answers. Is there any way to avoid this? Because I realized that different buffer functions in my app causes same error. For example I use free ZIP extension from marketplace which purely coded in GML causes same error sometimes when I use it.
I use some my own DLL's which I coded in Visual Studio 2017 and 2012. Using external call or using as an extension are the same thing in terms of using buffers or memory?
How can I control buffer pointer address which is not using by other buffers?
 

TheouAegis

Member
Well, one possibly way, assuming that's indeed the root cause, is to never destroy buffers. Ever. Just reuse buffers.

Also, if you are calling buffer_delete() anywhere, make sure you also set the variable that holds that buffer ID to -1 or noone the same time you delete the buffer.
 

mbeytekin

Member
Thank you TheouAegis... I change buffer methods in my app. I create once when needed and never delete. Only I change buffer size when I need. Now It doesn't crash anymore.
 
Top