Skip to content

Commit 7e115f6

Browse files
maloelEvgeni Raikhel
authored andcommitted
fix callback ptr from PR realsenseai#9336
1 parent 2cf11b6 commit 7e115f6

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

src/rs.cpp

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3234,12 +3234,8 @@ const rs2_raw_data_buffer* rs2_run_tare_calibration_cpp(rs2_device* device, floa
32343234

32353235
auto auto_calib = VALIDATE_INTERFACE(device->device, librealsense::auto_calibrated_interface);
32363236

3237-
std::vector<uint8_t> buffer;
32383237
std::string json((char*)json_content, (char*)json_content + content_size);
3239-
if (progress_callback == nullptr)
3240-
buffer = auto_calib->run_tare_calibration(timeout_ms, ground_truth_mm, json, nullptr);
3241-
else
3242-
buffer = auto_calib->run_tare_calibration(timeout_ms, ground_truth_mm, json, { progress_callback, [](rs2_update_progress_callback* p) { p->release(); } });
3238+
std::vector< uint8_t > buffer = auto_calib->run_tare_calibration( timeout_ms, ground_truth_mm, json, callback_ptr );
32433239

32443240
return new rs2_raw_data_buffer{ buffer };
32453241
}
@@ -3782,6 +3778,12 @@ NOEXCEPT_RETURN(, to_pixel)
37823778
const rs2_raw_data_buffer* rs2_run_focal_length_calibration_cpp(rs2_device* device, rs2_frame_queue* left, rs2_frame_queue* right, float target_w, float target_h,
37833779
int adjust_both_sides, float* ratio, float* angle, rs2_update_progress_callback * progress_callback, rs2_error** error) BEGIN_API_CALL
37843780
{
3781+
// Take ownership of the callback ASAP or else memory leaks could result if we throw! (the caller usually does a
3782+
// 'new' when calling us)
3783+
update_progress_callback_ptr callback_ptr;
3784+
if( progress_callback )
3785+
callback_ptr.reset( progress_callback, []( rs2_update_progress_callback * p ) { p->release(); } );
3786+
37853787
VALIDATE_NOT_NULL(device);
37863788
VALIDATE_NOT_NULL(left);
37873789
VALIDATE_NOT_NULL(right);
@@ -3794,11 +3796,8 @@ const rs2_raw_data_buffer* rs2_run_focal_length_calibration_cpp(rs2_device* devi
37943796
VALIDATE_RANGE(adjust_both_sides, 0, 1);
37953797

37963798
auto auto_calib = VALIDATE_INTERFACE(device->device, librealsense::auto_calibrated_interface);
3797-
std::vector<uint8_t> buffer;
3798-
if (progress_callback == nullptr)
3799-
buffer = auto_calib->run_focal_length_calibration(left, right, target_w, target_h, adjust_both_sides, ratio, angle, nullptr);
3800-
else
3801-
buffer = auto_calib->run_focal_length_calibration(left, right, target_w, target_h, adjust_both_sides, ratio, angle, { progress_callback, [](rs2_update_progress_callback* p) { p->release(); } });
3799+
std::vector< uint8_t > buffer =
3800+
auto_calib->run_focal_length_calibration( left, right, target_w, target_h, adjust_both_sides, ratio, angle, callback_ptr );
38023801

38033802
return new rs2_raw_data_buffer{ buffer };
38043803
}
@@ -3835,6 +3834,12 @@ HANDLE_EXCEPTIONS_AND_RETURN(nullptr, device, left, right, ratio, angle)
38353834
const rs2_raw_data_buffer* rs2_run_uv_map_calibration_cpp(rs2_device* device, rs2_frame_queue* left, rs2_frame_queue* color, rs2_frame_queue* depth, int py_px_only,
38363835
float* health, int health_size, rs2_update_progress_callback* progress_callback, rs2_error** error) BEGIN_API_CALL
38373836
{
3837+
// Take ownership of the callback ASAP or else memory leaks could result if we throw! (the caller usually does a
3838+
// 'new' when calling us)
3839+
update_progress_callback_ptr callback_ptr;
3840+
if( progress_callback )
3841+
callback_ptr.reset( progress_callback, []( rs2_update_progress_callback * p ) { p->release(); } );
3842+
38383843
VALIDATE_NOT_NULL(device);
38393844
VALIDATE_NOT_NULL(left);
38403845
VALIDATE_NOT_NULL(color);
@@ -3847,11 +3852,8 @@ const rs2_raw_data_buffer* rs2_run_uv_map_calibration_cpp(rs2_device* device, rs
38473852
VALIDATE_RANGE(py_px_only, 0, 1);
38483853

38493854
auto auto_calib = VALIDATE_INTERFACE(device->device, librealsense::auto_calibrated_interface);
3850-
std::vector<uint8_t> buffer;
3851-
if (progress_callback == nullptr)
3852-
buffer = auto_calib->run_uv_map_calibration(left, color, depth, py_px_only, health, health_size, nullptr);
3853-
else
3854-
buffer = auto_calib->run_uv_map_calibration(left, color, depth, py_px_only, health, health_size, { progress_callback, [](rs2_update_progress_callback* p) { p->release(); } });
3855+
std::vector< uint8_t > buffer
3856+
= auto_calib->run_uv_map_calibration( left, color, depth, py_px_only, health, health_size, callback_ptr );
38553857

38563858
return new rs2_raw_data_buffer{ buffer };
38573859
}
@@ -3889,20 +3891,20 @@ HANDLE_EXCEPTIONS_AND_RETURN(nullptr, device, left, color, depth, health)
38893891
float rs2_calculate_target_z_cpp(rs2_device* device, rs2_frame_queue* queue, float target_width, float target_height,
38903892
rs2_update_progress_callback* progress_callback, rs2_error** error) BEGIN_API_CALL
38913893
{
3894+
// Take ownership of the callback ASAP or else memory leaks could result if we throw! (the caller usually does a
3895+
// 'new' when calling us)
3896+
update_progress_callback_ptr callback_ptr;
3897+
if( progress_callback )
3898+
callback_ptr.reset( progress_callback, []( rs2_update_progress_callback * p ) { p->release(); } );
3899+
38923900
VALIDATE_NOT_NULL(device);
38933901
VALIDATE_NOT_NULL(queue);
38943902
VALIDATE_GT(target_width, 0.f);
38953903
VALIDATE_GT(target_height, 0.f);
38963904
VALIDATE_GT(rs2_frame_queue_size(queue, error), 0);
38973905

38983906
auto auto_calib = VALIDATE_INTERFACE(device->device, librealsense::auto_calibrated_interface);
3899-
3900-
if (progress_callback == NULL)
3901-
return auto_calib->calculate_target_z(queue, target_width, target_height, nullptr);
3902-
else
3903-
{
3904-
return auto_calib->calculate_target_z(queue, target_width, target_height, { progress_callback, [](rs2_update_progress_callback* p) { p->release(); } });
3905-
}
3907+
return auto_calib->calculate_target_z( queue, target_width, target_height, callback_ptr );
39063908
}
39073909
HANDLE_EXCEPTIONS_AND_RETURN(-1.f, device, queue, target_width, target_height)
39083910

0 commit comments

Comments
 (0)