Do not use os.exit to exit the application

Properly quit the application by terminating the core.run()
function. Otherwise a BadWindow event was happening when
closing the window.
This commit is contained in:
Francesco Abbate 2021-08-27 00:17:43 +02:00
parent daf916769f
commit 456f6eda65
1 changed files with 3 additions and 2 deletions

View File

@ -494,6 +494,7 @@ function core.init()
core.redraw = true core.redraw = true
core.visited_files = {} core.visited_files = {}
core.restart_request = false core.restart_request = false
core.quit_request = false
core.replacements = whitespace_replacements() core.replacements = whitespace_replacements()
core.root_view = RootView() core.root_view = RootView()
@ -632,7 +633,7 @@ local function quit_with_function(quit_fn, force)
end end
function core.quit(force) function core.quit(force)
quit_with_function(os.exit, force) quit_with_function(function() core.quit_request = true end, force)
end end
@ -1032,7 +1033,7 @@ function core.run()
core.frame_start = system.get_time() core.frame_start = system.get_time()
local did_redraw = core.step() local did_redraw = core.step()
local need_more_work = run_threads() local need_more_work = run_threads()
if core.restart_request then break end if core.restart_request or core.quit_request then break end
if not did_redraw and not need_more_work then if not did_redraw and not need_more_work then
idle_iterations = idle_iterations + 1 idle_iterations = idle_iterations + 1
-- do not wait of events at idle_iterations = 1 to give a chance at core.step to run -- do not wait of events at idle_iterations = 1 to give a chance at core.step to run