Fix: Protect against access of empty geometry bounds optional

This commit is contained in:
Hans Goudey
2023-12-06 09:12:02 -05:00
parent 79ed05b29f
commit 79552f87f2
7 changed files with 24 additions and 20 deletions

View File

@@ -25,6 +25,7 @@
#include "BLI_math_matrix.h"
#include "BLI_math_rotation.h"
#include "BLI_math_vector.h"
#include "BLI_math_vector.hh"
#include "BLI_math_vector_types.hh"
#include "BLI_polyfill_2d.h"
#include "BLI_span.hh"
@@ -115,10 +116,9 @@ std::optional<blender::Bounds<blender::float3>> BKE_gpencil_data_minmax(const bG
void BKE_gpencil_centroid_3d(bGPdata *gpd, float r_centroid[3])
{
const blender::Bounds<blender::float3> bounds = *BKE_gpencil_data_minmax(gpd);
const float3 tot = bounds.min + bounds.max;
mul_v3_v3fl(r_centroid, tot, 0.5f);
using namespace blender;
const Bounds<float3> bounds = BKE_gpencil_data_minmax(gpd).value_or(Bounds(float3(0)));
copy_v3_v3(r_centroid, math::midpoint(bounds.min, bounds.max));
}
void BKE_gpencil_stroke_boundingbox_calc(bGPDstroke *gps)

View File

@@ -790,7 +790,7 @@ void BKE_mesh_texspace_calc(Mesh *me)
using namespace blender;
if (me->texspace_flag & ME_TEXSPACE_FLAG_AUTO) {
const Bounds<float3> bounds = me->bounds_min_max().value_or(
Bounds<float3>{float3(-1.0f), float3(1.0f)});
Bounds(float3(-1.0f), float3(1.0f)));
float texspace_location[3], texspace_size[3];
mid_v3_v3v3(texspace_location, bounds.min, bounds.max);

View File

@@ -114,6 +114,7 @@ void EEVEE_shadows_cache_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata)
void EEVEE_shadows_caster_register(EEVEE_ViewLayerData *sldata, Object *ob)
{
using namespace blender;
EEVEE_LightsInfo *linfo = sldata->lights;
EEVEE_ShadowCasterBuffer *backbuffer = linfo->shcaster_backbuffer;
EEVEE_ShadowCasterBuffer *frontbuffer = linfo->shcaster_frontbuffer;
@@ -155,7 +156,7 @@ void EEVEE_shadows_caster_register(EEVEE_ViewLayerData *sldata, Object *ob)
}
/* Update World AABB in frontbuffer. */
const blender::Bounds<blender::float3> bounds = *BKE_object_boundbox_get(ob);
const Bounds<float3> bounds = BKE_object_boundbox_get(ob).value_or(Bounds(float3(0)));
BoundBox bb;
BKE_boundbox_init_from_minmax(&bb, bounds.min, bounds.max);
float min[3], max[3];

View File

@@ -949,7 +949,7 @@ GridAABB VolumePipeline::grid_aabb_from_object(Object *ob)
return int3(grid_coords * float3(data.tex_size) + 0.5);
};
const Bounds<float3> bounds = *BKE_object_boundbox_get(ob);
const Bounds<float3> bounds = BKE_object_boundbox_get(ob).value_or(Bounds(float3(0)));
int3 min = int3(INT32_MAX);
int3 max = int3(INT32_MIN);

View File

@@ -23,6 +23,7 @@
#include "BLI_hash.h"
#include "BLI_link_utils.h"
#include "BLI_math_color.h"
#include "BLI_math_vector.hh"
#include "BLI_memblock.h"
#include "gpencil_engine.h"
@@ -37,6 +38,7 @@
GPENCIL_tObject *gpencil_object_cache_add(GPENCIL_PrivateData *pd, Object *ob)
{
using namespace blender;
bGPdata *gpd = (bGPdata *)ob->data;
GPENCIL_tObject *tgp_ob = static_cast<GPENCIL_tObject *>(BLI_memblock_alloc(pd->gp_object_pool));
@@ -64,13 +66,12 @@ GPENCIL_tObject *gpencil_object_cache_add(GPENCIL_PrivateData *pd, Object *ob)
* strokes not aligned with the object axes. Maybe we could try to
* compute the minimum axis of all strokes. But this would be more
* computationally heavy and should go into the GPData evaluation. */
const blender::Bounds<blender::float3> bounds = *BKE_gpencil_data_minmax(gpd);
BoundBox bb;
BKE_boundbox_init_from_minmax(&bb, bounds.min, bounds.max);
const std::optional<Bounds<float3>> bounds = BKE_gpencil_data_minmax(gpd).value_or(
Bounds(float3(0)));
float3 size = bounds->max - bounds->min;
float3 center = math::midpoint(bounds->min, bounds->max);
/* Convert bbox to matrix */
float mat[4][4], size[3], center[3];
BKE_boundbox_calc_size_aabb(&bb, size);
BKE_boundbox_calc_center_aabb(&bb, center);
float mat[4][4];
unit_m4(mat);
copy_v3_v3(mat[3], center);
/* Avoid division by 0.0 later. */

View File

@@ -364,7 +364,7 @@ static void OVERLAY_bounds(OVERLAY_ExtraCallBuffers *cb,
}
const Bounds<float3> bounds = BKE_object_boundbox_get(ob).value_or(
Bounds<float3>{float3(-1.0f), float3(1.0f)});
Bounds(float3(-1.0f), float3(1.0f)));
float3 size = bounds.max - bounds.min;
const float3 center = around_origin ? float3(0) : math::midpoint(bounds.min, bounds.max);

View File

@@ -6,6 +6,8 @@
* \ingroup draw_engine
*/
#include "BLI_math_vector.hh"
#include "DRW_render.h"
#include "BKE_global.h"
@@ -22,6 +24,7 @@
/* Returns the normal plane in NDC space. */
static void gpencil_depth_plane(Object *ob, float r_plane[4])
{
using namespace blender;
/* TODO: put that into private data. */
float viewinv[4][4];
DRW_view_viewmat_get(nullptr, viewinv, true);
@@ -33,13 +36,12 @@ static void gpencil_depth_plane(Object *ob, float r_plane[4])
* strokes not aligned with the object axes. Maybe we could try to
* compute the minimum axis of all strokes. But this would be more
* computationally heavy and should go into the GPData evaluation. */
const blender::Bounds<blender::float3> bounds = *BKE_object_boundbox_get(ob);
BoundBox bb;
BKE_boundbox_init_from_minmax(&bb, bounds.min, bounds.max);
const std::optional<Bounds<float3>> bounds = BKE_object_boundbox_get(ob).value_or(
Bounds(float3(0)));
float3 size = bounds->max - bounds->min;
float3 center = math::midpoint(bounds->min, bounds->max);
/* Convert bbox to matrix */
float mat[4][4], size[3], center[3];
BKE_boundbox_calc_size_aabb(&bb, size);
BKE_boundbox_calc_center_aabb(&bb, center);
float mat[4][4];
unit_m4(mat);
copy_v3_v3(mat[3], center);
/* Avoid division by 0.0 later. */