Skip to content

Commit 7471ac2

Browse files
committed
Merge pull request #81543 from DarioSamo/lightmap-size-crash-fix
Propagate error correctly when max texture size for lightmaps is too small.
2 parents 64fce49 + 7dfb854 commit 7471ac2

File tree

4 files changed

+11
-1
lines changed

4 files changed

+11
-1
lines changed

doc/classes/LightmapGI.xml

+3
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@
118118
<constant name="BAKE_ERROR_USER_ABORTED" value="8" enum="BakeError">
119119
The user aborted the lightmap baking operation (typically by clicking the [b]Cancel[/b] button in the progress dialog).
120120
</constant>
121+
<constant name="BAKE_ERROR_TEXTURE_SIZE_TOO_SMALL" value="9" enum="BakeError">
122+
Lightmap baking failed as the maximum texture size is too small to fit some of the meshes marked for baking.
123+
</constant>
121124
<constant name="ENVIRONMENT_MODE_DISABLED" value="0" enum="EnvironmentMode">
122125
Ignore environment lighting when baking lightmaps.
123126
</constant>

editor/plugins/lightmap_gi_editor_plugin.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ void LightmapGIEditorPlugin::_bake_select_file(const String &p_file) {
103103
case LightmapGI::BAKE_ERROR_FOREIGN_DATA: {
104104
EditorNode::get_singleton()->show_warning(TTR("Lightmap data is not local to the scene."));
105105
} break;
106+
case LightmapGI::BAKE_ERROR_TEXTURE_SIZE_TOO_SMALL: {
107+
EditorNode::get_singleton()->show_warning(TTR("Maximum texture size is too small for the lightmap images."));
108+
} break;
106109
default: {
107110
} break;
108111
}

scene/3d/lightmap_gi.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -1082,7 +1082,9 @@ LightmapGI::BakeError LightmapGI::bake(Node *p_from_node, String p_image_data_pa
10821082

10831083
Lightmapper::BakeError bake_err = lightmapper->bake(Lightmapper::BakeQuality(bake_quality), use_denoiser, bounces, bias, max_texture_size, directional, Lightmapper::GenerateProbes(gen_probes), environment_image, environment_transform, _lightmap_bake_step_function, &bsud, exposure_normalization);
10841084

1085-
if (bake_err == Lightmapper::BAKE_ERROR_LIGHTMAP_CANT_PRE_BAKE_MESHES) {
1085+
if (bake_err == Lightmapper::BAKE_ERROR_LIGHTMAP_TOO_SMALL) {
1086+
return BAKE_ERROR_TEXTURE_SIZE_TOO_SMALL;
1087+
} else if (bake_err == Lightmapper::BAKE_ERROR_LIGHTMAP_CANT_PRE_BAKE_MESHES) {
10861088
return BAKE_ERROR_MESHES_INVALID;
10871089
}
10881090

@@ -1566,6 +1568,7 @@ void LightmapGI::_bind_methods() {
15661568
BIND_ENUM_CONSTANT(BAKE_ERROR_MESHES_INVALID);
15671569
BIND_ENUM_CONSTANT(BAKE_ERROR_CANT_CREATE_IMAGE);
15681570
BIND_ENUM_CONSTANT(BAKE_ERROR_USER_ABORTED);
1571+
BIND_ENUM_CONSTANT(BAKE_ERROR_TEXTURE_SIZE_TOO_SMALL);
15691572

15701573
BIND_ENUM_CONSTANT(ENVIRONMENT_MODE_DISABLED);
15711574
BIND_ENUM_CONSTANT(ENVIRONMENT_MODE_SCENE);

scene/3d/lightmap_gi.h

+1
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ class LightmapGI : public VisualInstance3D {
132132
BAKE_ERROR_MESHES_INVALID,
133133
BAKE_ERROR_CANT_CREATE_IMAGE,
134134
BAKE_ERROR_USER_ABORTED,
135+
BAKE_ERROR_TEXTURE_SIZE_TOO_SMALL,
135136
};
136137

137138
enum EnvironmentMode {

0 commit comments

Comments
 (0)