Skip to content

fix: cv::imencode 添加异常保护,防止触发 save_on_error 时崩溃#19

Open
ocsin1 wants to merge 1 commit into
MaaXYZ:masterfrom
ocsin1:fix/Imagelo
Open

fix: cv::imencode 添加异常保护,防止触发 save_on_error 时崩溃#19
ocsin1 wants to merge 1 commit into
MaaXYZ:masterfrom
ocsin1:fix/Imagelo

Conversation

@ocsin1

@ocsin1 ocsin1 commented Jul 13, 2026

Copy link
Copy Markdown

cv::imencode 在特定情况下会直接抛出 cv::Exception 而不是返回 false,
导致调用方 imwrite() 无法通过返回值处理错误, 异常穿透到 std::terminate
使进程崩溃。

崩溃定位: opencv_world4_maa!cv::imencodeWithMetadata+0x1017,
说明参数校验已通过, 是 PNG 编码内部的 CV_Assert 失败。

本提交为暂缓措施——try/catch 捕获异常并输出 code/msg/img_type
等诊断信息后返回 false, 防止进程崩溃。cv::imencode 内部失败
的根因尚未确定, 需要通过日志中的错误码进一步排查。

Summary by Sourcery

ImageIo::imwrite 中为 cv::imencode 添加异常处理,以防止进程崩溃,并在编码失败时记录诊断信息。

Bug 修复:

  • 防止在写入图像时,由于来自 cv::imencode 的未捕获 cv::Exception 以及其他异常导致的崩溃。

功能增强:

  • cv::imencode 因异常失败时,记录详细的错误信息(OpenCV 错误代码、消息、函数、文件、行号以及图像扩展名)。
Original summary in English

Summary by Sourcery

Add exception handling around cv::imencode in ImageIo::imwrite to prevent process crashes and log diagnostic information when encoding fails.

Bug Fixes:

  • Prevent crashes caused by uncaught cv::Exception and other exceptions thrown from cv::imencode during image writing.

Enhancements:

  • Log detailed error information (OpenCV error code, message, function, file, line and image extension) when cv::imencode fails with an exception.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - 我已经审阅了你的更改,看起来很棒!


Sourcery 对开源项目是免费的——如果你觉得我们的评审有帮助,欢迎分享 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续评审。
Original comment in English

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant