Skip to content

Commit

Permalink
SDL2 resource destructors fix
Browse files Browse the repository at this point in the history
This is from ninenines#12
  • Loading branch information
brainstormi authored and Chris Rees committed Aug 30, 2016
1 parent 14583c5 commit 280ea09
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
10 changes: 8 additions & 2 deletions c_src/sdl_gl.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,16 @@

#include "esdl2.h"


NIF_CAST_HANDLER(thread_destroy_GLContext)
{
SDL_GL_DeleteContext(NIF_RES_GET(GLContext, args[0]));
enif_release_resource(NIF_RES_DEP(GLContext, args[0]));
}

void dtor_GLContext(ErlNifEnv* env, void* obj)
{
SDL_GL_DeleteContext(NIF_RES_GET(GLContext, obj));
enif_release_resource(NIF_RES_DEP(GLContext, obj));
nif_thread_cast(env,thread_destroy_GLContext,1,obj);
}

// gl_create_context
Expand Down
8 changes: 6 additions & 2 deletions c_src/sdl_renderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@

#include "esdl2.h"

NIF_CAST_HANDLER(thread_destroy_renderer)
{
SDL_DestroyRenderer(NIF_RES_GET(Renderer, args[0]));
enif_release_resource(NIF_RES_DEP(Renderer, args[0]));
}
void dtor_Renderer(ErlNifEnv* env, void* obj)
{
SDL_DestroyRenderer(NIF_RES_GET(Renderer, obj));
enif_release_resource(NIF_RES_DEP(Renderer, obj));
nif_thread_cast(env,thread_destroy_renderer,1,obj);
}

#define RENDERER_FLAGS(F) \
Expand Down
6 changes: 5 additions & 1 deletion c_src/sdl_surface.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@
#include "esdl2.h"
#include "SDL_image.h"

NIF_CAST_HANDLER(thread_destroy_surface)
{
SDL_FreeSurface(NIF_RES_GET(Surface, args[0]));
}
void dtor_Surface(ErlNifEnv* env, void* obj)
{
SDL_FreeSurface(NIF_RES_GET(Surface, obj));
nif_thread_cast(env,thread_destroy_surface,1,obj);
}

// img_load
Expand Down
6 changes: 5 additions & 1 deletion c_src/sdl_texture.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@
NIF_ATOM_TO_ENUM_FUNCTION_DECL(atom_to_blend_mode, SDL_BlendMode)
NIF_ENUM_TO_ATOM_FUNCTION_DECL(blend_mode_to_atom, SDL_BlendMode)

NIF_CAST_HANDLER(thread_destroy_texture)
{
SDL_DestroyTexture(NIF_RES_GET(Texture, args[0]));
}
void dtor_Texture(ErlNifEnv* env, void* obj)
{
SDL_DestroyTexture(NIF_RES_GET(Texture, obj));
nif_thread_cast(env,thread_destroy_texture,1,obj);
}

// create_texture_from_surface
Expand Down
6 changes: 5 additions & 1 deletion c_src/sdl_window.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@

NIF_ATOM_TO_ENUM_FUNCTION_DECL(atom_to_bool, SDL_bool)

NIF_CAST_HANDLER(thread_destroy_window)
{
SDL_DestroyWindow(NIF_RES_GET(Window, args[0]));
}
void dtor_Window(ErlNifEnv* env, void* obj)
{
SDL_DestroyWindow(NIF_RES_GET(Window, obj));
nif_thread_cast(env,thread_destroy_window,1,obj);
}

#define WINDOW_FLAGS(F) \
Expand Down

0 comments on commit 280ea09

Please sign in to comment.