diff --git a/src/audio/audio.c b/src/audio/audio.c index f999be4b..8d4a285f 100644 --- a/src/audio/audio.c +++ b/src/audio/audio.c @@ -31,9 +31,10 @@ void lovrAudioInit() { state.device = device; state.context = context; vec_init(&state.sources); - vec3_set(state.position, 0, 0, 0); quat_set(state.orientation, 0, 0, 0, -1); + + atexit(lovrAudioDestroy); } void lovrAudioDestroy() { diff --git a/src/event/event.c b/src/event/event.c index 56d3e179..d6f477f4 100644 --- a/src/event/event.c +++ b/src/event/event.c @@ -18,6 +18,7 @@ void lovrEventInit() { vec_init(&state.events); lovrEventAddPump(glfwPollEvents); glfwSetWindowCloseCallback(window, onClose); + atexit(lovrEventDestroy); } void lovrEventDestroy() { diff --git a/src/filesystem/filesystem.c b/src/filesystem/filesystem.c index faeb46a1..7643d451 100644 --- a/src/filesystem/filesystem.c +++ b/src/filesystem/filesystem.c @@ -2,6 +2,7 @@ #include "util.h" #include #include +#include #ifdef __APPLE__ #include #elif _WIN32 @@ -21,6 +22,7 @@ void lovrFilesystemInit(const char* arg0) { state.gameSource = NULL; state.identity = NULL; + atexit(lovrFilesystemDestroy); } void lovrFilesystemDestroy() { diff --git a/src/graphics/graphics.c b/src/graphics/graphics.c index 6136e36a..00d2e861 100644 --- a/src/graphics/graphics.c +++ b/src/graphics/graphics.c @@ -29,6 +29,7 @@ void lovrGraphicsInit() { vec_init(&state.shapeIndices); state.depthTest = -1; lovrGraphicsReset(); + atexit(lovrGraphicsDestroy); } void lovrGraphicsDestroy() { diff --git a/src/headset/headset.c b/src/headset/headset.c index e8d7d301..eac4c006 100644 --- a/src/headset/headset.c +++ b/src/headset/headset.c @@ -10,6 +10,14 @@ void lovrHeadsetInit() { if (headset) { lovrEventAddPump(lovrHeadsetPoll); } + + atexit(lovrHeadsetDestroy); +} + +void lovrHeadsetDestroy() { + if (headset) { + headset->destroy(headset); + } } void lovrHeadsetPoll() { diff --git a/src/headset/headset.h b/src/headset/headset.h index f5fdd5c8..0243fd1c 100644 --- a/src/headset/headset.h +++ b/src/headset/headset.h @@ -32,6 +32,7 @@ typedef struct { typedef vec_t(Controller*) vec_controller_t; typedef struct { + void (*destroy)(void* headset); char (*isPresent)(void* headset); void (*poll)(void* headset); const char* (*getType)(void* headset); @@ -61,6 +62,7 @@ typedef struct { #endif void lovrHeadsetInit(); +void lovrHeadsetDestroy(); void lovrHeadsetPoll(); char lovrHeadsetIsPresent(); const char* lovrHeadsetGetType(); diff --git a/src/headset/vive.c b/src/headset/vive.c index ef20dd0a..443a8d5c 100644 --- a/src/headset/vive.c +++ b/src/headset/vive.c @@ -61,6 +61,7 @@ Headset* viveInit() { if (!vive) return NULL; Headset* headset = (Headset*) vive; + headset->destroy = viveDestroy; headset->poll = vivePoll; headset->isPresent = viveIsPresent; headset->getType = viveGetType;