Skip to content

Conversation

@maerki
Copy link
Contributor

@maerki maerki commented Dec 3, 2025

No description provided.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 116 to +120
std::lock_guard<std::recursive_mutex> lock(animationMutex);
long long animationDurationMs;
{
std::lock_guard<std::recursive_mutex> lock(paramMutex);
animationDurationMs = cameraZoomConfig.animationDurationMs;

Choose a reason for hiding this comment

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

P1 Badge Align mutex locking order to avoid deadlock

The new animation-duration read in moveToCenterPositionZoom acquires animationMutex and then paramMutex, while other animated entry points such as setZoom (lines 293–300) and setRotation (lines 337–344) take paramMutex before animationMutex. If two threads call these functions concurrently, one can hold animationMutex while waiting for paramMutex and the other the reverse, producing a deadlock. Lock the mutexes in a consistent order or avoid the nested locking to keep concurrent calls safe.

Useful? React with 👍 / 👎.

Copy link
Contributor

Copilot AI left a comment

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 adds thread safety protection for the cameraZoomConfig member by consistently using paramMutex locks when accessing it. This prevents data races that could occur when the camera configuration is updated concurrently with camera operations.

Key changes:

  • Extracts animationDurationMs from cameraZoomConfig into local variables under lock before creating animations
  • Adds locks to getter methods getCameraConfig(), getCameraVerticalDisplacement(), and getCameraPitch()
  • Protects an assert statement that reads interpolation values from the config

Comment on lines 1825 to 1831
std::lock_guard<std::recursive_mutex> lock(paramMutex);
return valueForZoom(cameraZoomConfig.verticalDisplacementInterpolationValues, zoom);
}

double MapCamera3d::getCameraPitch() {
std::lock_guard<std::recursive_mutex> lock(paramMutex);
return valueForZoom(cameraZoomConfig.pitchInterpolationValues, zoom);
Copy link

Copilot AI Dec 3, 2025

Choose a reason for hiding this comment

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

The new lock added here creates unnecessary nested locking. The function updateZoom() already holds paramMutex (line 1818), but now getCameraVerticalDisplacement() and getCameraPitch() (called at lines 1820-1821) also try to acquire it.

While this is safe due to std::recursive_mutex, it's inefficient and indicates a design issue. Consider either:

  1. Making private helper versions of these functions that assume the lock is already held, OR
  2. Releasing the lock before calling these functions and re-acquiring it after

This would improve both performance and code clarity.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@copilot open a new pull request to apply changes based on this feedback

Copy link
Contributor

Copilot AI commented Dec 4, 2025

@maerki I've opened a new pull request, #894, to work on those changes. Once the pull request is ready, I'll request review from you.

@maerki maerki marked this pull request as draft December 10, 2025 09:12
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.

2 participants