Skip to content

Commit

Permalink
secret patch: gracefully shutdown bgfx on quit
Browse files Browse the repository at this point in the history
prevents segfault on exit in Linux
  • Loading branch information
PyryM committed Aug 8, 2022
1 parent 330de7d commit fafe376
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
20 changes: 15 additions & 5 deletions dist/scripts/core/core.t
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,26 @@ function truss.sleep(ms)
truss.C.sleep(ms)
end

-- gracefully quit truss with an optional error code
function truss.quit(code)
-- the true quit function
local _quit_code
local function _truss_quit()
log.info("Shutdown: calling cleanup functions")
for _, f in pairs(truss._cleanup_functions) do f() end
if code and type(code) == "number" then
truss.C.set_error(code)
log.info("Error code: [" .. tostring(code) .. "]")
if _quit_code and type(_quit_code) == "number" then
truss.C.set_error(_quit_code)
log.info("Error code: [" .. tostring(_quit_code) .. "]")
end
truss.C.stop_interpreter(TRUSS_ID)
end

-- gracefully quit truss with an optional error code
function truss.quit(code)
log.info("Shutdown requested from Lua")
_quit_code = code
_core_update = _truss_quit
_fallback_update = _truss_quit
end

-- load an entire file into memory as a string (8-bit clean)
function truss.load_string_from_file(filename)
local temp = truss.C.load_file(filename)
Expand Down
1 change: 1 addition & 0 deletions dist/scripts/gfx/common.t
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ function m.init_gfx(options)
bgfx.set_debug(debug)

log.info("initted bgfx")
truss.on_quit(bgfx.shutdown)
local backend_type = bgfx.get_renderer_type()
if options.backend and (backend_type ~= renderer_type) then
log.warn("Requested backend", options.backend, "is not available!")
Expand Down

0 comments on commit fafe376

Please sign in to comment.