Skip to content

Harden reload-time label/ref recheck against stale document pointers#4564

Draft
sunderme with Copilot wants to merge 4 commits into
masterfrom
copilot/fix-crash-reloading-files
Draft

Harden reload-time label/ref recheck against stale document pointers#4564
sunderme with Copilot wants to merge 4 commits into
masterfrom
copilot/fix-crash-reloading-files

Conversation

Copilot AI commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Reloads after external file changes could traverse document lists containing stale/invalid LatexDocument*, leading to crashes while calling labelItems() during structure/reference refresh. This change adds pointer-validity gating in the reload/recheck paths.

  • Root cause containment: stale pointer filtering

    • Added a local helper to derive the current active-document set from LatexDocuments.
    • Before invoking labelItems() / recheckRefsLabels(), skip null pointers and pointers not present in the active set.
  • Applied in all relevant traversal paths

    • LatexDocument::setMasterDocument(..., recheck=true)
    • LatexDocument::recheckRefsLabels(...) (auto list/item aggregation branch)
    • LatexDocuments::addDocsToLoad(...) (post-load syntax/ref refresh)
  • Implementation notes

    • Consolidated duplicated validation logic via availableDocumentSet(...).
    • Switched affected loops to explicit range-based iteration for clearer pointer filtering semantics.
const QSet<LatexDocument *> availableDocs = availableDocumentSet(parent);
for (LatexDocument *elem : qAsConst(listOfDocs)) {
    if (!elem || !availableDocs.contains(elem)) continue;
    items << elem->labelItems();
}

Copilot AI changed the title [WIP] Fix crash when reloading files after change by another program Harden reload-time label/ref recheck against stale document pointers Jul 23, 2026
Copilot AI requested a review from sunderme July 23, 2026 06:39
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.

Crash when reloading files after change by another program.

2 participants