mirror of https://github.com/bjornbytes/lovr.git
Fix problem when requiring audio/graphics/headset in threads;
These modules access the conf table, which isn't available on threads.
This commit is contained in:
parent
599bbc5cf4
commit
7ed47e946b
|
@ -306,17 +306,20 @@ int luaopen_lovr_audio(lua_State* L) {
|
|||
bool start = true;
|
||||
const char *spatializer = NULL;
|
||||
luax_pushconf(L);
|
||||
lua_getfield(L, -1, "audio");
|
||||
if (lua_istable(L, -1)) {
|
||||
lua_getfield(L, -1, "spatializer");
|
||||
spatializer = lua_tostring(L, -1);
|
||||
lua_pop(L, 1);
|
||||
lua_getfield(L, -1, "audio");
|
||||
if (lua_istable(L, -1)) {
|
||||
lua_getfield(L, -1, "spatializer");
|
||||
spatializer = lua_tostring(L, -1);
|
||||
lua_pop(L, 1);
|
||||
|
||||
lua_getfield(L, -1, "start");
|
||||
start = lua_isnil(L, -1) || lua_toboolean(L, -1);
|
||||
lua_getfield(L, -1, "start");
|
||||
start = lua_isnil(L, -1) || lua_toboolean(L, -1);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
lua_pop(L, 2);
|
||||
lua_pop(L, 1);
|
||||
|
||||
if (lovrAudioInit(spatializer)) {
|
||||
luax_atexit(L, lovrAudioDestroy);
|
||||
|
|
|
@ -1845,22 +1845,26 @@ int luaopen_lovr_graphics(lua_State* L) {
|
|||
luax_registertype(L, ShaderBlock);
|
||||
luax_registertype(L, Texture);
|
||||
|
||||
luax_pushconf(L);
|
||||
|
||||
bool debug = false;
|
||||
lua_getfield(L, -1, "graphics");
|
||||
|
||||
luax_pushconf(L);
|
||||
if (lua_istable(L, -1)) {
|
||||
lua_getfield(L, -1, "debug");
|
||||
debug = lua_toboolean(L, -1);
|
||||
lua_getfield(L, -1, "graphics");
|
||||
if (lua_istable(L, -1)) {
|
||||
lua_getfield(L, -1, "debug");
|
||||
debug = lua_toboolean(L, -1);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
lua_pop(L, 1);
|
||||
|
||||
lovrGraphicsInit(debug);
|
||||
|
||||
lua_pushcfunction(L, l_lovrGraphicsCreateWindow);
|
||||
lua_getfield(L, -2, "window");
|
||||
lua_call(L, 1, 0);
|
||||
if (lua_istable(L, -1)) {
|
||||
lua_pushcfunction(L, l_lovrGraphicsCreateWindow);
|
||||
lua_getfield(L, -2, "window");
|
||||
lua_call(L, 1, 0);
|
||||
}
|
||||
lua_pop(L, 1);
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -114,9 +114,6 @@ static Device luax_optdevice(lua_State* L, int index) {
|
|||
}
|
||||
|
||||
static int l_lovrHeadsetInit(lua_State* L) {
|
||||
luax_pushconf(L);
|
||||
lua_getfield(L, -1, "headset");
|
||||
|
||||
size_t driverCount = 0;
|
||||
HeadsetDriver drivers[8];
|
||||
float supersample = 1.f;
|
||||
|
@ -124,48 +121,52 @@ static int l_lovrHeadsetInit(lua_State* L) {
|
|||
int msaa = 4;
|
||||
bool overlay = false;
|
||||
|
||||
luax_pushconf(L);
|
||||
if (lua_istable(L, -1)) {
|
||||
lua_getfield(L, -1, "headset");
|
||||
if (lua_istable(L, -1)) {
|
||||
|
||||
// Drivers
|
||||
lua_getfield(L, -1, "drivers");
|
||||
int n = luax_len(L, -1);
|
||||
for (int i = 0; i < n; i++) {
|
||||
lua_rawgeti(L, -1, i + 1);
|
||||
drivers[driverCount++] = luax_checkenum(L, -1, HeadsetDriver, NULL);
|
||||
lovrAssert(driverCount < sizeof(drivers) / sizeof(drivers[0]), "Too many headset drivers specified in conf.lua");
|
||||
// Drivers
|
||||
lua_getfield(L, -1, "drivers");
|
||||
int n = luax_len(L, -1);
|
||||
for (int i = 0; i < n; i++) {
|
||||
lua_rawgeti(L, -1, i + 1);
|
||||
drivers[driverCount++] = luax_checkenum(L, -1, HeadsetDriver, NULL);
|
||||
lovrAssert(driverCount < sizeof(drivers) / sizeof(drivers[0]), "Too many headset drivers specified in conf.lua");
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
lua_pop(L, 1);
|
||||
|
||||
// Supersample
|
||||
lua_getfield(L, -1, "supersample");
|
||||
if (lua_type(L, -1) == LUA_TBOOLEAN) {
|
||||
supersample = lua_toboolean(L, -1) ? 2.f : 1.f;
|
||||
} else {
|
||||
supersample = luax_optfloat(L, -1, 1.f);
|
||||
}
|
||||
lua_pop(L, 1);
|
||||
|
||||
// Offset
|
||||
lua_getfield(L, -1, "offset");
|
||||
offset = luax_optfloat(L, -1, 1.7f);
|
||||
lua_pop(L, 1);
|
||||
|
||||
// MSAA
|
||||
lua_getfield(L, -1, "msaa");
|
||||
msaa = luaL_optinteger(L, -1, 4);
|
||||
lua_pop(L, 1);
|
||||
|
||||
// Overlay
|
||||
lua_getfield(L, -1, "overlay");
|
||||
overlay = lua_toboolean(L, -1);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
lua_pop(L, 1);
|
||||
|
||||
// Supersample
|
||||
lua_getfield(L, -1, "supersample");
|
||||
if (lua_type(L, -1) == LUA_TBOOLEAN) {
|
||||
supersample = lua_toboolean(L, -1) ? 2.f : 1.f;
|
||||
} else {
|
||||
supersample = luax_optfloat(L, -1, 1.f);
|
||||
}
|
||||
lua_pop(L, 1);
|
||||
|
||||
// Offset
|
||||
lua_getfield(L, -1, "offset");
|
||||
offset = luax_optfloat(L, -1, 1.7f);
|
||||
lua_pop(L, 1);
|
||||
|
||||
// MSAA
|
||||
lua_getfield(L, -1, "msaa");
|
||||
msaa = luaL_optinteger(L, -1, 4);
|
||||
lua_pop(L, 1);
|
||||
|
||||
// Overlay
|
||||
lua_getfield(L, -1, "overlay");
|
||||
overlay = lua_toboolean(L, -1);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
lua_pop(L, 1);
|
||||
|
||||
luax_atexit(L, lovrHeadsetDestroy); // Always make sure the headset module gets cleaned up
|
||||
lovrHeadsetInit(drivers, driverCount, supersample, offset, msaa, overlay);
|
||||
|
||||
lua_pop(L, 2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue