Skip to content

Fix database update crashes and sanctifying elixir artifact scanning#593

Open
syrusgreycloak wants to merge 7 commits intoAndrewthe13th:masterfrom
syrusgreycloak:fix/defensive-mapping-checks-v1.3.17
Open

Fix database update crashes and sanctifying elixir artifact scanning#593
syrusgreycloak wants to merge 7 commits intoAndrewthe13th:masterfrom
syrusgreycloak:fix/defensive-mapping-checks-v1.3.17

Conversation

@syrusgreycloak
Copy link
Copy Markdown

Summary

This PR fixes critical issues that prevent the scanner from working with current Genshin Impact versions (6.4+):

Database Update Crash Fix

  • Problem: Database updater crashes when encountering unreleased game content (6.5.0 data)
  • Solution: Add defensive checks before accessing Mappings dictionary in UpdateCharacters, UpdateArtifacts, UpdateWeapons, UpdateMaterials
  • Impact: Updater now skips unreleased content with warnings instead of crashing, successfully saves all released content

Sanctifying Elixir Artifact Support

  • Problem: Scanner hangs indefinitely when encountering sanctified artifacts (rerolled with sanctifying elixir)
  • Root Cause: Purple indicator bar shifts card layout, causing scanner to read from wrong coordinates
  • Solution:
    • Detect sanctified artifacts using purple color range detection (handles both dark and light purple variants)
    • Apply coordinate adjustments (0.0520 for 16:9, 0.0471 for 16:10) to substats, level, and lock regions
  • Impact: Scanner can now process sanctified artifacts without hanging

OCR Timeout Improvements

  • Problem: Tesseract OCR can hang indefinitely in multithreaded environment
  • Solution: Add 30-second timeouts using Task.WhenAny() pattern for weapon and artifact processing
  • Impact: Scanner continues even if individual items time out, prevents complete application freeze

Debug Logging Enhancements

  • Added detailed logging throughout artifact scanning pipeline
  • Helps diagnose future OCR issues with specific log entries for each processing step

Testing

  • ✅ Successfully scanned 895 artifacts including sanctified ones
  • ✅ Database updates complete successfully with 6.4 released content, skips 6.5 unreleased items
  • ✅ Full inventory scan (characters, weapons, artifacts, materials) completes without crashes
  • ✅ GOOD JSON export validated and working

Compatibility

  • Based on v1.3.17 (latest release tag)
  • No breaking changes to existing functionality
  • Backwards compatible with existing installations

🤖 Generated with Claude Code

The database updater was crashing when trying to process unreleased
content (6.5.0 data) because it directly accessed the Mappings
dictionary without checking if keys existed first.

Changes:
- UpdateCharacters: Add defensive checks for character name, skill,
  and constellation hashes before accessing Mappings dictionary
- UpdateArtifacts: Add defensive check for artifact piece hashes
- UpdateWeapons and UpdateMaterials already had proper checks

This allows the updater to:
- Skip unreleased content with warnings instead of crashing
- Save all successfully processed released content (6.4)
- Complete updates successfully even when remote data contains
  unreleased items

Fixes issue where update would fail completely and roll back all
changes when encountering missing mapping keys, leaving users stuck
on outdated game data versions.
Sanctified artifacts have a purple indicator bar that shifts the visual
layout. Without this fix, the scanner hangs when processing rerolled
artifacts because bitmap coordinates are misaligned.

Changes:
- Add IsSanctified() to detect purple sanctifying indicator
- Add GetSanctifyBitmap() to extract indicator region
- Update GetSubstatsBitmap() with 0.0520 Y-shift for sanctified artifacts
- Update GetLevelBitmap() with 0.0520 Y-shift for sanctified artifacts
- Add GetArtifactLockedBitmap() with 0.0520 Y-shift for sanctified artifacts

Based on fix from Sirielia/Inventory_Kamera fork, adapted for 16:9.
Fixes hang/crash when scanning artifacts created with sanctifying elixir.
OCR worker threads were hanging indefinitely when processing problematic
artifacts, causing the entire scan to freeze. This adds timeouts and
additional debug logging to diagnose and recover from hangs.

Changes:
- Add 30-second timeout to artifact OCR processing
- Add 30-second timeout to weapon OCR processing
- Skip hung artifacts with error message instead of freezing
- Add debug logging to IsSanctified() to show color detection
- Add debug logging to bitmap extraction steps

When timeout occurs, the artifact/weapon is skipped and scanning continues
with remaining items. This prevents one problematic item from blocking the
entire scan.

Addresses issue where scanner hangs on specific artifacts during OCR
processing, particularly during substat parsing.
The sanctified purple indicator varies in brightness from dark purple
RGB(138,107,197) to light purple RGB(220,192,255). The exact color
matching with tolerance=10 was failing on light purple variants, causing
wrong coordinates and Tesseract hangs.

Changes:
- Replace exact color matching with purple range detection (B>R>G pattern)
- Check Blue channel > 150 to ensure it's purple-ish
- Switch from Task.Wait() to Task.WhenAny() for more reliable timeout
- Add debug logging for OCR start/completion

This should detect all purple variants and properly apply the coordinate
shift for sanctified artifacts, preventing OCR hangs on malformed regions.
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