From 6f916a001c2d2f23c275db13375f080556a6b28f Mon Sep 17 00:00:00 2001 From: MediaPipe Team Date: Mon, 31 Jul 2023 10:18:06 -0700 Subject: [PATCH] Fix crash in SavePngTestOutput Do not call SavePngTestOutput in CompareAndSaveImageOutput in case diff_img is null. This can happen if for instance the expected and the actual image have non-matching format or size. Currently, this crashes. Support single channel golden images. PiperOrigin-RevId: 552519834 --- mediapipe/framework/tool/test_util.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mediapipe/framework/tool/test_util.cc b/mediapipe/framework/tool/test_util.cc index 64b5072c..5e712ecf 100644 --- a/mediapipe/framework/tool/test_util.cc +++ b/mediapipe/framework/tool/test_util.cc @@ -228,7 +228,9 @@ absl::Status CompareAndSaveImageOutput( auto status = CompareImageFrames(**expected, actual, options.max_color_diff, options.max_alpha_diff, options.max_avg_diff, diff_img); - ASSIGN_OR_RETURN(auto diff_img_path, SavePngTestOutput(*diff_img, "diff")); + if (diff_img) { + ASSIGN_OR_RETURN(auto diff_img_path, SavePngTestOutput(*diff_img, "diff")); + } return status; }