Skip to content
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
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,7 @@ endif
bullet_engine:: all
erlc -o examples/bullet_engine examples/bullet_engine/*.erl
cd examples/bullet_engine && ./start.sh

hello_sdl:: all
erlc -o examples/hello_sdl examples/hello_sdl/*.erl
cd examples/hello_sdl && ./start.sh
8 changes: 6 additions & 2 deletions c_src/nif_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,14 @@ void nif_destroy_main_thread(void* void_st)
nif_thread_message* msg = nif_thread_message_alloc(NULL, NULL, NULL);

nif_thread_send(st, msg);
enif_thread_join(st->tid, NULL);
#if defined(__APPLE__) && defined(__MACH__)
erl_drv_stolen_main_thread_join(st->tid, NULL);
#else
enif_thread_join(st->tid, NULL);
#endif

enif_cond_destroy(st->cond);
enif_mutex_destroy(st->lock);
enif_cond_destroy(st->cond);
enif_free(st->mailbox);
enif_free(st);
}
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
2 changes: 1 addition & 1 deletion examples/hello_sdl/hello_sdl.erl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
-export([run/0]).

run() ->
spawn_opt(fun init/0, [{scheduler, 0}]).
spawn(fun init/0).

init() ->
ok = sdl:start([video]),
Expand Down