Skip to content

fix hdr bug where no depth sensor exists - #14179

Merged
Nir-Az merged 2 commits into
realsenseai:developmentfrom
AviaAv:auto-hdr
Jul 31, 2025
Merged

fix hdr bug where no depth sensor exists#14179
Nir-Az merged 2 commits into
realsenseai:developmentfrom
AviaAv:auto-hdr

Conversation

@AviaAv

@AviaAv AviaAv commented Jul 30, 2025

Copy link
Copy Markdown
Contributor

Tracked on: [RSDSO-19396]

@AviaAv
AviaAv requested a review from Copilot July 30, 2025 07:04

This comment was marked as outdated.

@AviaAv
AviaAv requested a review from Nir-Az July 30, 2025 07:04
@AviaAv
AviaAv force-pushed the auto-hdr branch 3 times, most recently from 7a6b577 to d9d1443 Compare July 30, 2025 08:54
@AviaAv
AviaAv requested a review from Copilot July 30, 2025 08:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes an HDR bug that occurs when no depth sensor is available on the device. The main issue was that the HDR model constructor was attempting to access depth sensor options without proper error handling, causing crashes when a depth sensor doesn't exist.

Key changes:

  • Added validation for HDR preset iterations to prevent invalid configurations
  • Wrapped depth sensor initialization in try-catch to handle missing depth sensors gracefully
  • Made option ranges non-const to allow initialization in the constructor body
  • Fixed format string vulnerabilities in ImGui text rendering

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
src/ds/advanced_mode/json_loader.hpp Added validation for HDR preset iterations to ensure valid range
common/hdr-model.h Changed option ranges from const to non-const to support deferred initialization
common/hdr-model.cpp Added error handling for missing depth sensors and fixed format string issues


item_header.header_size = hdr_preset::item_header::size();
item_header.iterations = static_cast<uint16_t>(std::stoi(item.at("iterations").get<std::string>()));
if( item_header.iterations <= 0 || item_header.iterations > 0xFFFF ) // not allowing 0 iterations

Copilot AI Jul 30, 2025

Copy link

Choose a reason for hiding this comment

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

The condition item_header.iterations > 0xFFFF is redundant since item_header.iterations is of type uint16_t, which can only hold values from 0 to 0xFFFF. This check will never be true.

Suggested change
if( item_header.iterations <= 0 || item_header.iterations > 0xFFFF ) // not allowing 0 iterations
if( item_header.iterations == 0 ) // not allowing 0 iterations

Copilot uses AI. Check for mistakes.
Comment thread common/hdr-model.cpp

auto text_gain = _is_auto ? "Gain Delta" : "Gain Value:";
ImGui::Text( text_gain );
auto text_gain = _is_auto ? "Gain Delta:" : "Gain Value:";

Copilot AI Jul 30, 2025

Copy link

Choose a reason for hiding this comment

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

Missing space after 'Delta' - should be 'Gain Delta: ' to match the pattern used for 'Gain Value:'

Suggested change
auto text_gain = _is_auto ? "Gain Delta:" : "Gain Value:";
auto text_gain = _is_auto ? "Gain Delta: " : "Gain Value:";

Copilot uses AI. Check for mistakes.
Comment thread common/hdr-model.cpp Outdated
@@ -306,7 +317,7 @@ void hdr_model::render_control_item( hdr_preset::control_item & control)
control.depth_gain = (int)clamp((float)g, _gain_range.min, _gain_range.max);

auto text_exp = _is_auto ? "Exposure Delta" : "Exposure Value:";

Copilot AI Jul 30, 2025

Copy link

Choose a reason for hiding this comment

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

Missing colon after 'Delta' - should be 'Exposure Delta:' to match the pattern used for 'Exposure Value:'

Suggested change
auto text_exp = _is_auto ? "Exposure Delta" : "Exposure Value:";
auto text_exp = _is_auto ? "Exposure Delta:" : "Exposure Value:";

Copilot uses AI. Check for mistakes.
Comment thread common/hdr-model.cpp Outdated
catch( const rs2::error & e )
{
_hdr_supported = false;
LOG_ERROR( "Failed to initialize HDR model: " << e.what() );

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LOG_DEBUG

@AviaAv
AviaAv requested a review from Nir-Az July 31, 2025 08:56
@Nir-Az
Nir-Az merged commit be4ae39 into realsenseai:development Jul 31, 2025
25 of 26 checks passed
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.

3 participants