I need to call a JNI method that runs a infinite native loop inside, but it stops my java UI.
Java code:
FraMain.java:
public class FraMain extends javax.swing.JFrame {
public FraMain() {
initComponents();
setExtendedState(java.awt.Frame.MAXIMIZED_BOTH);
System.out.println("here starts");
new Thread(new Runnable() {
@Override
public void run() {
new JNIEyes().iniciar(new XYListener() {
@Override
public void onFramePrecesed(double x, double y) {
System.out.println(String.format("POINT %f - %f", x,y));
}
});
}
}).run();
System.out.println("continue charging UI");
}
}
JNIEyes.java:
public class JNIEyes {
static {
System.load("/home/sparkler/NetBeansProjects/OpenEyes/dist/openeyes.so");
}
public native void iniciar(XYListener listener);
}
XYListener.java is an interface with the method:
void onFramePrecesed(double x, double y);
and C++ code:
JNIEXPORT void JNICALL Java_jnieyes_JNIEyes_iniciar
(JNIEnv *env, jclass clase, jobject listener)
{
jclass objclass = env->GetObjectClass(listener);
jmethodID methodID = env->GetMethodID(objclass,"onFramePrecesed", "(DD)V");
if(methodID == 0){
printf("\error\n");
return;
}
while (true) {
Point point = process_image();
env->CallVoidMethod(listener,methodID,point.x,point.y);
}
}
The loop itΕ working fine, and I am getting the x, y values into java onFramePrecesed method, but the UI never shows and the "continue charging UI" message is never printed.
Thanks!