Fix: GPv3: Empty grease pencil object crash
The `bounds` is `nullopt` when the number of points is 0 at current frame. The fix uses `value_or()` to make sure we get some bounds. Also uses `Bounds<float3>` instead of `std::optional<Bounds<float3>>` in `gpencil_object_cache_add`. Pull Request: https://projects.blender.org/blender/blender/pulls/119690
This commit is contained in:
committed by
Falk David
parent
12d34fed91
commit
bc74bbef0b
@@ -40,7 +40,7 @@
|
||||
GPENCIL_tObject *gpencil_object_cache_add(GPENCIL_PrivateData *pd,
|
||||
Object *ob,
|
||||
const bool is_stroke_order_3d,
|
||||
const std::optional<blender::Bounds<float3>> bounds)
|
||||
const blender::Bounds<float3> bounds)
|
||||
{
|
||||
using namespace blender;
|
||||
GPENCIL_tObject *tgp_ob = static_cast<GPENCIL_tObject *>(BLI_memblock_alloc(pd->gp_object_pool));
|
||||
@@ -69,8 +69,8 @@ GPENCIL_tObject *gpencil_object_cache_add(GPENCIL_PrivateData *pd,
|
||||
* 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. */
|
||||
float3 size = (bounds->max - bounds->min) * 0.5f;
|
||||
float3 center = math::midpoint(bounds->min, bounds->max);
|
||||
float3 size = (bounds.max - bounds.min) * 0.5f;
|
||||
float3 center = math::midpoint(bounds.min, bounds.max);
|
||||
/* Convert bbox to matrix */
|
||||
float mat[4][4];
|
||||
unit_m4(mat);
|
||||
|
||||
@@ -327,7 +327,7 @@ struct GpencilBatchCache *gpencil_batch_cache_get(struct Object *ob, int cfra);
|
||||
GPENCIL_tObject *gpencil_object_cache_add(GPENCIL_PrivateData *pd,
|
||||
Object *ob,
|
||||
bool is_stroke_order_3d,
|
||||
std::optional<blender::Bounds<float3>> bounds);
|
||||
blender::Bounds<float3> bounds);
|
||||
void gpencil_object_cache_sort(GPENCIL_PrivateData *pd);
|
||||
|
||||
GPENCIL_tLayer *gpencil_layer_cache_add(GPENCIL_PrivateData *pd,
|
||||
|
||||
@@ -567,7 +567,7 @@ static void gpencil_sbuffer_cache_populate_fast(GPENCIL_Data *vedata, gpIterPopu
|
||||
GPUTexture *depth_texture = iter->pd->scene_depth_tx;
|
||||
GPENCIL_tObject *last_tgp_ob = iter->pd->tobjects.last;
|
||||
/* Create another temp object that only contain the stroke. */
|
||||
const std::optional<blender::Bounds<float3>> bounds = BKE_gpencil_data_minmax(gpd).value_or(
|
||||
const blender::Bounds<float3> bounds = BKE_gpencil_data_minmax(gpd).value_or(
|
||||
blender::Bounds(float3(0)));
|
||||
iter->tgp_ob = gpencil_object_cache_add(
|
||||
iter->pd, iter->ob, (gpd->draw_mode == GP_DRAWMODE_3D), bounds);
|
||||
@@ -610,7 +610,8 @@ static GPENCIL_tObject *grease_pencil_object_cache_populate(GPENCIL_PrivateData
|
||||
using namespace blender::bke::greasepencil;
|
||||
GreasePencil &grease_pencil = *static_cast<GreasePencil *>(ob->data);
|
||||
const bool is_vertex_mode = (ob->mode & OB_MODE_VERTEX_PAINT) != 0;
|
||||
const std::optional<blender::Bounds<float3>> bounds = grease_pencil.bounds_min_max_eval();
|
||||
const blender::Bounds<float3> bounds = grease_pencil.bounds_min_max_eval().value_or(
|
||||
blender::Bounds(float3(0)));
|
||||
|
||||
const bool use_stroke_order_3d = (grease_pencil.flag & GREASE_PENCIL_STROKE_ORDER_3D) != 0;
|
||||
GPENCIL_tObject *tgp_ob = gpencil_object_cache_add(pd, ob, use_stroke_order_3d, bounds);
|
||||
@@ -803,7 +804,7 @@ void GPENCIL_cache_populate(void *ved, Object *ob)
|
||||
|
||||
if (ob->data && (ob->type == OB_GPENCIL_LEGACY) && (ob->dt >= OB_SOLID)) {
|
||||
bGPdata *gpd = (bGPdata *)ob->data;
|
||||
const std::optional<blender::Bounds<float3>> bounds = BKE_gpencil_data_minmax(gpd).value_or(
|
||||
const blender::Bounds<float3> bounds = BKE_gpencil_data_minmax(gpd).value_or(
|
||||
blender::Bounds(float3(0)));
|
||||
gpIterPopulateData iter = {nullptr};
|
||||
iter.ob = ob;
|
||||
|
||||
Reference in New Issue
Block a user