Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/370.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/190.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android-JNI在本机C++;变量 我在C++ C++类中尝试设置变量时,有一些JNI /C++代码崩溃。 void AndroidReflectionViewer::NativeSetVrActive(JNIEnv* env, jboolean active) { LOGW("This gets called fine"); other_obj_.set_vr_enabled(active); LOGW("Code never gets to here"); }_Java_Android_C++_Java Native Interface - Fatal编程技术网

Java Android-JNI在本机C++;变量 我在C++ C++类中尝试设置变量时,有一些JNI /C++代码崩溃。 void AndroidReflectionViewer::NativeSetVrActive(JNIEnv* env, jboolean active) { LOGW("This gets called fine"); other_obj_.set_vr_enabled(active); LOGW("Code never gets to here"); }

Java Android-JNI在本机C++;变量 我在C++ C++类中尝试设置变量时,有一些JNI /C++代码崩溃。 void AndroidReflectionViewer::NativeSetVrActive(JNIEnv* env, jboolean active) { LOGW("This gets called fine"); other_obj_.set_vr_enabled(active); LOGW("Code never gets to here"); },java,android,c++,java-native-interface,Java,Android,C++,Java Native Interface,反过来,其他对象函数如下所示: void set_vr_enabled(bool enabled) { LOGW("Before bool set prints fine."); what_eva = enabled; LOGW("After never prints"); } 当我将其他对象中的bool设置为任何值(或者真正更改该对象中的任何变量)时,它似乎崩溃了。不过,打印日志语句也不错。我也试过了,没有区别 ? A/libc: Fatal signal 11

反过来,
其他对象
函数如下所示:

void set_vr_enabled(bool enabled) { 
    LOGW("Before bool set prints fine."); 
    what_eva = enabled;
    LOGW("After never prints"); 
}
当我将
其他对象中的
bool
设置为任何值(或者真正更改该对象中的任何变量)时,它似乎崩溃了。不过,打印日志语句也不错。我也试过了,没有区别

? A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x123e in tid 12243

          [ 01-19 09:18:54.062   457:  457 W/         ]
          debuggerd: handling request: pid=12243 uid=10143 gid=10143 tid=12243
I/nanohub: osLog: [BMI160] gyrPower: on=1, state=3
I/nanohub: osLog: [BMI160] magPower: on=1, state=4
? W/debuggerd: type=1400 audit(0.0:1870): avc: denied { search } for name="com.foo" dev="sda35" ino=877326 scontext=u:r:debuggerd:s0 tcontext=u:object_r:app_data_file:s0:c512,c768 tclass=dir permissive=0
? W/debuggerd: type=1400 audit(0.0:1871): avc: denied { search } for name="com.foo" dev="sda35" ino=877326 scontext=u:r:debuggerd:s0 tcontext=u:object_r:app_data_file:s0:c512,c768 tclass=dir permissive=0
我读到了关于avc:Denized错误的文章。虽然这些有助于调试错误的来源,但对于实际可能导致的原因,它并没有给出很多建议。因此,对于实际问题:


是什么导致了这次崩溃?我该如何修复它?

有几件事情似乎是它们导致了这个问题:

  • 也许我的思路不对。我试着等那根线 但它不起作用

  • 也许jboolean是个问题?转换和刚设置
    what_eva=true
    不起作用

  • 也许这是一个竞争条件,Java代码是 在C++代码初始化之前运行。

实际解决方案:


崩溃是由竞争条件引起的,在尝试C++之前,我试图从java调用C++函数。我在调用C++之前延迟了几毫秒,它工作了。这似乎不是超级健壮,但在这种情况下,我计划无论如何都从用户激活的按钮调用它。当我这样做的时候,我不必担心比赛条件。

我把这列为一个答案,因为这是我从同事那里得到的解决这个问题的3种可能的方法。其中只有一个是有效的,我已经把它和其他的分开了。但它们似乎都是其他有类似问题的人可能会使用的看似合理的解决方案。这是一种非常糟糕的编程实践,将来肯定会对你造成伤害。