0

Androidアプリに戻すためstd::set<int>に変換/コピーする必要があるオブジェクトが提供されています。jintArray以下のコードを試してみましたが、これだけを手がかりにアプリがクラッシュしているようです:

致命的なシグナル 11 (SIGSEGV)、コード 1 (SEGV_MAPERR)、tid 19975 の障害 addr 0x2

キャストだと思いますが、正しい方法がわかりません。 theIdは間違いなくintです。以下のコードを参照してください。

std::set<int> speciesSet = someFunctionThatReturnsASet();

speciesIDSet = env->NewIntArray(speciesSet.size());

int count = 0;
for ( std::set<int>::iterator itr=speciesSet.begin(); itr != speciesSet.end(); itr++ ) {
    try {
        int theId = *itr;
        // This is the last line of code that runs.
        env->SetIntArrayRegion(speciesIDSet, count, 1, (jint*)theId);
        count++;
    }
    catch (const std::exception& e) {
        std::cout << e.what();
    }
    catch (...) {
        std::cout << "oops";
    }
}
4

2 に答える 2