-1

I'm attempting to create a minimal usage example for https://github.com/ginsweater/gif-h

But, starting with a vector<uint8_t> of size imageWidth*imageHeight, the second GifWriteFrame call throws an access violation reading location exception

My attempt:

#include <gif.h>
#include "BOBImageConversion.h"
int main(void)
{
    // USAGE:
    // Create a GifWriter struct. Pass it to GifBegin() to initialize and write the header.
    // Pass subsequent frames to GifWriteFrame().
    // Finally, call GifEnd() to close the file handle and free memory.

    int delay = 100;
    auto i1 = BOBImageIO::BOBLoadImage("Camera7.png");
    auto i2 = BOBImageIO::BOBLoadImage("Camera18.png");

    vector<uint8_t> vi1 = BOBImageConversion::ARGB2RGBAuint8(i1);
    vector<uint8_t> vi2 = BOBImageConversion::ARGB2RGBAuint8(i2);
    cout << (vi1.size() == i1.Width()*i1.Height()) << endl;         // true
    cout << (vi2.size() == i2.Width()*i2.Height()) << endl;         // true

    auto fileName = "gif.gif";
    GifWriter g;
    GifBegin(&g, fileName, i1.Width(), i1.Height(), delay);
    GifWriteFrame(&g, vi1.data(), i1.Width(), i1.Height(), delay);
    GifWriteFrame(&g, vi2.data(), i2.Width(), i2.Height(), delay); // Exception thrown: Access violation reading location 
    GifEnd(&g);

    return 0;
}

For the above point the code posted is a minimal example. What's wrong?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
WurmD
  • 1,231
  • 5
  • 21
  • 42

1 Answers1

1

This works

#include <vector>
#include <cstdint>
#include <gif.h>
int main()
{
    int width = 100;
    int height = 200;
    std::vector<uint8_t> vi1(width * height * 4, 0);
    std::vector<uint8_t> vi2(width * height * 4, 255);

    auto fileName = "bwgif.gif";
    int delay = 100;
    GifWriter g;
    GifBegin(&g, fileName, width, height, delay);
    GifWriteFrame(&g, vi1.data(), width, height, delay);
    GifWriteFrame(&g, vi2.data(), width, height, delay);
    GifEnd(&g);

    return 0;
}
WurmD
  • 1,231
  • 5
  • 21
  • 42
  • It's missing an include for vector and vectors should be prefixed with std namespace. uint8_t is pulled by gif.h, but it's not a good idea to rely on that. Also the main argument list should be empty in C++ as in 'int main()'. 'int main(void)' is a C syntax. – Miroslav Franc Apr 03 '19 at 12:21
  • txs @MiroslavFranc ! added – WurmD Apr 03 '19 at 13:42