-
Notifications
You must be signed in to change notification settings - Fork 140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Crashes at 300+ Frames #37
Comments
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. Here is what I see after the crash in Microsoft Edge Version 113.0.1774.42 (Official build) (64-bit) in Windows 10: 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. |
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. |
I've written a looping animation in a canvas, and i'm trying to convert it into a gif by adding a frame every time I draw to the canvas, my animation is 360 frames long, but as soon as it reaches 300 frames, my webpage crashes, i've attached the error
The text was updated successfully, but these errors were encountered: