Skip to content

fix(ocr): resolve silent OCR language not updating promptly#1047

Merged
tisfeng merged 8 commits intodevfrom
fix-silent-ocr
Jan 5, 2026
Merged

fix(ocr): resolve silent OCR language not updating promptly#1047
tisfeng merged 8 commits intodevfrom
fix-silent-ocr

Conversation

@tisfeng
Copy link
Copy Markdown
Owner

@tisfeng tisfeng commented Jan 3, 2026

This commit fixes an issue where the OCR language setting was not being updated immediately during background OCR operations.

The root cause was that background OCR was reusing the existing query model without updating the language settings from the current configuration. This led to OCR using stale language preferences.

The fix adds a new method resetQueryModelForBackgroundOCR that creates a fresh query model with the current language settings from Configuration.shared and properly rebinds all dependent managers and services. This ensures that OCR operations always use the most recent language preferences.

Fix #1040

This commit fixes an issue where the OCR language setting was not being updated immediately during background OCR operations.

The root cause was that background OCR was reusing the existing query model without updating the language settings from the current configuration. This led to OCR using stale language preferences.

The fix adds a new method `resetQueryModelForBackgroundOCR` that creates a fresh query model with the current language settings from Configuration.shared and properly rebinds all dependent managers and services. This ensures that OCR operations always use the most recent language preferences.
@tisfeng tisfeng requested review from Jerry23011 and phlpsong January 3, 2026 10:47
This commit fixes a compilation error in EZBaseQueryViewController where the Configuration class was referenced incorrectly.

The error occurred because the code was using `Configuration.shared` instead of the correct `MyConfiguration.shared` class name that was introduced during the migration from Configuration to MyConfiguration. This fix ensures the Objective-C code can properly access the configuration singleton without compilation errors.
@tisfeng tisfeng requested a review from Jerry23011 January 3, 2026 16:29
phlpsong
phlpsong previously approved these changes Jan 4, 2026
@Jerry23011
Copy link
Copy Markdown
Collaborator

Jerry23011 commented Jan 4, 2026

I can reproduce the issue in #1040 in the latest release version, it's now fixed with this PR.

But when I try 截图翻译, the app crashes. The crash doesn't happen with the release version or building on main.

The crash also happens on dev

Crash log

