Skip to content

Fix asset deletion flow and async loading race conditions#72

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/refactor-asset-management-system
Draft

Fix asset deletion flow and async loading race conditions#72
Copilot wants to merge 3 commits intomainfrom
copilot/refactor-asset-management-system

Conversation

Copy link

Copilot AI commented Mar 6, 2026

Review and fix correctness issues in the asset deletion pipeline and async loading flow, covering a compile-error-level capture bug, a double-load race, missing cache eviction on deletion, and several null-deref hazards.

Async Loading (AssetManager::LoadAsset)

  • Lambda capture bug (compile error): The previous fix introduced asset->status.store(FAILED) inside a lambda whose capture list was [this, uuid, archive, deps=...]asset was never captured. Replaced with FindAsset(uuid) via the already-captured this:
    // Before — `asset` not in capture list, compile error
    if (!success) { asset->status.store(AssetBase::Status::FAILED); return; }
    
    // After
    if (!success) {
        auto failedAsset = FindAsset(uuid);
        if (failedAsset) { failedAsset->status.store(AssetBase::Status::FAILED); }
        return;
    }
  • LOADING-state race: The early-return guard only checked IsLoaded(). A concurrent second call for the same UUID would fall through, re-open the file, and queue a duplicate async task. Now short-circuits for both LOADED and LOADING.

Asset Deletion

  • AssetDataBase::RemoveAsset: Replaced SKY_ASSERT(idMap.count(id)) with a graceful iterator-based early return. After removing from the source database, now calls AssetManager::RemoveAsset(id) to keep the runtime cache consistent.
  • New AssetManager::RemoveAsset(uuid): Evicts the weak_ptr entry under the mutex, then broadcasts IAssetEvent::OnAssetReset to all registered listeners.

Misc

  • AssetManager::FindAsset lazily erases expired weak_ptr entries on lookup (marked assets map mutable to allow this in the const method).
  • Added null guards to AssetDataBase::OpenFile (both overloads) and CreateOrOpenFileGetFileSystemBySourcePath returns null for invalid bundle types.

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…system

Co-authored-by: bluesky013 <35895395+bluesky013@users.noreply.github.com>
Copilot AI changed the title [WIP] Improve asset management system functionality Fix asset system bugs and implement missing serialization paths Mar 6, 2026
Co-authored-by: bluesky013 <35895395+bluesky013@users.noreply.github.com>
Copilot AI changed the title Fix asset system bugs and implement missing serialization paths Fix asset deletion flow and async loading race conditions Mar 6, 2026
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