Browse Source

Merge pull request #40163 from pycbouh/fix-saving-empty-scene

Improve scene preview generation for empty scenes and disabled features
Rémi Verschelde 5 years ago
parent
commit
b00e8ffb22
1 changed files with 13 additions and 8 deletions
  1. 13 8
      editor/editor_node.cpp

+ 13 - 8
editor/editor_node.cpp

@@ -1225,20 +1225,25 @@ void EditorNode::_save_scene_with_preview(String p_file, int p_idx) {
 
 
 		_find_node_types(editor_data.get_edited_scene_root(), c2d, c3d);
 		_find_node_types(editor_data.get_edited_scene_root(), c2d, c3d);
 
 
-		bool is2d;
-		if (c3d < c2d) {
-			is2d = true;
-		} else {
-			is2d = false;
-		}
 		save.step(TTR("Creating Thumbnail"), 1);
 		save.step(TTR("Creating Thumbnail"), 1);
 		//current view?
 		//current view?
 
 
 		Ref<Image> img;
 		Ref<Image> img;
-		if (is2d) {
+		// If neither 3D or 2D nodes are present, make a 1x1 black texture.
+		// We cannot fallback on the 2D editor, because it may not have been used yet,
+		// which would result in an invalid texture.
+		if (c3d == 0 && c2d == 0) {
+			img.instance();
+			img->create(1, 1, 0, Image::FORMAT_RGB8);
+		} else if (c3d < c2d) {
 			img = scene_root->get_texture()->get_data();
 			img = scene_root->get_texture()->get_data();
 		} else {
 		} else {
-			img = Node3DEditor::get_singleton()->get_editor_viewport(0)->get_viewport_node()->get_texture()->get_data();
+			// The 3D editor may be disabled as a feature, but scenes can still be opened.
+			// This check prevents the preview from regenerating in case those scenes are then saved.
+			Ref<EditorFeatureProfile> profile = feature_profile_manager->get_current_profile();
+			if (!profile->is_feature_disabled(EditorFeatureProfile::FEATURE_3D)) {
+				img = Node3DEditor::get_singleton()->get_editor_viewport(0)->get_viewport_node()->get_texture()->get_data();
+			}
 		}
 		}
 
 
 		if (img.is_valid()) {
 		if (img.is_valid()) {