C++ クラスに facebook ログインを実装しようとしています。Java から、ユーザーの Facebook 情報を取得しようとしています。すべてが Java から C++ に正しく渡されます。
ただし、このコードのコメントを外すと、アプリケーションがシグナル 11 でクラッシュします (他の同様の回答によると、メモリの問題はこちら)。
JNIEXPORT void JNICALL Java_com_humit_android_HumIt_javaCallJNI(JNIEnv* env, jobject obj,
jstring javaString1, jstring javaString2, jstring javaString3)
{
//Get the native string from javaString
const char *nativeString1 = env->GetStringUTFChars(javaString1, 0);
const char *nativeString2 = env->GetStringUTFChars(javaString2, 0);
const char *nativeString3 = env->GetStringUTFChars(javaString3, 0);
// 以下の 2 行でエラーが発生しています... コメントしても問題ありません...!
LoginScreen * loginScreen = new LoginScreen();
loginScreen->facebookProfileInfoFetch("hi", "hii", "hii");
env->ReleaseStringUTFChars(javaString1, nativeString1);
env->ReleaseStringUTFChars(javaString2, nativeString2);
env->ReleaseStringUTFChars(javaString3, nativeString3);
}
facebookProfileInfoFetch は次のとおりです。
void LoginScreen::facebookProfileInfoFetch(const char * value1, const char * value2, const char * value3) {
LOGD(" ----------------- facebookProfileInfoFetch ------------- %s ------------ ", value1);
LOGD(" ----------------- facebookProfileInfoFetch ------------- %s ------------ ", value2);
LOGD(" ----------------- facebookProfileInfoFetch ------------- %s ------------ ", value3);
facebookUserName = value1;
facebookUserId = value2;
facebookUserGender = value3;
this->loginHumServer();
}
loginHumServer() が呼び出されるとクラッシュします。
loginhumserver() は次のとおりです。
void LoginScreen::loginHumServer()
{
LOGD(" ----------------- loginHumServer ------------------------- ");
facebookDataRetrievedCount++;
if(facebookDataRetrievedCount<2)
return;
CCHttpRequest* request = new CCHttpRequest();
LOGD(" ----------------- constructing url ------------------------- ");
std::string url="http://humsrer.co.in/user/sign_in?";
url=url+"name"+"="+facebookNoSpaceUserName+"&";
url=url+"facebook_thumbnail"+"="+facebookUserPictureUrl+"&";
url=url+"facebook_id"+"="+facebookUserId+"&";
url=url+"gender"+"="+facebookUserGender+"&";
url=url+"ios_push_id"+"="+"12346";
CCLog("UUUUUUUUUUUUUUUUUUU %s ",url.c_str());
request->setUrl(url.c_str());
request->setRequestType(CCHttpRequest::kHttpGet);
request->setResponseCallback(this, callfuncND_selector(LoginScreen::onHttpRequestCompleted));
// optional fields
request->setTag("GET test2");
LOGD(" ----------------- loginHumServer getInstance ------------------------- ");
CCHttpClient::getInstance()->send(request);
// don't forget to release it, pair to new
request->release();
LOGD(" ----------------- loginHumServer request->release ------------------------- ");
loginLabel->setString("Loging to hum server..");
}
これは、アプリがクラッシュしたときに表示される logcat エラーです。
12-06 13:49:45.380: INFO/DEBUG(5637): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr deadbaad
12-06 13:49:45.380: INFO/DEBUG(5637): r0 deadbaad r1 01ddc9e8 r2 40000000 r3 00000000
12-06 13:49:45.380: INFO/DEBUG(5637): r4 00000000 r5 00000027 r6 00000000 r7 57797f3c
12-06 13:49:45.380: INFO/DEBUG(5637): r8 5c6d9c10 r9 57797f34 10 00000008 fp 5c6d9c24
12-06 13:49:45.380: INFO/DEBUG(5637): ip ffffffff sp 5c6d9a90 lr 400ff649 pc 400fb9d8 cpsr 60000030
12-06 13:49:45.380: INFO/DEBUG(5637): d0 4448000044480000 d1 0000000000000000
12-06 13:49:45.380: INFO/DEBUG(5637): d2 449a0000449a0000 d3 000004d0c41a0000
12-06 13:49:45.380: INFO/DEBUG(5637): d4 3f8000004b7fffff d5 449a000044480000
12-06 13:49:45.380: INFO/DEBUG(5637): d6 4499e0004447c000 d7 0000000000000000
12-06 13:49:45.380: INFO/DEBUG(5637): d8 0000000000000000 d9 0000000000000000
12-06 13:49:45.380: INFO/DEBUG(5637): d10 0000000000000000 d11 0000000000000000
12-06 13:49:45.380: INFO/DEBUG(5637): d12 0000000000000000 d13 0000000000000000
12-06 13:49:45.380: INFO/DEBUG(5637): d14 0000000000000000 d15 0000000000000000
12-06 13:49:45.380: INFO/DEBUG(5637): d16 5000000000000000 d17 0000000000000000
12-06 13:49:45.380: INFO/DEBUG(5637): d18 0000000000000000 d19 0000000000000000
12-06 13:49:45.380: INFO/DEBUG(5637): d20 0000000000000000 d21 0000000000000000
12-06 13:49:45.380: INFO/DEBUG(5637): d22 0000000000000000 d23 0000000000000000
12-06 13:49:45.380: INFO/DEBUG(5637): d24 0000000000000000 d25 0000000000000000
12-06 13:49:45.380: INFO/DEBUG(5637): d26 0000000000000000 d27 0000000000000000
12-06 13:49:45.380: INFO/DEBUG(5637): d28 0000000000000000 d29 0000000000000000
12-06 13:49:45.380: INFO/DEBUG(5637): d30 0000000000000000 d31 0000000000000000
12-06 13:49:45.380: INFO/DEBUG(5637): scr 60000010
12-06 13:49:45.650: INFO/DEBUG(5637): #00 pc 000179d8 /system/lib/libc.so
12-06 13:49:45.650: INFO/DEBUG(5637): #01 pc 0001ef44 /system/lib/libc.so (__assert2)
12-06 13:49:45.650: INFO/DEBUG(5637): #02 pc 000fb552 /data/data/com.humit/lib/libgame.so (_ZN11LoginScreen22onHttpRequestCompletedEPN7cocos2d6CCNodeEPv)
12-06 13:49:45.655: INFO/DEBUG(5637): #03 pc 001c3e32 /data/data/com.humit/lib/libgame.so (_ZN7cocos2d9extension12CCHttpClient25dispatchResponseCallbacksEf)
12-06 13:49:45.655: INFO/DEBUG(5637): #04 pc 000ff9aa /data/data/com.humit/lib/libgame.so (_ZN7cocos2d7CCTimer6updateEf)
12-06 13:49:45.655: INFO/DEBUG(5637): #05 pc 001053d6 /data/data/com.humit/lib/libgame.so (_ZN7cocos2d11CCScheduler6updateEf)
12-06 13:49:45.655: INFO/DEBUG(5637): #06 pc 0012f7f8 /data/data/com.humit/lib/libgame.so (_ZN7cocos2d10CCDirector9drawSceneEv)
12-06 13:49:45.660: INFO/DEBUG(5637): #07 pc 00130df8 /data/data/com.humit/lib/libgame.so (_ZN7cocos2d21CCDisplayLinkDirector8mainLoopEv)
12-06 13:49:45.660: INFO/DEBUG(5637): #08 pc 0016c66c /data/data/com.humit/lib/libgame.so (Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeRender)
12-06 13:49:45.660: INFO/DEBUG(5637): #09 pc 0001ed70 /system/lib/libdvm.so (dvmPlatformInvoke)
12-06 13:49:45.660: INFO/DEBUG(5637): #10 pc 0005902c /system/lib/libdvm.so (_Z16dvmCallJNIMethodPKjP6JValuePK6MethodP6Thread)
クラッシュする理由をデバッグできません。親切に助けてください。
EDIT onHttpRequestCompleted メソッドを追加しました:
void LoginScreen::onHttpRequestCompleted(CCNode *sender, void *data)
{
LOGD(" ----------------- LoginScreen onHttpRequestCompleted ------------------------- ");
CCLOG("request completed");
CCHttpResponse *response = (CCHttpResponse*)data;
if (!response)
{
LOGD(" ----------------- LoginScreen onHttpRequestCompleted return ------------------------- ");
return;
}
// You can get original request type from: response->request->reqType
if (0 != strlen(response->getHttpRequest()->getTag()))
{
CCLog("%s completed", response->getHttpRequest()->getTag());
}
int statusCode = response->getResponseCode();
char statusString[64] = {};
sprintf(statusString, "HTTP Status Code: %d, tag = %s", statusCode, response->getHttpRequest()->getTag());
//m_labelStatusCode->setString(statusString);
CCLog("response code: %d", statusCode);
if (!response->isSucceed())
{
CCLog(" %s response failed", response->getResponseData());
CCLog("error buffer: %s", response->getErrorBuffer());
LOGD(" ----------------- LoginScreen onHttpRequestCompleted response failed ------------------------- ");
return;
}
//dump data
std::vector<char> *buffer = response->getResponseData();
char * charbuffer = new char[buffer->size()];
printf("Http Test, dump data: ");
unsigned int size=0;
for (unsigned int i = 0; i < buffer->size(); i++)
{
charbuffer[i] = (*buffer)[i];
size=i+1;
}
charbuffer[size] = 0;
char *errorPos = 0;
char *errorDesc = 0;
int errorLine = 0;
block_allocator allocator(1 << 10); // 1 KB per block
json_value *root = json_parse(charbuffer, &errorPos, &errorDesc, &errorLine, &allocator);
root = root->first_child;
assert(root->type ==JSON_STRING );
assert(std::string(root->name) == "user_id" );
loginLabel->setString("Loading active games..");
GameManager::create(root->json_value::string_value,facebookUserId.c_str(),facebookUserName.c_str());
// GameManager::create("b37e329c-37ac-11e2-abf1-1231381a9805");
delete[] charbuffer;
this->next();
}