Skip to content

Fix access violation bug - #14173

Merged
Nir-Az merged 3 commits into
realsenseai:developmentfrom
AviaAv:quick-close-bug
Aug 3, 2025
Merged

Fix access violation bug#14173
Nir-Az merged 3 commits into
realsenseai:developmentfrom
AviaAv:quick-close-bug

Conversation

@AviaAv

@AviaAv AviaAv commented Jul 29, 2025

Copy link
Copy Markdown
Contributor

Tracked on: [LRS-1316]

@AviaAv
AviaAv requested a review from Nir-Az July 29, 2025 08:24
@Nir-Az

Nir-Az commented Jul 29, 2025

Copy link
Copy Markdown
Collaborator

Please check GHA CI failures

@Nir-Az
Nir-Az requested review from OhadMeir and Copilot and removed request for Nir-Az July 29, 2025 11:57

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 access violation bug by properly managing the lifetime of an initialization thread in the platform_camera class. The issue was caused by a detached thread that could potentially access destroyed object members after the platform_camera object was destroyed.

  • Replaces detached thread with a managed thread that can be properly joined on destruction
  • Adds early termination capability for the initialization process using an atomic flag
  • Refactors option registration from individual calls to a loop-based approach

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/platform-camera.h Adds destructor declaration, thread member variable, and atomic stop flag
src/platform-camera.cpp Implements proper thread management and early termination logic in initialization
Comments suppressed due to low confidence (1)

src/platform-camera.h:30

  • [nitpick] The variable name 'should_stop' uses snake_case which is inconsistent with the existing codebase style. Consider renaming to '_should_stop' or 'shouldStop' to match the naming convention used for '_init_thread'.
    std::atomic< bool > should_stop{ false };  // to avoid delay when closing and _init_thread is still running

Comment thread src/platform-camera.cpp Outdated
RS2_OPTION_WHITE_BALANCE,
RS2_OPTION_ENABLE_AUTO_EXPOSURE,
RS2_OPTION_ENABLE_AUTO_WHITE_BALANCE };
for (auto option : options)

Copilot AI Jul 29, 2025

Copy link

Choose a reason for hiding this comment

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

[nitpick] The loop variable 'option' should be passed by const reference to avoid unnecessary copying of the enum value. Change to 'for (const auto& option : options)' or 'for (auto option : options)' is fine since rs2_option is likely a simple enum, but consistency with modern C++ practices suggests using const auto&.

Suggested change
for (auto option : options)
for (const auto& option : options)

Copilot uses AI. Check for mistakes.

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.

@AviaAv why not taking co pilot advise here? seems like a valid comment

@Nir-Az
Nir-Az merged commit 418553f into realsenseai:development Aug 3, 2025
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.

4 participants