Skip to content

Commit b1cb7f1

Browse files
brainstormiChris Rees
authored and
Chris Rees
committed
SDL2 resource destructors fix
This is from ninenines#12
1 parent 4189b49 commit b1cb7f1

File tree

5 files changed

+29
-7
lines changed

5 files changed

+29
-7
lines changed

c_src/sdl_gl.c

+8-2
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,16 @@
1414

1515
#include "esdl2.h"
1616

17+
18+
NIF_CAST_HANDLER(thread_destroy_GLContext)
19+
{
20+
SDL_GL_DeleteContext(NIF_RES_GET(GLContext, args[0]));
21+
enif_release_resource(NIF_RES_DEP(GLContext, args[0]));
22+
}
23+
1724
void dtor_GLContext(ErlNifEnv* env, void* obj)
1825
{
19-
SDL_GL_DeleteContext(NIF_RES_GET(GLContext, obj));
20-
enif_release_resource(NIF_RES_DEP(GLContext, obj));
26+
nif_thread_cast(env,thread_destroy_GLContext,1,obj);
2127
}
2228

2329
// gl_create_context

c_src/sdl_renderer.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@
1414

1515
#include "esdl2.h"
1616

17+
NIF_CAST_HANDLER(thread_destroy_renderer)
18+
{
19+
SDL_DestroyRenderer(NIF_RES_GET(Renderer, args[0]));
20+
enif_release_resource(NIF_RES_DEP(Renderer, args[0]));
21+
}
1722
void dtor_Renderer(ErlNifEnv* env, void* obj)
1823
{
19-
SDL_DestroyRenderer(NIF_RES_GET(Renderer, obj));
20-
enif_release_resource(NIF_RES_DEP(Renderer, obj));
24+
nif_thread_cast(env,thread_destroy_renderer,1,obj);
2125
}
2226

2327
#define RENDERER_FLAGS(F) \

c_src/sdl_surface.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,13 @@
1515
#include "esdl2.h"
1616
#include "SDL_image.h"
1717

18+
NIF_CAST_HANDLER(thread_destroy_surface)
19+
{
20+
SDL_FreeSurface(NIF_RES_GET(Surface, args[0]));
21+
}
1822
void dtor_Surface(ErlNifEnv* env, void* obj)
1923
{
20-
SDL_FreeSurface(NIF_RES_GET(Surface, obj));
24+
nif_thread_cast(env,thread_destroy_surface,1,obj);
2125
}
2226

2327
// img_load

c_src/sdl_texture.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@
1717
NIF_ATOM_TO_ENUM_FUNCTION_DECL(atom_to_blend_mode, SDL_BlendMode)
1818
NIF_ENUM_TO_ATOM_FUNCTION_DECL(blend_mode_to_atom, SDL_BlendMode)
1919

20+
NIF_CAST_HANDLER(thread_destroy_texture)
21+
{
22+
SDL_DestroyTexture(NIF_RES_GET(Texture, args[0]));
23+
}
2024
void dtor_Texture(ErlNifEnv* env, void* obj)
2125
{
22-
SDL_DestroyTexture(NIF_RES_GET(Texture, obj));
26+
nif_thread_cast(env,thread_destroy_texture,1,obj);
2327
}
2428

2529
// create_texture_from_surface

c_src/sdl_window.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@
1616

1717
NIF_ATOM_TO_ENUM_FUNCTION_DECL(atom_to_bool, SDL_bool)
1818

19+
NIF_CAST_HANDLER(thread_destroy_window)
20+
{
21+
SDL_DestroyWindow(NIF_RES_GET(Window, args[0]));
22+
}
1923
void dtor_Window(ErlNifEnv* env, void* obj)
2024
{
21-
SDL_DestroyWindow(NIF_RES_GET(Window, obj));
25+
nif_thread_cast(env,thread_destroy_window,1,obj);
2226
}
2327

2428
#define WINDOW_FLAGS(F) \

0 commit comments

Comments
 (0)