Signal Exception:
Signal SIGABRT was raised.
Call Stack:
1   libsystem_platform.dylib            0x000000019e323744 _sigtramp + 56
2   libsystem_pthread.dylib             0x000000019e319888 pthread_kill + 296
3   libsystem_c.dylib                   0x000000019e21e850 abort + 124
4   libc++abi.dylib                     0x000000019e2cd858 _ZN10__cxxabiv130__aligned_malloc_with_fallbackEm + 0
5   libc++abi.dylib                     0x000000019e2bc4d4 _ZL29demangling_unexpected_handlerv + 0
6   libobjc.A.dylib                     0x000000019dee8414 _ZL15_objc_terminatev + 156
7   libc++abi.dylib                     0x000000019e2ccc2c _ZSt11__terminatePFvvE + 16
8   libc++abi.dylib                     0x000000019e2d0394 __cxa_get_exception_ptr + 0
9   libc++abi.dylib                     0x000000019e2d033c _ZN10__cxxabiv1L12failed_throwEPNS_15__cxa_exceptionE + 0
10  libobjc.A.dylib                     0x000000019dede580 objc_exception_throw + 448
11  CoreFoundation                      0x000000019e420ec4 _CFBundleGetValueForInfoKey + 0
12  AppKit                              0x00000001a328830c -[NSWindow(Regions) _postWindowNeedsToResetDragMargins] + 400
13  AppKit                              0x00000001a3496394 -[NSView _setHidden:setNeedsDisplay:] + 588
14  Easydict-debug.debug.dylib          0x00000001077dee34 -[EZLoadingAnimationView stopLoadingAnimation] + 40
15  Easydict-debug.debug.dylib          0x00000001077de3ec -[EZLoadingAnimationView startLoading:] + 84
16  Easydict-debug.debug.dylib          0x000000010779fb8c -[EZQueryView startLoadingAnimation:] + 224
17  Easydict-debug.debug.dylib          0x00000001077e676c __64-[EZBaseQueryViewController startOCRImage:actionType:autoQuery:]_block_invoke + 612
18  Easydict-debug.debug.dylib          0x000000010781ccd4 __36-[EZDetectManager ocrAndDetectText:]_block_invoke + 432
19  Easydict-debug.debug.dylib          0x0000000107ac5a18 $s8Easydict12QueryServiceC3ocrySo11EZOCRResultCSgAA0B5ModelCYaKFyyYacfU_ToTQ0_ + 120
20  Easydict-debug.debug.dylib          0x0000000107ac8d99 $s8Easydict12QueryServiceC3ocrySo11EZOCRResultCSgAA0B5ModelCYaKFyyYacfU_ToTATQ0_ + 1
21  Easydict-debug.debug.dylib          0x00000001078240d1 $sIeghH_IeAgH_TRTQ0_ + 1
22  Easydict-debug.debug.dylib          0x000000010782422d $sIeghH_IeAgH_TRTATQ0_ + 1
23  Easydict-debug.debug.dylib          0x0000000107824309 $sIeAgH_ytIeAgHr_TRTQ0_ + 1
24  Easydict-debug.debug.dylib          0x000000010782446d $sIeAgH_ytIeAgHr_TRTATQ0_ + 1
25  Easydict-debug.debug.dylib          0x0000000107824c09 $sxIeAgHr_xs5Error_pIegHrzo_s8SendableRzs5NeverORs_r0_lTRyt_Tgq5TQ0_ + 1
26  Easydict-debug.debug.dylib          0x0000000107824d51 $sxIeAgHr_xs5Error_pIegHrzo_s8SendableRzs5NeverORs_r0_lTRyt_Tgq5TATQ0_ + 1
27  libswift_Concurrency.dylib          0x0000000299c072fd _ZL23completeTaskWithClosurePN5swift12AsyncContextEPNS_10SwiftErrorE + 1
threadInfo:
<NSThread: 0x830db0700>{number = 12, name = (null)}

On Xcode:

FAULT: NSInternalInconsistencyException: Modifications to the layout engine must not be performed from a background thread after it has been accessed from the main thread.; (user info absent)

libc++abi: terminating due to uncaught exception of type NSException

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Modifications to the layout engine must not be performed from a background thread after it has been accessed from the main thread.'
terminating due to uncaught exception of type NSException
Screenshot 2026-01-03 at 18 56 02

@tisfeng
Copy link
Copy Markdown
Owner Author

tisfeng commented Jan 4, 2026

ok, i see, i will fix it later.

This commit fixes a critical UI crash issue in OCR processing by ensuring all callbacks are dispatched to the main thread.

The issue occurred when OCR completion handlers were called on background threads, causing UI updates to fail with threading violations. The fix wraps the completion callback in a `dispatch_async(dispatch_get_main_queue(), ^{ ... })` block to ensure all UI-related updates happen on the main thread.

This prevents crashes that occurred when updating UI elements in response to OCR results.
@tisfeng
Copy link
Copy Markdown
Owner Author

tisfeng commented Jan 4, 2026

Since I had rewritten all the ocr api with swift async/awiat, objc calls to ocr would automatically call back to a non-main thread, and this would cause the update UI to crash.

I fixed this crash by manually calling back objc's ocr function to the main thread, fixed in 3a94d8f

@tisfeng
Copy link
Copy Markdown
Owner Author

tisfeng commented Jan 4, 2026

@Jerry23011 please check it again

Copy link
Copy Markdown
Collaborator

@Jerry23011 Jerry23011 left a comment

Choose a reason for hiding this comment

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

Both issues fixed. LGTM.

@tisfeng tisfeng merged commit a9f41dd into dev Jan 5, 2026
5 checks passed
@tisfeng tisfeng deleted the fix-silent-ocr branch January 5, 2026 07:44
@tisfeng tisfeng mentioned this pull request Jan 5, 2026
6 tasks
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.

静默截图OCR识别有误

3 participants