More memory stuff;

This commit is contained in:
bjorn 2018-03-24 01:17:36 -07:00
parent 426b907294
commit fe47104869
3 changed files with 8 additions and 1 deletions

View File

@ -45,6 +45,7 @@ int l_lovrThreadInit(lua_State* L) {
luaL_register(L, NULL, lovrThreadModule);
luax_registertype(L, "Thread", lovrThread);
luax_registertype(L, "Channel", lovrChannel);
lovrThreadInit();
return 1;
}
@ -60,7 +61,6 @@ int l_lovrThreadGetChannel(lua_State* L) {
const char* name = luaL_checkstring(L, 1);
Channel* channel = lovrThreadGetChannel(name);
luax_pushtype(L, Channel, channel);
lovrRelease(channel);
return 1;
}

View File

@ -15,6 +15,7 @@ void lovrDestroy() {
lovrHeadsetDestroy();
lovrMathDestroy();
lovrPhysicsDestroy();
lovrThreadDeinit();
lovrTimerDestroy();
}

View File

@ -13,6 +13,12 @@ void lovrThreadInit() {
void lovrThreadDeinit() {
if (!state.initialized) return;
const char* key;
map_iter_t iter = map_iter(&state.channels);
while ((key = map_next(&state.channels, &iter)) != NULL) {
Channel* channel = *(Channel**) map_get(&state.channels, key);
lovrRelease(channel);
}
map_deinit(&state.channels);
state.initialized = false;
}