We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 4451

Summary: [patch] Loading GIFs on multiple threads returns garbage output and crashes
Product: SDL_image Reporter: David Lönnhager <dv.lnh.d>
Component: miscAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: gapkalov
Version: 2.0.4   
Hardware: x86_64   
OS: Windows 10   
Attachments: Load GIFs on multiple threads
fix access violation

Description David Lönnhager 2019-01-10 22:22:56 UTC
Created attachment 3565 [details]
Load GIFs on multiple threads

It's due to the use of global variables and static local variables. A quick fix was moving all of that into a "state" struct and declaring it in IMG_LoadGIF_RW(), which apparently fixed the issue.

The left image shows what the output might have looked like before the patch: https://i.imgur.com/bs26rG8.png

Loading PNGs, JPGs, and BMPs on multiple threads seems to work.
Comment 1 Sam Lantinga 2019-06-10 23:32:58 UTC
Fixed, thanks!
https://hg.libsdl.org/SDL_image/rev/07fe7a23da89
Comment 2 Dmitry Gapkalov 2019-06-18 16:28:43 UTC
Hello, I have a crash with this changes. Crash happens in:

    state->buf[0] = state->buf[state->last_byte - 2];   // access violation becasu in last_byte - trash
    state->buf[1] = state->buf[state->last_byte - 1];

    if ((count = GetDataBlock(src, &state->buf[2], state)) <= 0)
        state->done = TRUE;

    state->last_byte = 2 + count; // last_byte  initialization
Comment 3 Dmitry Gapkalov 2019-06-18 16:35:34 UTC
Created attachment 3829 [details]
fix access violation

patch to fix access violation
Comment 4 Sam Lantinga 2019-06-19 13:51:54 UTC
Patch added, thanks!
https://hg.libsdl.org/SDL_image/rev/02e1f7b5746c