aboutsummaryrefslogtreecommitdiffstats
path: root/c_src/sdl_window.c
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2014-04-03 19:13:04 +0200
committerLoïc Hoguin <[email protected]>2014-04-03 19:21:31 +0200
commit3026b4860fd3a1436a59bf2d26792fbbf6b60917 (patch)
tree8b8e3b8aafcc3968ee8031293fa63f65fbac4f66 /c_src/sdl_window.c
parentafc06a3ef6689bd86780c3df065d3ec8efa4bce8 (diff)
downloadesdl2-3026b4860fd3a1436a59bf2d26792fbbf6b60917.tar.gz
esdl2-3026b4860fd3a1436a59bf2d26792fbbf6b60917.tar.bz2
esdl2-3026b4860fd3a1436a59bf2d26792fbbf6b60917.zip
Add sdl_window:set_icon/2
The surface needs to be kept around and not GC otherwise it crashes.
Diffstat (limited to 'c_src/sdl_window.c')
-rw-r--r--c_src/sdl_window.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/c_src/sdl_window.c b/c_src/sdl_window.c
index c32d33c..b79cd4f 100644
--- a/c_src/sdl_window.c
+++ b/c_src/sdl_window.c
@@ -518,3 +518,28 @@ NIF_FUNCTION(set_window_grab)
return nif_thread_cast(env, thread_set_window_grab, 2,
NIF_RES_GET(Window, window_res), b);
}
+
+// set_window_icon
+//
+// We use a call here because we need the surface to exist until this call
+// succeeds. If we didn't, a race condition might happen where the surface
+// is GC before it is used in the main thread.
+
+NIF_CALL_HANDLER(thread_set_window_icon)
+{
+ SDL_SetWindowIcon(args[0], args[1]);
+
+ return atom_ok;
+}
+
+NIF_FUNCTION(set_window_icon)
+{
+ void* window_res;
+ void* surface_res;
+
+ BADARG_IF(!enif_get_resource(env, argv[0], res_Window, &window_res));
+ BADARG_IF(!enif_get_resource(env, argv[1], res_Surface, &surface_res));
+
+ return nif_thread_call(env, thread_set_window_icon, 2,
+ NIF_RES_GET(Window, window_res), NIF_RES_GET(Surface, surface_res));
+}