Skip to content

Commit 3e28932

Browse files
committed
Merge pull request #109116 from WhalesState/scene-preview-headless
Prevent generating Editor 3D scene preview in headless mode.
2 parents 901065b + 7066017 commit 3e28932

File tree

3 files changed

+6
-13
lines changed

3 files changed

+6
-13
lines changed

editor/editor_interface.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,12 @@ Vector<Ref<Texture2D>> EditorInterface::make_mesh_previews(const Vector<Ref<Mesh
230230
}
231231

232232
void EditorInterface::make_scene_preview(const String &p_path, Node *p_scene, int p_preview_size) {
233-
ERR_FAIL_NULL_MSG(p_scene, "The provided scene is null.");
233+
if (!Engine::get_singleton()->is_editor_hint() || !DisplayServer::get_singleton()->window_can_draw()) {
234+
return;
235+
}
236+
ERR_FAIL_COND_MSG(p_path.is_empty(), "Path is empty, cannot generate preview.");
237+
ERR_FAIL_NULL_MSG(p_scene, "The provided scene is null, cannot generate preview.");
234238
ERR_FAIL_COND_MSG(p_scene->is_inside_tree(), "The scene must not be inside the tree.");
235-
ERR_FAIL_COND_MSG(!Engine::get_singleton()->is_editor_hint(), "This function can only be called from the editor.");
236239
ERR_FAIL_NULL_MSG(EditorNode::get_singleton(), "EditorNode doesn't exist.");
237240

238241
SubViewport *sub_viewport_node = memnew(SubViewport);

editor/import/3d/resource_importer_scene.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2963,15 +2963,6 @@ void ResourceImporterScene::_optimize_track_usage(AnimationPlayer *p_player, Ani
29632963
}
29642964
}
29652965

2966-
void ResourceImporterScene::_generate_editor_preview_for_scene(const String &p_path, Node *p_scene) {
2967-
if (!Engine::get_singleton()->is_editor_hint()) {
2968-
return;
2969-
}
2970-
ERR_FAIL_COND_MSG(p_path.is_empty(), "Path is empty, cannot generate preview.");
2971-
ERR_FAIL_NULL_MSG(p_scene, "Scene is null, cannot generate preview.");
2972-
EditorInterface::get_singleton()->make_scene_preview(p_path, p_scene, 1024);
2973-
}
2974-
29752966
Node *ResourceImporterScene::pre_import(const String &p_source_file, const HashMap<StringName, Variant> &p_options) {
29762967
Ref<EditorSceneFormatImporter> importer;
29772968
String ext = p_source_file.get_extension().to_lower();
@@ -3359,7 +3350,7 @@ Error ResourceImporterScene::import(ResourceUID::ID p_source_id, const String &p
33593350
print_verbose("Saving scene to: " + p_save_path + ".scn");
33603351
err = ResourceSaver::save(packer, p_save_path + ".scn", flags); //do not take over, let the changed files reload themselves
33613352
ERR_FAIL_COND_V_MSG(err != OK, err, "Cannot save scene to file '" + p_save_path + ".scn'.");
3362-
_generate_editor_preview_for_scene(p_source_file, scene);
3353+
EditorInterface::get_singleton()->make_scene_preview(p_source_file, scene, 1024);
33633354
} else {
33643355
ERR_FAIL_V_MSG(ERR_FILE_UNRECOGNIZED, "Unknown scene import type: " + _scene_import_type);
33653356
}

editor/import/3d/resource_importer_scene.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,6 @@ class ResourceImporterScene : public ResourceImporter {
232232
};
233233

234234
void _optimize_track_usage(AnimationPlayer *p_player, AnimationImportTracks *p_track_actions);
235-
void _generate_editor_preview_for_scene(const String &p_path, Node *p_scene);
236235

237236
String _scene_import_type = "PackedScene";
238237

0 commit comments

Comments
 (0)