lovr.graphics.isInitialized;

Returns whether the graphics module is initialized.  Used by the default
error handler to know if it's safe to try to render the error screen.
This commit is contained in:
bjorn 2022-11-07 19:12:11 -08:00
parent 5e2b44ad08
commit 36e1471cf0
4 changed files with 15 additions and 1 deletions

View File

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

View File

@ -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 },

View File

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

View File

@ -96,6 +96,7 @@ enum {
bool lovrGraphicsInit(GraphicsConfig* config);
void lovrGraphicsDestroy(void);
bool lovrGraphicsIsInitialized(void);
void lovrGraphicsGetDevice(GraphicsDevice* device);
void lovrGraphicsGetFeatures(GraphicsFeatures* features);