Skip to content

Conversation

Dankirk
Copy link

@Dankirk Dankirk commented Oct 13, 2025

Description

  • Fix candidate for hang when opening "Captions (Experimental)" dialog from top menu.
  • Fix unnecessary caption thread restart when opening caption dialog
  • Tweak: Use proper char<->wchar encoding instead of simple type casting for locale names

When captions are enabled and the caption dialog is opened, the ui initialization in CaptionsDialog::CaptionsDialog() caused an event trigger which then restarted the caption thread. During the restart (which also happens when changing caption settings) CaptionStream::Stop() is supposed to notify/wake waiting reader thread, but the way mutex is handled in CaptionStream::Read() may cause the thread to miss the notification and then wait infinitely. Fix includes changes to mutex handling, but also adding a new stop flag to prevent calling wait() when Stop() has been called.

Additional fix for mutex handling in CaptionStream::CopyTo(), which acquired the size to copy outside of mutex lock.

There is also potential issue in mssapi_captions::main_thread() which has a busy inner loop and the stop event is checked only in an outer loop, but this seemed more unlikely to happen in practice than the above fixes. Something to keep an eye out for though.

Motivation and Context

Fixes #12626

How Has This Been Tested?

Seeking testers, since I'm unable to reproduce the original issue.

Note that since opening the dialog no longer restarts the caption thread, testing the fix should be done by changing the caption settings while the captions are enabled instead.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • Tweak (non-breaking change to improve existing functionality)

Checklist:

  • My code has been run through clang-format.
  • I have read the contributing document.
  • My code is not on the master branch.
  • The code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation.

Fixes caption thread hanging when stopping/restarting the thread and read buffer waits for more data infinitely.

Fixes usage of mutex protected caption buffer in copyTo() and Read()
Fixes caption thread restarting when dialog is opened. This was caused by setting ui state in constructor that triggered an edit event, which restarts the thread.
Use os_utf8_to_wcs_ptr() and os_wcs_to_utf8_ptr() to encode locale names instead of type cast.
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.

The 'Captions (Experimental)' menu frequently crashes when opened.

1 participant