-
Notifications
You must be signed in to change notification settings - Fork 59
Fix BillingResult ObjectDisposedException in Billing 8.0.0.1 #1232
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jonathanpeppers the problem persists - I will send you an example project for you to reproruce the crash
This PR fixes an
ObjectDisposedException
that occurs when accessingBillingResult.ResponseCode
after callingQueryProductDetailsAsync
in the Billing Client 8.0.0.1 binding.Problem
Users reported crashes when trying to access
ResponseCode
from the result ofQueryProductDetailsAsync
:The exception occurred because the native Java
BillingResult
objects 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.cs
to create persistent copies ofBillingResult
objects using the Builder pattern. Instead of passing the originalBillingResult
reference (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)InternalAcknowledgePurchaseResponseListener
InternalBillingClientStateListener
InternalConsumeResponseListener
InternalPriceChangeConfirmationListener
InternalPurchaseHistoryResponseListener
InternalPurchasesUpdatedListener
The 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.