Skip to content
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

SDL2 resource destructors segfaults fix #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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