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

Crash when trying to export without a project #92606

Closed
KoBeWi opened this issue May 31, 2024 · 6 comments · Fixed by #95005
Closed

Crash when trying to export without a project #92606

KoBeWi opened this issue May 31, 2024 · 6 comments · Fixed by #95005

Comments

@KoBeWi
Copy link
Member

KoBeWi commented May 31, 2024

Tested versions

4.3 beta1 and earlier

System information

Windows 10.0.19045 - Vulkan (Forward+) - dedicated NVIDIA GeForce GTX 1060 (NVIDIA; 31.0.15.4633) - Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz (8 Threads)

Issue description

When exporting from empty folder, the engine crashes:

CrashHandlerException: Program crashed
Engine version: Godot Engine v4.3.beta.custom_build (705b7a0b0bd535c95e4e8fb439f3d84b3fb4f427)
Dumping the backtrace. Please include this when reporting the bug to the project developer.
[0] EditorSettings::create (C:\godot_source\editor\editor_settings.cpp:1061)
[1] EditorNode::EditorNode (C:\godot_source\editor\editor_node.cpp:6429)
[2] Main::start (C:\godot_source\main\main.cpp:3706)
[3] widechar_main (C:\godot_source\platform\windows\godot_windows.cpp:179)
[4] _main (C:\godot_source\platform\windows\godot_windows.cpp:206)
[5] main (C:\godot_source\platform\windows\godot_windows.cpp:220)
[6] WinMain (C:\godot_source\platform\windows\godot_windows.cpp:234)
[7] __scrt_common_main_seh (D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288)
[8] <couldn't map PC to fn name>
-- END OF BACKTRACE --

The culprit seems to be this code:

godot/main/main.cpp

Lines 1770 to 1783 in 705b7a0

