JNI 开发:为什么 C++ 在 Debug 正常,Release 却返回 NaN?
本文为以下问题的解决记录。由于问题较为典型,故梳理备忘。 https://github.com/eqgis/Sceneform-EQR/discussions/16

一、问题现象描述
1. 现象
- Debug 构建
- JNI 返回的坐标数值正常

- Release 构建
- 返回坐标中出现
NaN/Infinity - 且仅在 Release 出现
- 返回坐标中出现

2. 出问题的方法
JNIEXPORT void JNICALL Java_com_eqgis_eqr_core_CoordinateUtilsNative_jni_1ToScenePosition(
JNIEnv *env, jclass clazz,
jdouble ref_x, jdouble ref_y,
jdouble target_location_x, jdouble target_location_y,
jdouble azimuth_rad, jdoubleArray outJNIArray) {
double* offset = ComputeTranslation(ref_x, ref_y, target_location_x, target_location_y);
double deX = *offset;
double deY = *(offset + 1);
double x = deX * cos(azimuth_rad) - deY * sin(azimuth_rad);
double y = deX * (azimuth_rad) + deY * (azimuth_rad);
outArray[] = {x, y};
env->(outJNIArray, , , outArray);
}


