diff --git a/etc/boot.lua b/etc/boot.lua index 34d2925e..3be2d23d 100644 --- a/etc/boot.lua +++ b/etc/boot.lua @@ -167,7 +167,9 @@ function lovr.errhand(message) message = tostring(message) .. formatTraceback(debug.traceback('', 4)) print('Error:\n' .. message) - if not lovr.graphics then return function() return 1 end end + if not lovr.graphics or not lovr.graphics.isInitialized() then + return function() return 1 end + end if lovr.audio then lovr.audio.stop() end diff --git a/src/api/l_graphics.c b/src/api/l_graphics.c index 59e484b5..3651385d 100644 --- a/src/api/l_graphics.c +++ b/src/api/l_graphics.c @@ -682,6 +682,12 @@ static int l_lovrGraphicsInitialize(lua_State* L) { return 0; } +static int l_lovrGraphicsIsInitialized(lua_State* L) { + bool initialized = lovrGraphicsIsInitialized(); + lua_pushboolean(L, initialized); + return 1; +} + static int l_lovrGraphicsSubmit(lua_State* L) { bool table = lua_istable(L, 1); int length = table ? luax_len(L, 1) : lua_gettop(L); @@ -1492,6 +1498,7 @@ static int l_lovrGraphicsGetPass(lua_State* L) { static const luaL_Reg lovrGraphics[] = { { "initialize", l_lovrGraphicsInitialize }, + { "isInitialized", l_lovrGraphicsIsInitialized }, { "submit", l_lovrGraphicsSubmit }, { "present", l_lovrGraphicsPresent }, { "wait", l_lovrGraphicsWait }, diff --git a/src/modules/graphics/graphics.c b/src/modules/graphics/graphics.c index b11abc88..848c7a4a 100644 --- a/src/modules/graphics/graphics.c +++ b/src/modules/graphics/graphics.c @@ -741,6 +741,10 @@ void lovrGraphicsDestroy() { memset(&state, 0, sizeof(state)); } +bool lovrGraphicsIsInitialized() { + return state.initialized; +} + void lovrGraphicsGetDevice(GraphicsDevice* device) { device->deviceId = state.device.deviceId; device->vendorId = state.device.vendorId; diff --git a/src/modules/graphics/graphics.h b/src/modules/graphics/graphics.h index 41a13e9f..345451b5 100644 --- a/src/modules/graphics/graphics.h +++ b/src/modules/graphics/graphics.h @@ -96,6 +96,7 @@ enum { bool lovrGraphicsInit(GraphicsConfig* config); void lovrGraphicsDestroy(void); +bool lovrGraphicsIsInitialized(void); void lovrGraphicsGetDevice(GraphicsDevice* device); void lovrGraphicsGetFeatures(GraphicsFeatures* features);