grimfang4 / sdl-gpu

A library for high-performance, modern 2D graphics with SDL written in C.
MIT License
1.18k stars 123 forks source link

Crash Caused by last_target->data Invalid State #131

Open DiegoAce opened 6 years ago

DiegoAce commented 6 years ago

By using the following code I believe I can cause last_target->data to be in an invalid state which could cause a crash.

#include "SDL.h"
#include "SDL_gpu.h"

int main(int argc, char* argv[])
{
    GPU_Init(800, 600, 0);
    GPU_Image* image = GPU_LoadImage("data/test.bmp");
    GPU_Image* image2 = GPU_CopyImage(image);
    GPU_Target* target = GPU_LoadTarget(image2);
    GPU_FreeTarget(target);
    GPU_ResetRendererState();
    return 0;
}

Inside the call to GPU_ResetRendererState cdata->last_target is not NULL and during the line: extBindFramebuffer(renderer, ((GPU_TARGET_DATA*)cdata->last_target->data)->handle); the handle and rest of the data is invalid. I think it was previously freed.

grimfang4 commented 6 years ago

That sounds right. The GL renderers' Free*() functions should be fixed so they NULL out the necessary internal state variables. Thanks for pointing this out!