Cercando di capire perché la chiamata di funzione C++ restituisce un int arresta l'intera applicazione senza errori/avvisi.Restituzione di una funzione int dalla funzione nativa (C++, jni)
Qui sta lavorando Codice:
jint Java_org_ntorrent_DummyTorrentInfoProvider_next(
JNIEnv * env, jobject obj, jint number)
{
jint test = rand();
__android_log_print(ANDROID_LOG_DEBUG, "HelloNDK!", "rand() = %d", test);
return number;
}
E questo codice applicazione si blocca senza avvisi:
jint Java_org_ntorrent_DummyTorrentInfoProvider_next(
JNIEnv * env, jobject obj, jint number)
{
jint test = rand();
__android_log_print(ANDROID_LOG_DEBUG, "HelloNDK!", "rand() = %d", test);
return number + test;
}
Prima l'applicazione si blocca posso vedere il mio messaggio di log (__ android_log_print) nel registro gatto
MODIFICA: Anche se sostituisco "numero + test" con "1" l'applicazione si blocca ancora ... È solo una preoccupazione ks se torno "numero" ...
EDIT # 2: codice Java lato:
package org.ntorrent;
import java.util.ArrayList;
import java.util.Random;
public class DummyTorrentInfoProvider implements TorrentInfoProvider {
public native Integer next(Integer number);
//public Integer next() { return _random.nextInt(); }
public native void test();
private Random _random = new Random(100);
@Override
public ArrayList getTorrents() {
test();
ArrayList torrents = new ArrayList();
torrents.add(
new TorrentInfo("test torrent number 1", next(1), 3f, 5f));
torrents.add(
new TorrentInfo("test torrent number 2", next(2), 4f, 15f));
torrents.add(
new TorrentInfo("test torrent number 555"));
torrents.add(
new TorrentInfo("test torrent number 3", next(3), 13f, 5f));
return torrents;
}
static {
System.loadLibrary("test");
}
}
stack-smash o altri tipi di problemi di memoria? –
Prendi un dump dalla JVM e guarda cosa sta succedendo esattamente. Sotto Hotspot ci sono opzioni per il debug di questi problemi - nessuna idea di Android però. Il codice qui va bene, il problema è altrove. – Voo
Grazie per le risposte veloci, ragazzi! Ci proverò domani ... – 6opuc