if (globals->setup(project_path, main_pack, upwards, editor) == OK) {
#ifdef TOOLS_ENABLED
found_project = true;
#endif
} else {
#ifdef TOOLS_ENABLED
editor = false;
#else
const String error_msg = "Error: Couldn't load project data at path \"" + project_path + "\". Is the .pck file missing?\nIf you've renamed the executable, the associated .pck file should also be renamed to match the executable's name (without the extension).\n";
OS::get_singleton()->print("%s", error_msg.utf8().get_data());
OS::get_singleton()->alert(error_msg);
goto error;
#endif

If the project is found, everything works normally.
If it's not found:

  • in non-editor build go to error and abort
  • in editor build, disable editor and continue normally... 🤦‍♂️

So it continues and tries to do editor stuff without editor hint. The above crash happens in editorless EditorNode, which can't create EditorSettings, because it's not in editor. There is a variation of this crash that happens in EditorFileSystem, which tries doing filesystem scan.

Steps to reproduce

Run godot --headless --export-release "anything" in an empty folder (no project.godot).
If you omit "anything" you'll get a different crash.

Minimal reproduction project (MRP)

New folder.zip

@akien-mga
Copy link
Member

akien-mga commented May 31, 2024

Duplicate of #91527, or the other way around, whichever is clearer.

With several reports on dev 6 / beta 1, is that a recent regression?

@KoBeWi
Copy link
Member Author

KoBeWi commented May 31, 2024

The comments in #91527 are unrelated to the original issue, which doesn't involve any crash. They are 2 separate bugs.

@RealMadvicius
Copy link
Contributor

If you look at this section

singleton = ResourceLoader::load(config_file_path, "EditorSettings");
singleton->set_path(get_newest_settings_path()); // Settings can be loaded from older version file, so make sure it's newest.
if (singleton.is_null()) {
ERR_PRINT("Could not load editor settings from path: " + config_file_path);
goto fail;
}
singleton->save_changed_setting = true;

You can see that we call singleton->set_path before checking if "singleton" is null, which lead to some "undefined behaviour". To improve things, we should have the if (singleton.is_null()) done just after the call to singleton = ResourceLoader::load.

Same thing here :

godot/main/main.cpp

Lines 3704 to 3709 in 96a386f

for (const String &path : paths) {
Ref<GDScript> gdscript = ResourceLoader::load(path);
for (const DocData::ClassDoc &class_doc : gdscript->get_documentation()) {
docs.add_doc(class_doc);
}
}

We call gdscript->get_documentation() without checking if gdscript isnt a null pointer which can lead to crash aswell potentially

@jsjtxietian
Copy link
Contributor

jsjtxietian commented Jun 5, 2024

You can see that we call singleton->set_path before checking if "singleton" is null, which lead to some "undefined behaviour". To improve things, we should have the if (singleton.is_null()) done just after the call to singleton = ResourceLoader::load.

Yes I noticed this nullptr too.

IMHO culprit is here, it will set the editor flag not matter what.

else if (E->get() == "--export-release") {
	editor = true; //needs editor
	_export_preset = E->next()->get();
} else if (E->get() == "--export-debug") {
	editor = true; //needs editor
	_export_preset = E->next()->get();
	export_debug = true;
} else if (E->get() == "--export-pack") {
	editor = true;
	_export_preset = E->next()->get();
	export_pack_only = true;

I also has crash here, f is null :

String extension_list_config_file = GDExtension::get_extension_list_config_file();
if (extensions.size()) {
	if (extensions_added.size() || extensions_removed.size()) { //extensions were added or removed
		Ref<FileAccess> f = FileAccess::open(extension_list_config_file, FileAccess::WRITE);
		for (const String &E : extensions) {
			f->store_line(E);
		}
	}
}

@KoBeWi
Copy link
Member Author

KoBeWi commented Jul 31, 2024

The crash was fixed by #94593. Now exporting results in some errors:

ERROR: Class 'EditorSettings' can only be instantiated by editor.
   at: _instantiate_internal (core/object/class_db.cpp:521)
ERROR: Could not load editor settings from path: C:/Users/Tomek/AppData/Roaming/Godot/editor_settings-4.3.tres
   at: create (editor/editor_settings.cpp:1067)
ERROR: Cannot save project metadata to file 'res://.godot/editor/project_metadata.cfg'.
   at: (editor/editor_settings.cpp:1326)
ERROR: Cannot create file 'res://.godot/editor/filesystem_cache8'. Check user write permissions.
   at: (editor/editor_file_system.cpp:418)
ERROR: This project doesn't have an `export_presets.cfg` file at its root.
Create an export preset from the "Project > Export" dialog and try again.
   at: _fs_changed (editor/editor_node.cpp:1028)

None of them really tell what's the problem, so maybe we could detect this and print a proper error.

@KoBeWi KoBeWi removed the crash label Jul 31, 2024
@jsjtxietian
Copy link
Contributor

jsjtxietian commented Aug 1, 2024

With godot --headless --export-release I still get a crash:

================================================================
CrashHandlerException: Program crashed
Engine version: Godot Engine v4.3.rc.custom_build (3978628c6cc1227250fc6ed45c8d854d24c30c30)
Dumping the backtrace. Please include this when reporting the bug to the project developer.
[0] EditorFileSystem::doing_first_scan (E:\godot\editor\editor_file_system.h:341)
[1] EditorFileSystem::doing_first_scan (E:\godot\editor\editor_file_system.h:341)
[2] Main::iteration (E:\godot\main\main.cpp:4192)
[3] OS_Windows::run (E:\godot\platform\windows\os_windows.cpp:1666)
[4] widechar_main (E:\godot\platform\windows\godot_windows.cpp:181)
[5] _main (E:\godot\platform\windows\godot_windows.cpp:206)
[6] main (E:\godot\platform\windows\godot_windows.cpp:220)
[7] WinMain (E:\godot\platform\windows\godot_windows.cpp:234)
[8] __scrt_common_main_seh (D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288)
[9] <couldn't map PC to fn name>
-- END OF BACKTRACE --
================================================================

I think part pf my pr #92783 can solve the unclear log when exporting with godot --headless --export-release "anything",

With it the log looks like

ERROR: Please provide a valid project path when exporting, aborting.
   at: (main\main.cpp:3336)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment