Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to lily.quit() on love.errorhandler? #5

Closed
gphg opened this issue May 29, 2023 · 6 comments
Closed

how to lily.quit() on love.errorhandler? #5

gphg opened this issue May 29, 2023 · 6 comments

Comments

@gphg
Copy link

gphg commented May 29, 2023

I managed to get lily quit on love.quit callback by following code:

function love.quit()
	local lily = package['lily'] or package['libs.lily'] or package['path.to.lily'] or nil
	if lily then 
		lily.quit()
	end
end

But how to do it on love.errorhandler. Without it, an usual error if lily.quit() is not called popped out after the error message displayed and program quited.

AL lib: (EE) alc_cleanup: 1 device not closed
@gphg
Copy link
Author

gphg commented May 29, 2023

I somehow managed to get it right without completely rewrite the errorhandler.

-- cache the function
local old_errorhandler = love.errorhandler
function love.errorhandler(msg)
	-- quit lily before original errorhandler get called
	local lily = package['lily'] or package['libs.lily'] or package['path.to.lily'] or nil
	if lily then 
		lily.quit()
	end
	-- call original cached errorhandler function
	old_errorhandler(msg)
end

@gphg gphg closed this as completed May 29, 2023
@gphg
Copy link
Author

gphg commented May 29, 2023

Above solution doesn't work. On unexpected error, the program simply quits without tell any error. I had to uncomment it.

@gphg gphg reopened this May 29, 2023
@banepwn
Copy link

banepwn commented May 29, 2023

love.errorhandler is supposed to return a function. When detouring it, you need to make sure your function returns the same values as the old one. Do return old_errorhandler(msg).

@gphg
Copy link
Author

gphg commented May 29, 2023

I debug it, and it seems the old errorhandler is nil.
image

Updated:
I'm on latest stable version. And it is love.errhand, not love.errorhandler. But the wiki page says otherwise. :/

-- Something like this:
local old_errorhandler = love.errorhandler or love.errhand
function love.errorhandler(msg)
	lilyQuit() -- a defined function somewhere to call lily.quit
	return old_errorhandler(msg)
end

@banepwn
Copy link

banepwn commented May 29, 2023

That's because LÖVE's default error handler is actually in love.errhand. In the event of an error, LÖVE will check if love.errorhandler exists first, and then love.errhand if it doesn't, then a third inaccessible function if neither exist.

@gphg
Copy link
Author

gphg commented May 29, 2023

image
https://love2d.org/wiki/love.errhand
image

Closing this issue.

@gphg gphg closed this as completed May 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants