Requesting C++ / stbi help with developing animated GIF feature

Greetings fellow developers. I am in the process of adding support for animated GIFs to my existing module Computerscare Custom Blank. I found an implementation example online using stbi that I have successfully adapted to work in my module, but when I have multiple instances of Custom Blank, they all show the same GIF. I’ve confirmed that each module instance is trying to load a different GIF, I believe the problem is somewhere in the stbi_xload function defined here:

This is the module code:

I’m pretty ignorant about using pointers, and direct memory reading/writing in C++ (as this code does). Any ideas would be much appreciated! Thanks in advance.


so I really don’t know why I even tried this, but the problem is here -

You delete there some frame data or corrupt the image data somehow in your frames vector with stbi_image_free(img);. I commented this line out and then it works. I tried this on Windows and your original code immediately crashes Rack when loading a gif.

Every panel shows then it’s own gif animation.

And btw - this code is really scary :scream:

You should definitely think about some proper memory management!

1 Like

Thank you for taking a look at this!

And btw - this code is really scary :scream:

Yeah… I’m scared by it too. I mostly just copy/pasted that method from a gist I found and it worked so I decided it is a good starting point. Do you have any specific suggestions for how this can be improved related to memory management? Or any additional thoughts on what is problematic about this implementation?

Again I appreciate your time and feedback!