fix hdr bug where no depth sensor exists - #14179
Conversation
7a6b577 to
d9d1443
Compare
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
| if( item_header.iterations <= 0 || item_header.iterations > 0xFFFF ) // not allowing 0 iterations | |
| if( item_header.iterations == 0 ) // not allowing 0 iterations |
|
|
||
| auto text_gain = _is_auto ? "Gain Delta" : "Gain Value:"; | ||
| ImGui::Text( text_gain ); | ||
| auto text_gain = _is_auto ? "Gain Delta:" : "Gain Value:"; |
There was a problem hiding this comment.
Missing space after 'Delta' - should be 'Gain Delta: ' to match the pattern used for 'Gain Value:'
| auto text_gain = _is_auto ? "Gain Delta:" : "Gain Value:"; | |
| auto text_gain = _is_auto ? "Gain Delta: " : "Gain Value:"; |
| @@ -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:"; | |||
There was a problem hiding this comment.
Missing colon after 'Delta' - should be 'Exposure Delta:' to match the pattern used for 'Exposure Value:'
| auto text_exp = _is_auto ? "Exposure Delta" : "Exposure Value:"; | |
| auto text_exp = _is_auto ? "Exposure Delta:" : "Exposure Value:"; |
| catch( const rs2::error & e ) | ||
| { | ||
| _hdr_supported = false; | ||
| LOG_ERROR( "Failed to initialize HDR model: " << e.what() ); |
Tracked on: [RSDSO-19396]