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

Segmentation Fault #305

Closed
chris-cronin opened this issue Dec 25, 2016 · 2 comments
Closed

Segmentation Fault #305

chris-cronin opened this issue Dec 25, 2016 · 2 comments
Assignees
Labels
Bug.Well Shit Here we go again...
Milestone

Comments

@chris-cronin
Copy link

I'm getting a Segmentation Fault when I run the following code. I tested with a lot of different setups, but it seems once I call set_default_handler there is a fault when the program ends. I tried tracing with the debugger, but the access violation happens right as main ends and I can't find what is causing it.

I tried putting the error function in a lua script, creating it c++ and then using set_function, inlining it, lambdas....

#include <string>
#include "sol.hpp"
// the following code causes a segmentation fault.
// compiled with visual studio 2015 community debug mode.
// tested with lua51, lua5.3.3, luajit 2.0, and luajit 2.1 beta.
int main() {
	sol::state lua;
	lua.script(
		"function the_error_handler(msg)"
		"	return(msg)"
		"end"
	);
	sol::protected_function::set_default_handler(lua["the_error_handler"]);
	return 0;
}
@ThePhD ThePhD self-assigned this Dec 26, 2016
@ThePhD ThePhD added the Bug.Well Shit Here we go again... label Dec 26, 2016
@ThePhD ThePhD added this to the Bugs.Damnit milestone Dec 26, 2016
@ThePhD
Copy link
Owner

ThePhD commented Dec 26, 2016

Oops. This error is because the lua state gets destructed before the handler for it does and it dies and everything is sad.

Temporary fix on my end would be to set an empty default handler in the destructo of sol::state. It won't help people who use sol::state_view, but it should help most everyone else...

@ThePhD
Copy link
Owner

ThePhD commented Dec 26, 2016

Small temp fix that should keep sol::state users safe and okay for the most part:

https://github.com/ThePhD/sol2/blob/develop/single/sol/sol.hpp

@ThePhD ThePhD closed this as completed Dec 26, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug.Well Shit Here we go again...
Projects
None yet
Development

No branches or pull requests

2 participants