I'm provided a std::set<int> object that I need to convert/copy into a jintArray to return to an Android app.  I tried the code below, but it seems to be crashing my app with only this as a clue:
Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x2 in tid 19975
I suspect it's the cast, but I'm not sure the right way to do it.  theId is definitely an int.  See the code below:
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";
    }
}
 
     
    