Skip to content

Skip null resources when restoring repository entries - #5799

Merged
alex-dev-neo merged 1 commit into
r5.4from
fix/resources-cache-null-entries-r5.4
Sep 16, 2026
Merged

alex-dev-neo merged 1 commit into
r5.4from
fix/resources-cache-null-entries-r5.4

Conversation

@alex-dev-neo

Copy link
Copy Markdown
Contributor

prepareData rebuilds the region cache incrementally. When a resource that was local or outdated is gone from the fresh scan, the else branch restores its repository entry so the region shows it as downloadable again:

regionResources.allResources.insert(resource->id, _resourcesInRepository.value(resource->id));

QHash::value returns a default-constructed shared_ptr when the key is absent, so an id that is no longer in the repository stores a null pointer in allResources. Every reader of the region cache dereferences its entries unconditionally — collectSubregionItemsFromRegularRegion does resource_->type on each one — so the null is dereferenced on a later pass, not at the insertion site.

Two ways to reach it: a catalog refresh drops an id that is still installed locally, and rescanUnmanagedStoragePaths puts imported .obf files into the local resources, which by definition have no repository entry.

Insert the entry only when the repository actually has it.

Scope

Deliberately minimal for the release branch: two call sites, no behaviour change when the value is non-null, no locking, no perf impact.

The same area has a separate synchronization problem — the region cache is static but its lock is a per-instance ivar, and four external +prepareData callers bypass it, one of them on a background queue. That belongs in master on top of #5765, which makes a lock across prepareData cheap; it is not in this PR.

Testing

Not built or run — build verification is left to the maintainer. The change is a null check on the value returned by QHash::value before storing it.

When a local or outdated resource is removed, prepareData restores its
repository entry so the region shows it as downloadable. The lookup uses
QHash::value, which returns a null pointer when the id is not in the
repository, and that null was stored in the region cache. Readers of the
cache dereference every entry, so the crash surfaced later, in
collectSubregionItemsFromRegularRegion rather than here.

Insert the entry only when the repository actually has it.
@alex-dev-neo
alex-dev-neo merged commit f257899 into r5.4 Sep 16, 2026
@alex-dev-neo
alex-dev-neo deleted the fix/resources-cache-null-entries-r5.4 branch September 16, 2026 12:29
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.

1 participant