Fix #126605: GPv3: Crash exporting selected frames to PDF

Crash when exporting selected frames due to two different reason.
frame returned by frame_at() can be null, so add a null check
before calling `is_selected()` member function.

After depsgraph update, ob_eval.data changes. So cast it to gease_pencil
every frame to avoid the crash (otherwise grease_pencil will point to
invalid memory).

Pull Request: https://projects.blender.org/blender/blender/pulls/126643
This commit is contained in:
Pratik Borhade
2024-08-22 13:38:45 +02:00
committed by Pratik Borhade
parent 3a6a953662
commit b0390cae09

View File

@@ -59,7 +59,7 @@ static bool is_selected_frame(const GreasePencil &grease_pencil, const int frame
for (const bke::greasepencil::Layer *layer : grease_pencil.layers()) {
if (layer->is_visible()) {
const GreasePencilFrame *frame = layer->frame_at(frame_number);
if (frame->is_selected()) {
if ((frame != nullptr) && (frame->is_selected())) {
return true;
}
}
@@ -71,7 +71,6 @@ bool PDFExporter::export_scene(Scene &scene, StringRefNull filepath)
{
bool result = false;
Object &ob_eval = *DEG_get_evaluated_object(context_.depsgraph, params_.object);
GreasePencil &grease_pencil = *static_cast<GreasePencil *>(ob_eval.data);
if (!create_document()) {
return false;
@@ -92,6 +91,7 @@ bool PDFExporter::export_scene(Scene &scene, StringRefNull filepath)
const bool only_selected = (params_.frame_mode == ExportParams::FrameMode::Selected);
const int orig_frame = scene.r.cfra;
for (int frame_number = scene.r.sfra; frame_number <= scene.r.efra; frame_number++) {
GreasePencil &grease_pencil = *static_cast<GreasePencil *>(ob_eval.data);
if (only_selected && !is_selected_frame(grease_pencil, frame_number)) {
continue;
}