Fix BillingResult ObjectDisposedException in Billing 8.0.0.1#1232
Conversation
Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
jonathanpeppers
left a comment
There was a problem hiding this comment.
This is not the appropriate fix.
-
Undo all your changes
-
Next, let's maybe take this approach instead:
public async Task<QueryPurchasesResult> QueryPurchasesAsync(QueryPurchasesParams purchasesParams)
{
var tcs = new TaskCompletionSource<QueryPurchasesResult>();
var listener = new InternalPurchasesResponseListener
{
PurchasesResponseHandler = (r, s) => tcs.TrySetResult(new QueryPurchasesResult
{
Result = r,
Purchases = s
})
};
QueryPurchases(purchasesParams, listener);
var result = await tcs.Task;
GC.KeepAlive (listener);
return result;
}- Apply this change to all places needed in
source/com.android.billingclient/billing/Additions/Additions.cs.
Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
I've implemented the requested changes:
Each method now uses Fixed in commit e3ae4b3. |
| return tcs.Task; | ||
| var result = await tcs.Task; | ||
| GC.KeepAlive(listener); | ||
| return result; |
There was a problem hiding this comment.
@tipa I think this is plausible that it could fix the ObjectDisposedException, but it seems like the old version would have had a similar issue.
The version number is unchanged, because we didn't ship it yet:
There was a problem hiding this comment.
@jonathanpeppers the problem persists - I will send you an example project for you to reproruce the crash
|
/azp run |
|
Azure Pipelines could not run because the pipeline triggers exclude this branch/path. |
|
The .nupkg here can be tested with: I believe it currently hits a build error with r8.jar. |
This PR fixes an
ObjectDisposedExceptionthat occurs when accessingBillingResult.ResponseCodeafter callingQueryProductDetailsAsyncin the Billing Client 8.0.0.1 binding.Problem
Users reported crashes when trying to access
ResponseCodefrom the result ofQueryProductDetailsAsync:The exception occurred because the native Java
BillingResultobjects were being disposed after callback completion, but the C# wrappers still held references to them:Solution
Modified all internal response listeners in
source/com.android.billingclient/billing/Additions/Additions.csto create persistent copies ofBillingResultobjects using the Builder pattern. Instead of passing the originalBillingResultreference (which may be disposed by the native side), we now create new instances with the same data:This ensures the managed objects have persistent Java references that won't be disposed unexpectedly.
Files Changed
InternalProductDetailsResponseListener(primary fix for the reported issue)InternalAcknowledgePurchaseResponseListenerInternalBillingClientStateListenerInternalConsumeResponseListenerInternalPriceChangeConfirmationListenerInternalPurchaseHistoryResponseListenerInternalPurchasesUpdatedListenerThe same issue did not occur in version 7.1.1.4, indicating this is a regression introduced in the 8.0.0 upgrade.
Fixes #1231.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.