Fixed crash if buying when no listener was set

This commit is contained in:
Björn Ritzl 2020-02-10 08:25:48 +01:00
parent c8d2d4e0d8
commit 8d9ea79d7d
3 changed files with 15 additions and 3 deletions

View File

@ -244,6 +244,12 @@ JNIEXPORT void JNICALL Java_com_defold_iap_IapJNI_onPurchaseResult__ILjava_lang_
static void HandleProductResult(const IAPCommand* cmd) static void HandleProductResult(const IAPCommand* cmd)
{ {
if (cmd->m_Callback == 0)
{
dmLogWarning("Received product list but no listener was set!");
return;
}
lua_State* L = dmScript::GetCallbackLuaContext(cmd->m_Callback); lua_State* L = dmScript::GetCallbackLuaContext(cmd->m_Callback);
int top = lua_gettop(L); int top = lua_gettop(L);
@ -289,6 +295,12 @@ static void HandleProductResult(const IAPCommand* cmd)
static void HandlePurchaseResult(const IAPCommand* cmd) static void HandlePurchaseResult(const IAPCommand* cmd)
{ {
if (cmd->m_Callback == 0)
{
dmLogWarning("Received purchase result but no listener was set!");
return;
}
lua_State* L = dmScript::GetCallbackLuaContext(cmd->m_Callback); lua_State* L = dmScript::GetCallbackLuaContext(cmd->m_Callback);
int top = lua_gettop(L); int top = lua_gettop(L);

View File

@ -67,7 +67,7 @@ public class IapGooglePlay implements Handler.Callback {
private boolean autoFinishTransactions; private boolean autoFinishTransactions;
private static interface ISkuRequestListener { private static interface ISkuRequestListener {
public void onProducts(int resultCode, JSONObject products); public void onProducts(int resultCode, JSONObject products);
} }
private static class SkuRequest { private static class SkuRequest {

View File

@ -69,8 +69,8 @@ public class IapGooglePlayActivity extends Activity {
} }
private void buy(String product, String productType) { private void buy(String product, String productType) {
// Flush any pending items, in order to be able to buy the same (new) product again // Flush any pending items, in order to be able to buy the same (new) product again
processPendingConsumables(); processPendingConsumables();
try { try {
Bundle buyIntentBundle = service.getBuyIntent(3, getPackageName(), product, productType, ""); Bundle buyIntentBundle = service.getBuyIntent(3, getPackageName(), product, productType, "");