Cleanup: Resolve const correctness in grease pencil API
It was possible to access a mutable drawing from a const GreasePencil object. This sort of mistake is possible because DNA requires using raw pointers.
This commit is contained in:
@@ -741,7 +741,7 @@ inline const blender::bke::greasepencil::LayerGroup &GreasePencilLayerTreeGroup:
|
||||
return *reinterpret_cast<const blender::bke::greasepencil::LayerGroup *>(this);
|
||||
}
|
||||
|
||||
inline GreasePencilDrawingBase *GreasePencil::drawings(int64_t index) const
|
||||
inline const GreasePencilDrawingBase *GreasePencil::drawings(int64_t index) const
|
||||
{
|
||||
return this->drawings()[index];
|
||||
}
|
||||
|
||||
@@ -675,11 +675,11 @@ GeometryDeformation get_evaluated_grease_pencil_drawing_deformation(const Object
|
||||
BLI_assert(ob_orig.type == OB_GREASE_PENCIL);
|
||||
const GreasePencil &grease_pencil_orig = *static_cast<const GreasePencil *>(ob_orig.data);
|
||||
|
||||
GreasePencilDrawingBase *drawing_base = grease_pencil_orig.drawings(drawing_index);
|
||||
const GreasePencilDrawingBase *drawing_base = grease_pencil_orig.drawings(drawing_index);
|
||||
|
||||
GeometryDeformation deformation;
|
||||
if (drawing_base->type == GP_DRAWING) {
|
||||
GreasePencilDrawing *drawing = reinterpret_cast<GreasePencilDrawing *>(drawing_base);
|
||||
const auto *drawing = reinterpret_cast<const GreasePencilDrawing *>(drawing_base);
|
||||
/* Use the undeformed positions by default. */
|
||||
deformation.positions = drawing->wrap().strokes().positions();
|
||||
}
|
||||
|
||||
@@ -1235,10 +1235,9 @@ Material *BKE_grease_pencil_object_material_ensure_by_name(Main *bmain,
|
||||
static bool grease_pencil_references_cyclic_check_internal(const GreasePencil *id_reference,
|
||||
const GreasePencil *grease_pencil)
|
||||
{
|
||||
for (GreasePencilDrawingBase *base : grease_pencil->drawings()) {
|
||||
for (const GreasePencilDrawingBase *base : grease_pencil->drawings()) {
|
||||
if (base->type == GP_DRAWING_REFERENCE) {
|
||||
GreasePencilDrawingReference *reference = reinterpret_cast<GreasePencilDrawingReference *>(
|
||||
base);
|
||||
const auto *reference = reinterpret_cast<const GreasePencilDrawingReference *>(base);
|
||||
if (id_reference == reference->id_reference) {
|
||||
return true;
|
||||
}
|
||||
@@ -1331,7 +1330,7 @@ template<typename T> static void shrink_array(T **array, int *num, const int shr
|
||||
*num = new_array_num;
|
||||
}
|
||||
|
||||
blender::Span<GreasePencilDrawingBase *> GreasePencil::drawings() const
|
||||
blender::Span<const GreasePencilDrawingBase *> GreasePencil::drawings() const
|
||||
{
|
||||
return blender::Span<GreasePencilDrawingBase *>{this->drawing_array, this->drawing_array_num};
|
||||
}
|
||||
@@ -1516,7 +1515,8 @@ static void remove_drawings_unchecked(GreasePencil &grease_pencil,
|
||||
}
|
||||
}
|
||||
/* Swap the pointers to the drawings in the drawing array. */
|
||||
std::swap(grease_pencil.drawings()[index_to_remove], grease_pencil.drawings()[swap_index]);
|
||||
std::swap(grease_pencil.drawing_array[index_to_remove],
|
||||
grease_pencil.drawing_array[swap_index]);
|
||||
next_available_index--;
|
||||
}
|
||||
|
||||
@@ -1620,7 +1620,7 @@ void GreasePencil::move_duplicate_frames(
|
||||
}
|
||||
|
||||
blender::bke::greasepencil::Drawing *GreasePencil::get_editable_drawing_at(
|
||||
const blender::bke::greasepencil::Layer *layer, const int frame_number) const
|
||||
const blender::bke::greasepencil::Layer *layer, const int frame_number)
|
||||
{
|
||||
if (layer == nullptr || !layer->is_editable()) {
|
||||
return nullptr;
|
||||
@@ -1694,7 +1694,7 @@ static void foreach_drawing_ex(
|
||||
{
|
||||
using namespace blender::bke::greasepencil;
|
||||
|
||||
blender::Span<GreasePencilDrawingBase *> drawings = grease_pencil.drawings();
|
||||
blender::Span<const GreasePencilDrawingBase *> drawings = grease_pencil.drawings();
|
||||
for (const Layer *layer : grease_pencil.layers()) {
|
||||
switch (mode) {
|
||||
case VISIBLE: {
|
||||
|
||||
@@ -430,9 +430,9 @@ typedef struct GreasePencil {
|
||||
blender::bke::greasepencil::LayerGroup &root_group();
|
||||
|
||||
/* Drawings read/write access. */
|
||||
blender::Span<GreasePencilDrawingBase *> drawings() const;
|
||||
blender::Span<const GreasePencilDrawingBase *> drawings() const;
|
||||
blender::MutableSpan<GreasePencilDrawingBase *> drawings();
|
||||
GreasePencilDrawingBase *drawings(int64_t index) const;
|
||||
const GreasePencilDrawingBase *drawings(int64_t index) const;
|
||||
GreasePencilDrawingBase *drawings(int64_t index);
|
||||
|
||||
blender::Span<const blender::bke::greasepencil::TreeNode *> nodes() const;
|
||||
@@ -538,7 +538,7 @@ typedef struct GreasePencil {
|
||||
* drawing exists.
|
||||
*/
|
||||
blender::bke::greasepencil::Drawing *get_editable_drawing_at(
|
||||
const blender::bke::greasepencil::Layer *layer, int frame_number) const;
|
||||
const blender::bke::greasepencil::Layer *layer, int frame_number);
|
||||
|
||||
void foreach_visible_drawing(
|
||||
const int frame,
|
||||
|
||||
Reference in New Issue
Block a user