First, I am new at Android and Java, so I am doing most of my stuff in native code. I am doing this mostly for speed reason, as my code has to deal with image processing.
My application is a timelapse camera, where it has to wake up every once in a while, acquire a wakelock, take some pictures, process them, set a new alarm then go to sleep.
My alarm receiver code looks like so:
public class MyBroadcastReceiver extends BroadcastReceiver {
private static final String TAG = "Something";
@Override
public void onReceive(Context context, Intent intent)
{
Log.e(TAG, "We got alarm :)");
new Thread(new Runnable() {
public void run() {
CameraActivity.cameraraw.call_alarm(); }
}).start();
}
CameraActivity.cameraraw.call_alarm(); just calls a JNI function and then gives the control to my c code, which looks like so:
JNIEXPORT jbyte JNICALL Java_com_example_android_camera2raw_Camera2RawFragment_rtc_1alarm(JNIEnv* env,jclass clazz,jobject cameraraw)
{
syslog(LOG_CRIT, "Alarm in native code, picture %s",cur_timelapse_pic);
wake_me_up(env,clazz,cameraraw);
sleep(5);
if(cur_timelapse_pic<timelapse_shots)
{
do_focus_stack(env,clazz,cameraraw,cur_timelapse_pic);
cur_timelapse_pic++;
set_alarm(env,clazz,cameraraw,timelapse_delay);
}
go_to_sleep(env,clazz,cameraraw);
syslog(LOG_CRIT, "Went to sleep");
}
The code works fine at the first alarm, but the second alarm crashes even before the syslog()
2020-04-30 18:19:00.039 15198-15727/com.example.android.camera2raw W/roid.camera2ra: 0xebadde09 skipped times: 0
--------- beginning of crash
2020-04-30 18:19:00.040 15198-15727/com.example.android.camera2raw A/libc: Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x1 in tid 15727 (Thread-8), pid 15198 (roid.camera2raw) 2020-04-30 18:19:06.531 15198-15198/com.example.android.camera2raw D/ViewRootImpl@1b051d4[CameraActivity]: Surface release. android.view.ViewRootImpl$ViewRootHandler.handleMessage:4825 android.os.Handler.dispatchMessage:106
Is there something I am missing? Btw, my function finishes doing it's work long before the next alarm comes. Any help would be much appreciated!
cur_timelapse_pic
seems to be a number, yet you are trying to log it as a string (%s
). Change that to %d
or %u
instead.