aajiwani / EasyNDK-for-cocos2dx

NDK is always a problem. Writing such a code that can become a breeze in connecting with other platforms is always a problem when working with cocos2dx. This repo is a step made forward to make this pain a simple step.
MIT License
171 stars 107 forks source link

Android callback empty dictionary #1

Open KirillBarkousky opened 11 years ago

KirillBarkousky commented 11 years ago

Hi, i found a bug. When creating CCDictionary from JSON object we use autorelease object. And when parameters pass to Native equriment we get empty dictionary. So i added retatin when create CCDIctionary and release in every to_be_call function.

CCObject* NDKHelper::GetCCObjectFromJson(json_t *obj) { if (obj == NULL) return NULL;

if (json_is_object(obj))
{
    CCDictionary *dictionary = CCDictionary::create();
    dictionary->retain();

.....

Log displayed issue: {"calling_method_name":"getCoins","calling_method_params":{"coins":"0","gems":"0"}} Ndk proceed key coins Ndk proceed key gems Ndk get dictionary with 2 keys getCoins call params count 0 //so we have empty dictionary NULL string NULL string

aajiwani commented 11 years ago

Hey KirillBarkousky,

First of all thanks for the bug report. I think if i will retain the dictionary in the method, i will have a non released or an orphan pointer hanging around. What i can do is, i can release the pointer outside my function where i actually make the call, but again there would be consistency issues in here. I will think of solving this bug in some other way from which i can release the memory too after the use. I will let you know.

Thanks once again for helping me out with the solution i made.

Thanks.

Amir Ali Jiwani CTO Pi Labs - http://pilabs.com

aajiwani commented 11 years ago

Hey Kirill,

I have tried to resolve the bug of having null as dictionary. Can you please check it and tell me if its now giving you the correct value or not ? Thanks.