Repository navigation
Background Assets: fix EnsureLocalAvailability never completing on success - #127
Open
petarkarov wants to merge 1 commit into
Open
petarkarov wants to merge 1 commit into
petarkarov wants to merge 1 commit into
Conversation
The native local_ensure* functions only invoked the completion handler on failure, so on a successful download the C# side's semaphore was never released: EnsureLocalAvailabilityOfAssetPack(s)Async hung forever and leaked the marshalled context. Invoke the handler with baw_res_kind_success once ensureLocalAvailability returns, using a new static, empty baw_err.none as the unused error value. Also make EnsureLocalAvailabilityOfAssetPacksAsync return Task instead of void, as its documentation describes, so callers can await it and catch its errors.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
AssetPackManager.EnsureLocalAvailabilityOfAssetPackAsync(...)andEnsureLocalAvailabilityOfAssetPacksAsync(...)never return when the download succeeds.The native wrappers
baw_assetpackmanager_assetpack_local_ensure,_local_ensure_updateand_local_ensure_updatevonly invoke the completion handler in thecatchblock. On success the handler is never called, so the C# side'sSemaphoreSlimis never released. Theawaithangs forever and theAllocHGlobal'd context is leaked.Failures are reported correctly. Only the success path is affected.
Separately,
EnsureLocalAvailabilityOfAssetPacksAsyncis declaredasync void, although its documentation says it returns a task. Callers can't await it or catch its errors.Fix
AssetPackManager.swift: callcompletionHandler(.none, baw_res_kind_success, contextPointer)afterensureLocalAvailabilityreturns, in all threelocal_ensure*functions.Error.swift: addbaw_err.none, a static empty error used as the unused error value on success. It's marked_static, sobaw_err_deinitnever tries to free it.AssetPackManager.cs: changeEnsureLocalAvailabilityOfAssetPacksAsyncfromasync voidtoasync Task, matching its doc comment and the single-pack versions.The C# callback already handles
baw_res_kind_success(it releases the semaphore and leaves the error unset), so no other C# changes are needed.Notes
RemoveAssetPackAsync(baw_assetpackmanager_assetpack_remove) andReconcilePreferredLanguages(baw_assetpackmanager_lang_reconcile) have the same missing success callback. They are left out to keep this PR focused, and I'm happy to fix them here or in a follow-up.