Skip to content

Conversation

@jw098
Copy link
Collaborator

@jw098 jw098 commented Jan 19, 2026

Deadlock occurs under certain situations.
To reproduce. Run the CommandLineTests, where TEST_LIST contains "PokemonLZA/FlavorPowerScreenDetector".
Deadlock seems to trigger when PaddleOCR and Tesseract are both called by the same function. e.g. FlavorPowerDetector::detect_power, since text OCR uses Paddle and number OCR uses Tesseract.

The deadlock is "fixed" if we switch number OCR to using PaddleOCR as well.

EDIT: This should be fixed now.

// ocr_pool_lock protects the map
struct PaddleOcrGlobals{
SpinLock ocr_pool_lock; // Protects ocr_pool map.
std::map<LanguageGroup, std::shared_ptr<ML::PaddleOCRPipeline>> ocr_pool; // One instance per language.
Copy link
Collaborator

Choose a reason for hiding this comment

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

You don't need shared_ptr here since this owns the instance itself. Just stick with:
std::map<LanguageGroup, ML::PaddleOCRPipeline> ocr_pool;

Then when you construct it later on:

iter = ocr_pool.emplace(
    std::piecewise_construct,
    std::forward_as_tuple(language_group),
    std::forward_as_tuple(language)
).first;

Then you can ensure_paddle_ocr_instance() can just return ML::PaddleOCRPipeline&.

@Mysticial Mysticial merged commit 77dd02b into PokemonAutomation:main Jan 21, 2026
7 checks passed
@jw098 jw098 deleted the ocr branch January 21, 2026 18:53
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