From 86f9be758fe81b5119c6d1ada935ab72ce1c52d1 Mon Sep 17 00:00:00 2001 From: Ingvar Stepanyan Date: Fri, 23 Jul 2021 19:22:34 +0000 Subject: [PATCH] Fix context error handler This can be called deep in the gphoto2 callstack, and throwing here would prevent proper C cleanup. Instead, just log an error here and rely on status values higher up in the APIs to throw actual C++ errors. --- api.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/api.cpp b/api.cpp index 0625ff3..9294e80 100644 --- a/api.cpp +++ b/api.cpp @@ -20,8 +20,8 @@ void gpp_try(int status) { } } -void gpp_error(GPContext *context, const char *text, void *data) { - throw std::runtime_error(text); +void gpp_log_error(GPContext *context, const char *text, void *data) { + std::cerr << text << std::endl; } #define GPP_CALL(RET, EXPR) \ @@ -55,7 +55,7 @@ class Context { gpp_rethrow([=]() { camera.reset(GPP_CALL(Camera *, gp_camera_new(_))); context.reset(gp_context_new()); - gp_context_set_error_func(context.get(), gpp_error, nullptr); + gp_context_set_error_func(context.get(), gpp_log_error, nullptr); gpp_try(gp_camera_init(camera.get(), context.get())); }); }