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

Using print_line from the destructor of a tool class in a GDNative library crashes Godot on exit #37417

Open
Zylann opened this issue Mar 29, 2020 · 0 comments

Comments

@Zylann
Copy link
Contributor

Zylann commented Mar 29, 2020

Godot 3.2.1
Windows 10 64 bits

I made an editor plugin which instanciates a C++ NativeScript (GDNative) to speed up some things. This class inherits Reference and gets freed when Godot quits.
As I often do to debug some of my classes, I used Godot::print in the destructor of that class. It gets destroyed when my editor plugin gets destroyed, because it is stored in one of its member variables.
However, this causes Godot to crash on exit.

The call stack to this is unbelievably long. It starts from the scene tree destroying its root, which goes to predelete the EditorNode (the one in GDCLASS), gets to destroy my plugin (I guess?), which destroys the class, which prints, goes to EditorNode::_print_handler, and leads to the RichTextLabel of the editor... which was freed already.
It looks like the print handler is not being told that the console output has been freed and still references a dangling pointer?
Indeed, print_handler is only removed in ~EditorNode, but ~EditorNode has not been called yet.

void EditorNode::_print_handler(void *p_this, const String &p_string, bool p_error) {
	EditorNode *en = (EditorNode *)p_this;
	en->log->add_message(p_string, p_error ? EditorLog::MSG_TYPE_ERROR : EditorLog::MSG_TYPE_STD);
}

This print handler should be setup and deinitialized by EditorLog, not EditorNode.

image

This is happening in a large plugin and making a simple one means going through a lot of steps (and only for Windows) so I don't have a simple test project at the moment.

However, reproduction steps with this project are simple:
http://zylannprods.fr/dl/godot/gdnative_hterrain_repro_crash_on_exit.zip
On Windows, just launch the editor on this project, with debugger attached, and close it.
This project contains a precompiled debug dll compiled with msvc.

@Zylann Zylann changed the title Using print_line from the destructor of a class in a GDNative library crashes Godot on exit Using print_line from the destructor of a tool class in a GDNative library crashes Godot on exit Mar 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants