Giter Site home page Giter Site logo

Crashes at 300+ Frames about jsgif HOT 2 OPEN

antimatter15 avatar antimatter15 commented on July 24, 2024
Crashes at 300+ Frames

from jsgif.

Comments (2)

joshi1983 avatar joshi1983 commented on July 24, 2024

I ran into likely the same bug. I get the same error message after trying to encode 201 frames of a 512 by 512 resolution animation but I think the more critical detail is how large the compressed data is getting. It crashed shortly after the "outs" variable reached roughly 50 million elements. It is a ByteArray as defined in GIFEncoder.js which is repeatedly given more bytes using writeByte and writeBytes in the LZWEncoder.js. Eventually, the browser freezes for a few seconds before showing the error message above. The exact line of crash was outs.writeBytes(accum, 0, a_count) in the flush_char function of LZWEncoder.js while GIFEncoder is calling output on a pixel indirectly from the addFrame function. Immediately before that final call to writeBytes, outs = ByteArray { bin: Array(50139333)} according to Edge's debugger tools. I tried to encode the same animation in both Microsoft Edge and Google Chrome and it crashed on the same frame. I'm testing with a laptop that has 8GB of RAM.

I want to help you reproduce the problem so I'm sharing a prototype that tries to encode and download a gif as soon as you open it. When I open it in Edge, it encodes many frames but eventually crashes within a minute or so.
My prototype references a minified version but the problem is reproduced if you download and reference using script tags in the HTML file:
jsgif/LZWEncoder.js
jsgif/NeuQuant.js
jsgif/GIFEncoder.js
gifOutputBufferTooLarge.zip

Here is what I see after the crash in Microsoft Edge Version 113.0.1774.42 (Official build) (64-bit) in Windows 10:
image

I understand if the encoder runs out of RAM at some point but 50MB seems a little small for a maximum sized gif. Even if ByteArray can't expand beyond 50 million elements or so, a JavaScript Error or exception would be FAR more graceful than letting the browser tab completely crash. If GIFEncoder needs to be optimized for memory, a typed Array of 8-bit elements such as Uint8Array should use a small fraction of the memory.

from jsgif.

joshi1983 avatar joshi1983 commented on July 24, 2024

Pull request #40 is open to tackle a large part of this problem by optimizing the data structure maintaining the encoded GIF data. I have it merged in my fork so if you want a more updated and stable jsgif, try my fork. antimatter15's repo looks like it has been dead for about 6 years.

from jsgif.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.