Skip to content

Commit e2ef0e7

Browse files
committed
Merge pull request godotengine#82408 from hpvb/fix-import-crash
Fix Image import crash
2 parents ef3a6e0 + a82704d commit e2ef0e7

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

core/io/image.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1930,8 +1930,7 @@ Error Image::generate_mipmaps(bool p_renormalize) {
19301930
}
19311931

19321932
Error Image::generate_mipmap_roughness(RoughnessChannel p_roughness_channel, const Ref<Image> &p_normal_map) {
1933-
Vector<double> normal_sat_vec; //summed area table
1934-
double *normal_sat = nullptr; //summed area table for normal map
1933+
LocalVector<double> normal_sat_vec; //summed area table
19351934
int normal_w = 0, normal_h = 0;
19361935

19371936
ERR_FAIL_COND_V_MSG(p_normal_map.is_null() || p_normal_map->is_empty(), ERR_INVALID_PARAMETER, "Must provide a valid normal map for roughness mipmaps");
@@ -1945,8 +1944,7 @@ Error Image::generate_mipmap_roughness(RoughnessChannel p_roughness_channel, con
19451944
normal_h = nm->get_height();
19461945

19471946
normal_sat_vec.resize(normal_w * normal_h * 3);
1948-
1949-
normal_sat = normal_sat_vec.ptrw();
1947+
double *normal_sat = normal_sat_vec.ptr();
19501948

19511949
//create summed area table
19521950

@@ -2021,24 +2019,26 @@ Error Image::generate_mipmap_roughness(RoughnessChannel p_roughness_channel, con
20212019
avg[2] += normal_sat[tofs + 2];
20222020
}
20232021

2024-
if (from_y > 0) {
2022+
if (from_y > 0 && to_x > 0) {
20252023
uint32_t tofs = ((from_y - 1) * normal_w + to_x) * 3;
20262024
avg[0] -= normal_sat[tofs + 0];
20272025
avg[1] -= normal_sat[tofs + 1];
20282026
avg[2] -= normal_sat[tofs + 2];
20292027
}
20302028

2031-
if (from_x > 0) {
2029+
if (from_x > 0 && to_y > 0) {
20322030
uint32_t tofs = (to_y * normal_w + (from_x - 1)) * 3;
20332031
avg[0] -= normal_sat[tofs + 0];
20342032
avg[1] -= normal_sat[tofs + 1];
20352033
avg[2] -= normal_sat[tofs + 2];
20362034
}
20372035

2038-
uint32_t tofs = (to_y * normal_w + to_x) * 3;
2039-
avg[0] += normal_sat[tofs + 0];
2040-
avg[1] += normal_sat[tofs + 1];
2041-
avg[2] += normal_sat[tofs + 2];
2036+
if (to_y > 0 && to_x > 0) {
2037+
uint32_t tofs = (to_y * normal_w + to_x) * 3;
2038+
avg[0] += normal_sat[tofs + 0];
2039+
avg[1] += normal_sat[tofs + 1];
2040+
avg[2] += normal_sat[tofs + 2];
2041+
}
20422042

20432043
double div = double(size_x * size_y);
20442044
Vector3 vec(avg[0] / div, avg[1] / div, avg[2] / div);

0 commit comments

Comments
 (0)