Properly destroy modules on exit;

This commit is contained in:
bjorn 2017-01-21 18:18:12 -08:00
parent 4303846eac
commit 492a75acba
7 changed files with 17 additions and 1 deletions

View File

@ -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() {

View File

@ -18,6 +18,7 @@ void lovrEventInit() {
vec_init(&state.events);
lovrEventAddPump(glfwPollEvents);
glfwSetWindowCloseCallback(window, onClose);
atexit(lovrEventDestroy);
}
void lovrEventDestroy() {

View File

@ -2,6 +2,7 @@
#include "util.h"
#include <physfs.h>
#include <stdio.h>
#include <stdlib.h>
#ifdef __APPLE__
#include <mach-o/dyld.h>
#elif _WIN32
@ -21,6 +22,7 @@ void lovrFilesystemInit(const char* arg0) {
state.gameSource = NULL;
state.identity = NULL;
atexit(lovrFilesystemDestroy);
}
void lovrFilesystemDestroy() {

View File

@ -29,6 +29,7 @@ void lovrGraphicsInit() {
vec_init(&state.shapeIndices);
state.depthTest = -1;
lovrGraphicsReset();
atexit(lovrGraphicsDestroy);
}
void lovrGraphicsDestroy() {

View File

@ -10,6 +10,14 @@ void lovrHeadsetInit() {
if (headset) {
lovrEventAddPump(lovrHeadsetPoll);
}
atexit(lovrHeadsetDestroy);
}
void lovrHeadsetDestroy() {
if (headset) {
headset->destroy(headset);
}
}
void lovrHeadsetPoll() {

View File

@ -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();

View File

@ -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;