Camera crashes: Fatal signal 6 (SIGABRT) with JNI code - java

I am currently developing an application where after the camera detected a body, an image (shirt) will be overlaid. However, after detecting the body, the camera crashes and my logcat says Fatal signal 6 (SIGABRT), code -6 in tid 23908 (Thread-39833).
Below are the codes I've made so far.
nerds_thesis_clartips_OpencvClass.h //header file
#include <jni.h>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <stdio.h>
using namespace cv;
using namespace std;
#ifndef _Included_nerds_thesis_clartips_OpencvClass
#define _Included_nerds_thesis_clartips_OpencvClass
#ifdef __cplusplus
extern "C" {
#endif
void detectHuman(Mat& frame);
Mat putShirt(Mat frame, Point center, Size humanSize);
JNIEXPORT void JNICALL Java_nerds_thesis_clartips_OpencvClass_humanDetection
(JNIEnv *, jclass, jlong);
#ifdef __cplusplus
}
#endif
#endif
nerds_thesis_clartips_OpencvClass.cpp //C++ file
#include "nerds_thesis_clartips_OpencvClass.h"
JNIEXPORT void JNICALL Java_nerds_thesis_clartips_OpencvClass_humanDetection
(JNIEnv *, jclass, jlong addrRgba){
Mat& frame = *(Mat*)addrRgba;
detectHuman(frame);
}
void detectHuman(Mat& frame){
// assign xml file to a variable
String human_cascade_name = "/storage/emulated/0/data/haarcascade_upperbody.xml";
CascadeClassifier human_cascade;
// load xml file
if(!human_cascade.load( human_cascade_name ) ) { printf("--(!)Error loading\n"); return; };
std::vector<Rect> humans;
Mat frame_gray;
//convert input to grayscale
cvtColor( frame, frame_gray, CV_BGR2GRAY );
//increase image contrast
equalizeHist( frame_gray, frame_gray);
//Detect Human
human_cascade.detectMultiScale( frame_gray, humans, 1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, Size(100, 100) );
// Draw the mask over all rectangles
for (size_t i = 0; i < humans.size(); i++){
Rect r = humans[i];
Mat humanROI = frame_gray( humans[i] ); //image of the upper body
int h_temp = humans[i].height; // storing original height
int x = humans[i].x;
int y = humans[i].y - h_temp*(-0.6); // y is increased by 0.6*h
int w = humans[i].width;
int h = h_temp; // height detected
rectangle(frame, Point(x,y), Point(x + w,y +h),Scalar(255,0,255));
Point center( humans[i].x + humans[i].width*0.5, humans[i].y + humans[i].height*0.5 );
frame = putShirt(frame,center,Size( humans[i].width, humans[i].height));
}
}
Mat putShirt(Mat frame, Point center, Size humanSize){
Mat mask = imread("C:/Users/Requinala/AndroidStudioProjects/CLARTIPS/app/src/main/res/drawable/bluevelvet.png");
Mat mask1,src1;
resize(mask,mask1,humanSize);
// ROI selection
Rect roi(center.x - humanSize.width/2, center.y - humanSize.width/2, humanSize.width, humanSize.width);
frame(roi).copyTo(src1);
// to make the white region transparent
Mat mask2,m,m1;
cvtColor(mask1,mask2,CV_BGR2GRAY);
threshold(mask2,mask2,230,255,CV_THRESH_BINARY_INV);
vector<Mat> maskChannels(3),result_mask(3);
split(mask1, maskChannels);
bitwise_and(maskChannels[0],mask2,result_mask[0]);
bitwise_and(maskChannels[1],mask2,result_mask[1]);
bitwise_and(maskChannels[2],mask2,result_mask[2]);
merge(result_mask,m ); // imshow("m",m);
mask2 = 255 - mask2;
vector<Mat> srcChannels(3);
split(src1, srcChannels);
bitwise_and(srcChannels[0],mask2,result_mask[0]);
bitwise_and(srcChannels[1],mask2,result_mask[1]);
bitwise_and(srcChannels[2],mask2,result_mask[2]);
merge(result_mask,m1 ); // imshow("m1",m1);
addWeighted(m,1,m1,1,0,m1); // imshow("m2",m1);
m1.copyTo(frame(roi));
return frame;
}
OpencvCamera.java //Java class for camera
public class OpencvCamera extends AppCompatActivity implements CameraBridgeViewBase.CvCameraViewListener2{
Mat mRgba;
#Override
public void onCameraViewStarted(int width, int height) {
mRgba = new Mat(height, width, CvType.CV_8UC4);
}
#Override
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
mRgba = inputFrame.rgba();
OpencvClass.humanDetection(mRgba.getNativeObjAddr());
return mRgba;
}
}
OpencvClass.java //java class for the jni
public class OpencvClass {
public native static void humanDetection(long addrRgba);
}
logcats
02-24 16:45:36.269 13615-23908/? A/libc: Fatal signal 6 (SIGABRT), code -6 in tid 23908 (Thread-39833)
02-24 16:45:36.372 280-280/? I/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
02-24 16:45:36.372 280-280/? I/DEBUG: Build fingerprint: 'CMCC/M631Y/M631Y:5.1.1/LMY47V/M631Y_02.24.00RPD_HK.00:user/release-keys'
02-24 16:45:36.372 280-280/? I/DEBUG: Revision: '0'
02-24 16:45:36.372 280-280/? I/DEBUG: ABI: 'arm'
02-24 16:45:36.373 280-280/? I/DEBUG: pid: 13615, tid: 23908, name: Thread-39833 >>> nerds.thesis.clartips <<<
02-24 16:45:36.373 280-280/? I/DEBUG: signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
02-24 16:45:36.396 280-280/? I/DEBUG: r0 00000000 r1 00005d64 r2 00000006 r3 00000000
02-24 16:45:36.396 280-280/? I/DEBUG: r4 a4674dd8 r5 00000006 r6 00000000 r7 0000010c
02-24 16:45:36.396 280-280/? I/DEBUG: r8 00000047 r9 00000001 sl a4674400 fp 0000203e
02-24 16:45:36.397 280-280/? I/DEBUG: ip 00005d64 sp a46732a0 lr b6dbfc2d pc b6de5f3c cpsr 600f0010
02-24 16:45:36.397 280-280/? I/DEBUG: backtrace:
02-24 16:45:36.397 280-280/? I/DEBUG: #00 pc 00039f3c /system/lib/libc.so (tgkill+12)
02-24 16:45:36.397 280-280/? I/DEBUG: #01 pc 00013c29 /system/lib/libc.so (pthread_kill+52)
02-24 16:45:36.397 280-280/? I/DEBUG: #02 pc 00014847 /system/lib/libc.so (raise+10)
02-24 16:45:36.397 280-280/? I/DEBUG: #03 pc 00010fd5 /system/lib/libc.so (__libc_android_abort+36)
02-24 16:45:36.397 280-280/? I/DEBUG: #04 pc 0000f534 /system/lib/libc.so (abort+4)
02-24 16:45:36.397 280-280/? I/DEBUG: #05 pc 008a2e50 /data/app/nerds.thesis.clartips-2/lib/arm/libopencv_java3.so (_ZN9__gnu_cxx27__verbose_terminate_handlerEv+344)
02-24 16:45:36.398 280-280/? I/DEBUG: #06 pc 0087914c /data/app/nerds.thesis.clartips-2/lib/arm/libopencv_java3.so (_ZN10__cxxabiv111__terminateEPFvvE+4)
02-24 16:45:36.398 280-280/? I/DEBUG: #07 pc 0087918c /data/app/nerds.thesis.clartips-2/lib/arm/libopencv_java3.so (_ZSt9terminatev+16)
02-24 16:45:36.398 280-280/? I/DEBUG: #08 pc 00878b68 /data/app/nerds.thesis.clartips-2/lib/arm/libopencv_java3.so (__cxa_throw+168)
02-24 16:45:36.398 280-280/? I/DEBUG: #09 pc 001c8305 /data/app/nerds.thesis.clartips-2/lib/arm/libopencv_java3.so (_ZN2cv5errorERKNS_9ExceptionE+244)
02-24 16:45:36.398 280-280/? I/DEBUG: #10 pc 001c8445 /data/app/nerds.thesis.clartips-2/lib/arm/libopencv_java3.so (_ZN2cv5errorEiRKNS_6StringEPKcS4_i+96)
02-24 16:45:36.398 280-280/? I/DEBUG: #11 pc 0037660f /data/app/nerds.thesis.clartips-2/lib/arm/libopencv_java3.so (_ZN2cv6resizeERKNS_11_InputArrayERKNS_12_OutputArrayENS_5Size_IiEEddi+406)
02-24 16:45:36.399 280-280/? I/DEBUG: #12 pc 0000fbf5 /data/app/nerds.thesis.clartips-2/lib/arm/libMyLibs.so (putShirt+172)
02-24 16:45:36.399 280-280/? I/DEBUG: #13 pc 0000f7ab /data/app/nerds.thesis.clartips-2/lib/arm/libMyLibs.so (detectHuman+842)
02-24 16:45:36.399 280-280/? I/DEBUG: #14 pc 0015fc6d /data/dalvik-cache/arm/data#app#nerds.thesis.clartips-2#base.apk#classes.dex
I'm a beginner and I've searched about SIGABRT and it says it has something to do about memory issues. I can't find where I've gone wrong in my codes.
This is very crucial. All helps/ideas will be appreciated because this will serve as my final output in college.

imread("C:/Users/Requinala/AndroidStudioProjects/CLARTIPS/app/src/main/res/drawable/bluevelvet.png")
tires to read the png from your PC disk. No wonder that it fails. You should
always check that result of file read, etc. is OK
read the image from your phone storage, or from assets of your app
You can use Java to extract images from the resources (or assets) to local storage, or you can use the Android assets native API to read such images directly from the APK.
Assets seem to suit your cause better, because the drawable resources are meant to be adapted to the screen resolution.
Using native assets API with imread() is possible, but tricky.

Related

This Error Force close my app when I'm inspecting my table : signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x10

I have table in my application and I'm Running my app on Huawei y9 and this error pops up after a 30 sec and force close my application. I link my other question that I put the code of my table btw Im ussing implementation "androidx.room:room-runtime:2.3.0" and
annotationProcessor "androidx.room:room-compiler:2.3.0" but I don't think this casing the error.
my Error :
2022-03-05 20:41:45.893 29390-29425/com.example.myapplication A/libc: Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x10 in tid 29425 (HeapTaskDaemon), pid 29390 (e.myapplication)
2022-03-05 20:41:46.093 29837-29837/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
2022-03-05 20:41:46.094 29837-29837/? A/DEBUG: Build fingerprint: 'HUAWEI/JKM-LX1/HWJKM-H:9/HUAWEIJKM-LX1/9.1.0.309C185:user/release-keys'
2022-03-05 20:41:46.094 29837-29837/? A/DEBUG: Revision: '0'
2022-03-05 20:41:46.094 29837-29837/? A/DEBUG: ABI: 'arm64'
2022-03-05 20:41:46.095 29837-29837/? A/DEBUG: Happend: 'Sat Mar 5 20:41:46 2022
'
2022-03-05 20:41:46.095 29837-29837/? A/DEBUG: SYSVMTYPE: Art
APPVMTYPE: Art
2022-03-05 20:41:46.095 29837-29837/? A/DEBUG: pid: 29390, tid: 29425, name: HeapTaskDaemon >>> com.example.myapplication <<<
2022-03-05 20:41:46.095 29837-29837/? A/DEBUG: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x10
2022-03-05 20:41:46.095 29837-29837/? A/DEBUG: Cause: null pointer dereference
2022-03-05 20:41:46.095 29837-29837/? A/DEBUG: x0 0000007cd5ef6f00 x1 0000007cb6eede48 x2 0000000000000008 x3 0000000000000400
2022-03-05 20:41:46.095 29837-29837/? A/DEBUG: x4 0000000017e08744 x5 0000000013489974 x6 0000000017e1fa50 x7 0000000017e1fa50
2022-03-05 20:41:46.095 29837-29837/? A/DEBUG: x8 0000000000000000 x9 fbafe48ae0791bf6 x10 0000000042c00000 x11 0000000000000008
2022-03-05 20:41:46.095 29837-29837/? A/DEBUG: x12 000000000000000b x13 17e053d000000000 x14 0000007cd5ec0d50 x15 00000cefaa754cdb
2022-03-05 20:41:46.096 29837-29837/? A/DEBUG: x16 0000007cd5b95ec0 x17 0000007d5909fdf0 x18 0000007cd5abea50 x19 0000007cb6eede48
2022-03-05 20:41:46.096 29837-29837/? A/DEBUG: x20 0000000070c0d868 x21 0000000000000008 x22 00000000714d2528 x23 00000000714d10b0
2022-03-05 20:41:46.096 29837-29837/? A/DEBUG: x24 0000000000000028 x25 00000000000023c8 x26 0000000000001478 x27 0000007cb6eef588
2022-03-05 20:41:46.096 29837-29837/? A/DEBUG: x28 00000000714d10c8 x29 0000007cb6eede30
2022-03-05 20:41:46.096 29837-29837/? A/DEBUG: sp 0000007cb6eeddc0 lr 0000007cd570e08c pc 0000007cd570e068
2022-03-05 20:41:46.151 29837-29837/? A/DEBUG: backtrace:
2022-03-05 20:41:46.151 29837-29837/? A/DEBUG: #00 pc 00000000001d7068 /system/lib64/libart.so (_ZN3art6mirror6Object15VisitReferencesILb1ELNS_17VerifyObjectFlagsE0ELNS_17ReadBarrierOptionE1ENS_2gc9collector17ConcurrentCopying16RefFieldsVisitorES8_EEvRKT2_RKT3_+2504)
2022-03-05 20:41:46.151 29837-29837/? A/DEBUG: #01 pc 00000000001c9594 /system/lib64/libart.so (art::gc::collector::ConcurrentCopying::ImmuneSpaceScanObjVisitor::Callback(art::mirror::Object*, void*)+68)
2022-03-05 20:41:46.151 29837-29837/? A/DEBUG: #02 pc 00000000001bb220 /system/lib64/libart.so (art::gc::accounting::ModUnionTableReferenceCache::VisitObjects(void (*)(art::mirror::Object*, void*), void*)+224)
2022-03-05 20:41:46.151 29837-29837/? A/DEBUG: #03 pc 00000000001c6770 /system/lib64/libart.so (art::gc::collector::ConcurrentCopying::MarkingPhase()+244)
2022-03-05 20:41:46.151 29837-29837/? A/DEBUG: #04 pc 00000000001c51b8 /system/lib64/libart.so (art::gc::collector::ConcurrentCopying::RunPhases()+1176)
2022-03-05 20:41:46.151 29837-29837/? A/DEBUG: #05 pc 00000000001db930 /system/lib64/libart.so (art::gc::collector::GarbageCollector::Run(art::gc::GcCause, bool)+320)
2022-03-05 20:41:46.151 29837-29837/? A/DEBUG: #06 pc 0000000000201860 /system/lib64/libart.so (art::gc::Heap::CollectGarbageInternal(art::gc::collector::GcType, art::gc::GcCause, bool)+3404)
2022-03-05 20:41:46.151 29837-29837/? A/DEBUG: #07 pc 00000000001ff654 /system/lib64/libart.so (art::gc::Heap::DoPendingCollectorTransition()+108)
2022-03-05 20:41:46.151 29837-29837/? A/DEBUG: #08 pc 00000000002185c0 /system/lib64/libart.so (art::gc::Heap::CollectorTransitionTask::Run(art::Thread*)+40)
2022-03-05 20:41:46.151 29837-29837/? A/DEBUG: #09 pc 000000000023ab48 /system/lib64/libart.so (art::gc::TaskProcessor::RunAllTasks(art::Thread*)+68)
2022-03-05 20:41:46.151 29837-29837/? A/DEBUG: #10 pc 0000000000092a6c /system/framework/arm64/boot-core-libart.oat (offset 0x90000) (dalvik.system.VMRuntime.clampGrowthLimit [DEDUPED]+124)
2022-03-05 20:41:46.151 29837-29837/? A/DEBUG: #11 pc 0000000000580588 /system/lib64/libart.so (art_quick_invoke_stub+584)
2022-03-05 20:41:46.151 29837-29837/? A/DEBUG: #12 pc 00000000000d8608 /system/lib64/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+200)
2022-03-05 20:41:46.151 29837-29837/? A/DEBUG: #13 pc 000000000028cec8 /system/lib64/libart.so (art::interpreter::ArtInterpreterToCompiledCodeBridge(art::Thread*, art::ArtMethod*, art::ShadowFrame*, unsigned short, art::JValue*)+344)
2022-03-05 20:41:46.151 29837-29837/? A/DEBUG: #14 pc 0000000000286ed0 /system/lib64/libart.so (bool art::interpreter::DoCall<false, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*)+968)
2022-03-05 20:41:46.151 29837-29837/? A/DEBUG: #15 pc 0000000000547bf8 /system/lib64/libart.so (MterpInvokeVirtual+588)
2022-03-05 20:41:46.152 29837-29837/? A/DEBUG: #16 pc 0000000000572c94 /system/lib64/libart.so (ExecuteMterpImpl+14228)
2022-03-05 20:41:46.152 29837-29837/? A/DEBUG: #17 pc 00000000000bbe7e /system/framework/boot-core-libart.vdex (java.lang.Daemons$HeapTaskDaemon.runInternal+38)
2022-03-05 20:41:46.152 29837-29837/? A/DEBUG: #18 pc 0000000000260bd4 /system/lib64/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadERKNS_20CodeItemDataAccessorERNS_11ShadowFrameENS_6JValueEb.llvm.4179671085+488)
2022-03-05 20:41:46.152 29837-29837/? A/DEBUG: #19 pc 00000000002666c8 /system/lib64/libart.so (art::interpreter::ArtInterpreterToInterpreterBridge(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame*, art::JValue*)+216)
2022-03-05 20:41:46.152 29837-29837/? A/DEBUG: #20 pc 0000000000286eb4 /system/lib64/libart.so (bool art::interpreter::DoCall<false, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*)+940)
2022-03-05 20:41:46.152 29837-29837/? A/DEBUG: #21 pc 0000000000547bf8 /system/lib64/libart.so (MterpInvokeVirtual+588)
2022-03-05 20:41:46.152 29837-29837/? A/DEBUG: #22 pc 0000000000572c94 /system/lib64/libart.so (ExecuteMterpImpl+14228)
2022-03-05 20:41:46.152 29837-29837/? A/DEBUG: #23 pc 00000000000bb9b4 /system/framework/boot-core-libart.vdex (java.lang.Daemons$Daemon.run+20)
2022-03-05 20:41:46.152 29837-29837/? A/DEBUG: #24 pc 0000000000260bd4 /system/lib64/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadERKNS_20CodeItemDataAccessorERNS_11ShadowFrameENS_6JValueEb.llvm.4179671085+488)
2022-03-05 20:41:46.152 29837-29837/? A/DEBUG: #25 pc 00000000002666c8 /system/lib64/libart.so (art::interpreter::ArtInterpreterToInterpreterBridge(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame*, art::JValue*)+216)
2022-03-05 20:41:46.152 29837-29837/? A/DEBUG: #26 pc 0000000000286eb4 /system/lib64/libart.so (bool art::interpreter::DoCall<false, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*)+940)
2022-03-05 20:41:46.152 29837-29837/? A/DEBUG: #27 pc 00000000005489b4 /system/lib64/libart.so (MterpInvokeInterface+944)
2022-03-05 20:41:46.152 29837-29837/? A/DEBUG: #28 pc 0000000000572e94 /system/lib64/libart.so (ExecuteMterpImpl+14740)
2022-03-05 20:41:46.152 29837-29837/? A/DEBUG: #29 pc 00000000000cd1ce /system/framework/boot.vdex (java.lang.Thread.run+12)
2022-03-05 20:41:46.152 29837-29837/? A/DEBUG: #30 pc 0000000000260bd4 /system/lib64/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadERKNS_20CodeItemDataAccessorERNS_11ShadowFrameENS_6JValueEb.llvm.4179671085+488)
2022-03-05 20:41:46.152 29837-29837/? A/DEBUG: #31 pc 0000000000533b90 /system/lib64/libart.so (artQuickToInterpreterBridge+1020)
2022-03-05 20:41:46.152 29837-29837/? A/DEBUG: #32 pc 00000000005896fc /system/lib64/libart.so (art_quick_to_interpreter_bridge+92)
2022-03-05 20:41:46.152 29837-29837/? A/DEBUG: #33 pc 0000000000580588 /system/lib64/libart.so (art_quick_invoke_stub+584)
2022-03-05 20:41:46.152 29837-29837/? A/DEBUG: #34 pc 00000000000d8608 /system/lib64/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+200)
2022-03-05 20:41:46.152 29837-29837/? A/DEBUG: #35 pc 000000000047b3e8 /system/lib64/libart.so (art::(anonymous namespace)::InvokeWithArgArray(art::ScopedObjectAccessAlreadyRunnable const&, art::ArtMethod*, art::(anonymous namespace)::ArgArray*, art::JValue*, char const*)+104)
2022-03-05 20:41:46.152 29837-29837/? A/DEBUG: #36 pc 000000000047c4a4 /system/lib64/libart.so (art::InvokeVirtualOrInterfaceWithJValues(art::ScopedObjectAccessAlreadyRunnable const&, _jobject*, _jmethodID*, jvalue*)+424)
2022-03-05 20:41:46.152 29837-29837/? A/DEBUG: #37 pc 00000000004a8238 /system/lib64/libart.so (art::Thread::CreateCallback(void*)+1120)
2022-03-05 20:41:46.152 29837-29837/? A/DEBUG: #38 pc 0000000000083a6c /system/lib64/libc.so (__pthread_start(void*)+36)
2022-03-05 20:41:46.152 29837-29837/? A/DEBUG: #39 pc 00000000000246e4 /system/lib64/libc.so (__start_thread+68)

Android Libgdx - Sigsegv 11 error on real device but no crash on emulator

I am currently trying to make an application with libgdx on android.
The application is working fine on emulator of android studio but there is a crash with my real phone when I do a world.destroy(body) with the library box2d.
More precisely, during the execution of the game, the application destroys 2 bodys after a collision like it is suppose to do but after 1 sec the app crash.
Here is the code of my listener of collision.
#Override
public void beginContact(Contact contact) {
Body a = contact.getFixtureA().getBody();
Body b = contact.getFixtureB().getBody();
if ((BodyUtils.bodyIsWater(b) && BodyUtils.bodyIsEnemy(a))|| (BodyUtils.bodyIsEnemy(b) && BodyUtils.bodyIsWater(a))){
if (!remove.contains(a)) {
remove.add(a);
}
if (!remove.contains(b)) {
remove.add(b);
}
iswater = false;
}
else if(BodyUtils.bodyIsGround(b) && BodyUtils.bodyIsWater(a)){
if(!remove.contains(a)) {
remove.add(a);
}
iswater=false;
}
else if(BodyUtils.bodyIsGround(a) && BodyUtils.bodyIsWater(b)){
if(!remove.contains(b)) {
remove.add(b);
}
iswater=false;
}
a=null;
b=null;
}
Comment about the code: Water is the bullet which shoot the ennemy. Remove is the arraylist.
Here is the code of my act method which destroy the body that are inside my arraylist of body to destroy ( the collision method but body to destroy into the arraylist ). The destroy call is into the for loop.
#Override
public void act(float delta) {
super.act(delta);
// Fixed timestep
accumulator += delta;
while (accumulator >= delta) {
world.step(TIME_STEP, 10, 10);
accumulator -= TIME_STEP;
}
for (int i = 0; i < remove.size(); i++) {
world.destroyBody(remove.get(i));
remove.remove(i);
/*for (int n = 0; i < y.getJointList().size; n++){
world.destroyJoint(y.getJointList().get(n).joint);
}*/
}
if(add%100==0 && !iswater) {
Array<Body> bodies = new Array<Body>(world.getBodyCount());
world.getBodies(bodies);
for (Body body : bodies) {
update(body);
}
}
if(add%80==0){
createEnemy();
}
add++;
}
Here is the content of the update methode :
private void update(Body body) {
if (BodyUtils.bodyIsEnemy(body) && !iswater) {
EnemyUserData z = (EnemyUserData) body.getUserData();
Vector2 m=body.getPosition();
if(m.x<23f){
createWater(z,m);
iswater=true;
}
}
}
First, I tried to figure out where to problem was from and I found that the app was not crashing if a wasn't destroying bodies. So know I know that the destroy function makes the app crash.
Here is the Sigsegv log:
04-03 19:01:50.068 25361-25404/com.mygdx.game A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x7a99fd63c0 in tid 25404 (GLThread 3290)
[ 04-03 19:01:50.076 402: 402 W/ ]
debuggerd: handling request: pid=25361 uid=10171 gid=10171 tid=25404
04-03 19:01:50.174 25501-25501/? A/DEBUG: *** *** *** *** *** *** *** ***
*** *** *** *** *** *** *** ***
04-03 19:01:50.174 25501-25501/? A/DEBUG: Build fingerprint: 'HUAWEI/PRA-LX1/HWPRA-H:7.0/HUAWEIPRA-LX1/C432B196:user/release-keys'
04-03 19:01:50.174 25501-25501/? A/DEBUG: Revision: '0'
04-03 19:01:50.174 25501-25501/? A/DEBUG: ABI: 'arm64'
04-03 19:01:50.174 25501-25501/? A/DEBUG: pid: 25361, tid: 25404, name: GLThread 3290 >>> com.mygdx.game <<<
04-03 19:01:50.174 25501-25501/? A/DEBUG: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x7a99fd63c0
04-03 19:01:50.174 25501-25501/? A/DEBUG: x0 0000007a99fd63c0 x1 00000000000000b8 x2 0000007899f841c0 x3 0000000000000002
04-03 19:01:50.174 25501-25501/? A/DEBUG: x4 0000000000000001 x5 0000000000000001 x6 0000000000000000 x7 0000000000000000
04-03 19:01:50.174 25501-25501/? A/DEBUG: x8 000000789a2e8098 x9 0000000000000000 x10 0000000000000001 x11 0000000000000001
04-03 19:01:50.174 25501-25501/? A/DEBUG: x12 000000789a91d718 x13 000000789a91d7b4 x14 00000078b7ab1150 x15 0000000000000060
04-03 19:01:50.174 25501-25501/? A/DEBUG: x16 000000789a2e7a18 x17 000000789a2b99d8 x18 0000000000000001 x19 0000007899f841c0
04-03 19:01:50.175 25501-25501/? A/DEBUG: x20 00000078b6888760 x21 0000007899f84200 x22 0000000000000006 x23 00000078b0a86fa0
04-03 19:01:50.175 25501-25501/? A/DEBUG: x24 0000000000000048 x25 604eae760b11fb4a x26 00000078b80d5698 x27 00000078b80d5600
04-03 19:01:50.175 25501-25501/? A/DEBUG: x28 000000789a91d7b0 x29 000000789a91d6d0 x30 000000789a2bd004
04-03 19:01:50.175 25501-25501/? A/DEBUG: sp 000000789a91d6a0 pc 000000789a2b9a34 pstate 0000000080000000
04-03 19:01:50.180 25501-25501/? A/DEBUG: backtrace:
04-03 19:01:50.180 1295-1316/? I/Bluetooth_framework: BluetoothManagerService:Message: 401
04-03 19:01:50.181 25501-25501/? A/DEBUG: #00 pc 000000000001ba34 /data/app/com.mygdx.game-1/lib/arm64/libgdx-box2d.so (_ZN16b2BlockAllocator8AllocateEi+92)
04-03 19:01:50.181 25501-25501/? A/DEBUG: #01 pc 000000000001f000 /data/app/com.mygdx.game-1/lib/arm64/libgdx-box2d.so (_ZN7b2World10CreateBodyEPK9b2BodyDef+48)
04-03 19:01:50.181 25501-25501/? A/DEBUG: #02 pc 000000000002f6d0 /data/app/com.mygdx.game-1/lib/arm64/libgdx-box2d.so (Java_com_badlogic_gdx_physics_box2d_World_jniCreateBody+160)
04-03 19:01:50.181 25501-25501/? A/DEBUG: #03 pc 00000000000db790 /system/lib64/libart.so (art_quick_generic_jni_trampoline+144)
04-03 19:01:50.181 25501-25501/? A/DEBUG: #04 pc 00000000000d21b4 /system/lib64/libart.so (art_quick_invoke_stub+580)
04-03 19:01:50.181 25501-25501/? A/DEBUG: #05 pc 00000000000dee80 /system/lib64/libart.so (_ZN3art9ArtMethod6InvokeEPNS_6ThreadEPjjPNS_6JValueEPKc+204)
04-03 19:01:50.181 25501-25501/? A/DEBUG: #06 pc 000000000028cbf0 /system/lib64/libart.so (_ZN3art11interpreter34ArtInterpreterToCompiledCodeBridgeEPNS_6ThreadEPNS_9ArtMethodEPKNS_7DexFile8CodeItemEPNS_11ShadowFrameEPNS_6JValueE+312)
04-03 19:01:50.181 25501-25501/? A/DEBUG: #07 pc 0000000000286cac /system/lib64/libart.so (_ZN3art11interpreter6DoCallILb1ELb0EEEbPNS_9ArtMethodEPNS_6ThreadERNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+444)
04-03 19:01:50.181 25501-25501/? A/DEBUG: #08 pc 00000000005556e4 /system/lib64/libart.so (MterpInvokeDirectRange+384)
04-03 19:01:50.181 25501-25501/? A/DEBUG: #09 pc 00000000000c4f94 /system/lib64/libart.so (ExecuteMterpImpl+15252)
[ 04-03 19:01:50.536 402: 402 W/ ]
debuggerd: resuming target 25361
I've also tested an emulator which have the same android version of my phone and it worked. ( it is version 7 api 24 ). So it isn't the problem.
ps: I don't destroy twice a body (I've put some condition to avoid it).
I am a noob of libgdx please help <3 (and sorry for my bad english!)
EDIT : To answers a question in the comment of "Subrata M" here is the logcat if i put the destroy method after the update and the createEnemy().
04-03 20:26:59.973 29708-29747/com.mygdx.game A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x7a9a07b400 in tid 29747 (GLThread 3385)
04-03 20:26:59.974 2497-2497/? I/WearableService: Wearable Services stopping
[ 04-03 20:26:59.976 402: 402 W/ ]
debuggerd: handling request: pid=29708 uid=10171 gid=10171 tid=29747
04-03 20:27:00.017 1600-1600/? W/HwKeyguardDragHelper: AnimationBlocked
04-03 20:27:00.025 1600-1600/? I/EventCenter: EventCenter Get :android.intent.action.TIME_TICK
04-03 20:27:00.032 1600-1600/? W/HwKeyguardDragHelper: AnimationBlocked
04-03 20:27:00.039 1600-1600/? E/DateLunarView: mDateString is: mar 3 avr
04-03 20:27:00.042 1600-1600/? E/DateLunarView: mDateString is: mar 3 avr
04-03 20:27:00.054 2572-2572/? I/HwLauncher: Model onReceive intent=Intent { act=android.intent.action.TIME_TICK flg=0x50000014 (has extras) }
04-03 20:27:00.054 2572-2572/? I/HwLauncher: Model onReceive user=UserHandle{0}
04-03 20:27:00.079 29868-29868/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
04-03 20:27:00.079 29868-29868/? A/DEBUG: Build fingerprint: 'HUAWEI/PRA-LX1/HWPRA-H:7.0/HUAWEIPRA-LX1/C432B196:user/release-keys'
04-03 20:27:00.079 29868-29868/? A/DEBUG: Revision: '0'
04-03 20:27:00.079 29868-29868/? A/DEBUG: ABI: 'arm64'
04-03 20:27:00.079 29868-29868/? A/DEBUG: pid: 29708, tid: 29747, name: GLThread 3385 >>> com.mygdx.game <<<
04-03 20:27:00.079 29868-29868/? A/DEBUG: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x7a9a07b400
04-03 20:27:00.079 29868-29868/? A/DEBUG: x0 0000007a9a07b400 x1 00000000000000b8 x2 0000007899b36980 x3 0000000000000002
04-03 20:27:00.079 29868-29868/? A/DEBUG: x4 0000000000000001 x5 0000000000000001 x6 0000000000000000 x7 0000000000000000
04-03 20:27:00.079 29868-29868/? A/DEBUG: x8 000000789775e098 x9 0000000000000000 x10 0000000000000001 x11 0000000000000001
04-03 20:27:00.079 29868-29868/? A/DEBUG: x12 000000789aa1a7e8 x13 000000789aa1a884 x14 00000078b7ab1150 x15 0000000000000060
04-03 20:27:00.079 29868-29868/? A/DEBUG: x16 000000789775da18 x17 000000789772f9d8 x18 0000000000000001 x19 0000007899b36980
04-03 20:27:00.079 29868-29868/? A/DEBUG: x20 00000078b687a270 x21 0000007899b369c0 x22 0000000000000006 x23 00000078b6a13fa0
04-03 20:27:00.079 29868-29868/? A/DEBUG: x24 0000000000000048 x25 604eae760b11fb4a x26 00000078a908ca98 x27 00000078a908ca00
04-03 20:27:00.079 29868-29868/? A/DEBUG: x28 000000789aa1a880 x29 000000789aa1a7a0 x30 0000007897733004
04-03 20:27:00.079 29868-29868/? A/DEBUG: sp 000000789aa1a770 pc 000000789772fa34 pstate 0000000080000000
04-03 20:27:00.087 1600-1600/? W/ExpandableNotificationRow: setActionsBackground,null == view,mPublicLayout
04-03 20:27:00.089 1600-1600/? W/ExpandableNotificationRow: setActionsBackground,null == view,mPublicLayout
04-03 20:27:00.092 1600-1600/? W/ExpandableNotificationRow: setActionsBackground,null == view,mPublicLayout
04-03 20:27:00.094 1600-1600/? W/ExpandableNotificationRow: setActionsBackground,null == view,mPublicLayout
04-03 20:27:00.097 1600-1600/? W/HwKeyguardDragHelper: AnimationBlocked
04-03 20:27:00.098 29868-29868/? A/DEBUG: backtrace:
04-03 20:27:00.098 29868-29868/? A/DEBUG: #00 pc 000000000001ba34 /data/app/com.mygdx.game-2/lib/arm64/libgdx-box2d.so (_ZN16b2BlockAllocator8AllocateEi+92)
04-03 20:27:00.098 29868-29868/? A/DEBUG: #01 pc 000000000001f000 /data/app/com.mygdx.game-2/lib/arm64/libgdx-box2d.so (_ZN7b2World10CreateBodyEPK9b2BodyDef+48)
04-03 20:27:00.098 29868-29868/? A/DEBUG: #02 pc 000000000002f6d0 /data/app/com.mygdx.game-2/lib/arm64/libgdx-box2d.so (Java_com_badlogic_gdx_physics_box2d_World_jniCreateBody+160)
04-03 20:27:00.098 29868-29868/? A/DEBUG: #03 pc 00000000000db790 /system/lib64/libart.so (art_quick_generic_jni_trampoline+144)
04-03 20:27:00.098 29868-29868/? A/DEBUG: #04 pc 00000000000d21b4 /system/lib64/libart.so (art_quick_invoke_stub+580)
04-03 20:27:00.098 29868-29868/? A/DEBUG: #05 pc 00000000000dee80 /system/lib64/libart.so (_ZN3art9ArtMethod6InvokeEPNS_6ThreadEPjjPNS_6JValueEPKc+204)
04-03 20:27:00.098 29868-29868/? A/DEBUG: #06 pc 000000000028cbf0 /system/lib64/libart.so (_ZN3art11interpreter34ArtInterpreterToCompiledCodeBridgeEPNS_6ThreadEPNS_9ArtMethodEPKNS_7DexFile8CodeItemEPNS_11ShadowFrameEPNS_6JValueE+312)
04-03 20:27:00.098 29868-29868/? A/DEBUG: #07 pc 0000000000286cac /system/lib64/libart.so (_ZN3art11interpreter6DoCallILb1ELb0EEEbPNS_9ArtMethodEPNS_6ThreadERNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+444)
04-03 20:27:00.098 29868-29868/? A/DEBUG: #08 pc 00000000005556e4 /system/lib64/libart.so (MterpInvokeDirectRange+384)
04-03 20:27:00.098 29868-29868/? A/DEBUG: #09 pc 00000000000c4f94 /system/lib64/libart.so (ExecuteMterpImpl+15252)
04-03 20:27:00.123 2572-2572/? E/HW-JPEG-DEC: [HME_JPEG_DEC_Delete](3321): HME_JPEG_DEC_Delete: decoder_ctx=null
04-03 20:27:00.131 2572-2572/? E/HW-JPEG-DEC: [HME_JPEG_DEC_Delete](3321): HME_JPEG_DEC_Delete: decoder_ctx=null
04-03 20:27:00.136 2572-2572/? E/HW-JPEG-DEC: [HME_JPEG_DEC_Delete](3321): HME_JPEG_DEC_Delete: decoder_ctx=null
[ 04-03 20:27:00.390 402: 402 W/ ]
debuggerd: resuming target 29708
EDIT2 : I asked two friends to test the app. the first has got a oneplus 3t and it doesn't crash. The other has got a Huawei Mate 9 and it crash.
This is most certainly a box2d allocation issue and not a phone/make specific issue. What you can do is to set the body object to null when you destroy it and you will see what is happening.
Try this:
for (int i = 0; i < remove.size(); i++) {
world.destroyBody(remove.get(i));
remove.get(i) = null;
/*for (int n = 0; i < y.getJointList().size; n++){
world.destroyJoint(y.getJointList().get(n).joint);
}*/
}
remove.clear();

JNI table overflow in android app

I have an android app that goes back and forth between a couple of screens organized as fragments of an activity that uses a viewPager to make scrolling possible.
When moving too much within these screens the app crashes with an
JNI ERROR (app bug): local reference table overflow (max=512)
here is the stacktrace:
03-23 13:25:56.781 8120-8506/com.example.debug A/art: art/runtime/indirect_reference_table.cc:127] JNI ERROR (app bug): local reference table overflow (max=512)
03-23 13:25:56.781 8120-8506/com.example.debug A/art: art/runtime/indirect_reference_table.cc:127] local reference table dump:
03-23 13:25:56.781 8120-8506/com.example.debug A/art: art/runtime/indirect_reference_table.cc:127] Last 10 entries (of 512):
03-23 13:25:56.781 8120-8506/com.example.debug A/art: art/runtime/indirect_reference_table.cc:127] 511: 0x144abc00 long[] (6 elements)
03-23 13:25:56.781 8120-8506/com.example.debug A/art: art/runtime/indirect_reference_table.cc:127] 510: 0x144abbc0 long[] (6 elements)
03-23 13:25:56.781 8120-8506/com.example.debug A/art: art/runtime/indirect_reference_table.cc:127] 509: 0x144abb80 long[] (6 elements)
03-23 13:25:56.781 8120-8506/com.example.debug A/art: art/runtime/indirect_reference_table.cc:127] 508: 0x144abb40 long[] (6 elements)
03-23 13:25:56.781 8120-8506/com.example.debug A/art: art/runtime/indirect_reference_table.cc:127] 507: 0x144abb00 long[] (6 elements)
03-23 13:25:56.781 8120-8506/de.everskill.everskill.debug A/art: art/runtime/indirect_reference_table.cc:127] 506: 0x144abac0 long[] (6 elements)
03-23 13:25:56.781 8120-8506/de.everskill.everskill.debug A/art: art/runtime/indirect_reference_table.cc:127] 505: 0x144aba80 long[] (6 elements)
03-23 13:25:56.781 8120-8506/de.everskill.everskill.debug A/art: art/runtime/indirect_reference_table.cc:127] 504: 0x144aba40 long[] (6 elements)
03-23 13:25:56.781 8120-8506/de.everskill.everskill.debug A/art: art/runtime/indirect_reference_table.cc:127] 503: 0x144aba00 long[] (6 elements)
03-23 13:25:56.781 8120-8506/de.everskill.everskill.debug A/art: art/runtime/indirect_reference_table.cc:127] 502: 0x144ab9c0 long[] (6 elements)
03-23 13:25:56.781 8120-8506/de.everskill.everskill.debug A/art: art/runtime/indirect_reference_table.cc:127] Summary:
03-23 13:25:56.781 8120-8506/de.everskill.everskill.debug A/art: art/runtime/indirect_reference_table.cc:127] 511 of long[] (6 elements) (511 unique instances)
03-23 13:25:56.781 8120-8506/de.everskill.everskill.debug A/art: art/runtime/indirect_reference_table.cc:127] 1 of java.lang.Thread
03-23 13:25:56.781 8120-8506/de.everskill.everskill.debug A/art: art/runtime/indirect_reference_table.cc:127]
03-23 13:25:56.781 3493-3573/? D/StatusBarManagerService: manageDisableList userId=0 what=0x0 pkg=Window{5a171b1 u0 d0 Starting de.everskill.everskill.debug}
03-23 13:25:56.791 3035-3035/? D/libEGL: eglInitialize EGLDisplay = 0x7fff60dac8
03-23 13:25:56.791 1976-1976/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
03-23 13:25:56.791 1976-1976/? A/DEBUG: Build fingerprint: 'samsung/zerofltexx/zeroflte:6.0.1/MMB29K/G920FXXU5DQA7:user/release-keys'
03-23 13:25:56.791 1976-1976/? A/DEBUG: Revision: '11'
03-23 13:25:56.791 1976-1976/? A/DEBUG: ABI: 'arm64'
03-23 13:25:56.791 1976-1976/? A/DEBUG: pid: 8120, tid: 8699, name: pool-2-thread-1 >>> de.everskill.everskill.debug <<<
03-23 13:25:56.791 1976-1976/? A/DEBUG: signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
03-23 13:25:56.811 1976-1976/? A/DEBUG: Abort message: 'art/runtime/indirect_reference_table.cc:127] JNI ERROR (app bug): local reference table overflow (max=512)'
03-23 13:25:56.811 1976-1976/? A/DEBUG: x0 0000000000000000 x1 00000000000021fb x2 0000000000000006 x3 0000000000000000
03-23 13:25:56.811 1976-1976/? A/DEBUG: x4 0000000000000000 x5 0000000000000001 x6 0000000000000000 x7 0000000000000000
03-23 13:25:56.811 1976-1976/? A/DEBUG: x8 0000000000000083 x9 0000000000016240 x10 000000000057d960 x11 000000000057daa0
03-23 13:25:56.811 1976-1976/? A/DEBUG: x12 0000000000000000 x13 0000007f960f5000 x14 0000000000000000 x15 0000007f960e7000
03-23 13:25:56.811 1976-1976/? A/DEBUG: x16 0000007f960e7568 x17 0000007f9607a338 x18 0000000000000000 x19 0000007f59dff500
03-23 13:25:56.811 1976-1976/? A/DEBUG: x20 0000007f59dff440 x21 0000000000000011 x22 0000000000000006 x23 0000007f64056240
03-23 13:25:56.811 1976-1976/? A/DEBUG: x24 0000007f9236cbc0 x25 0000007f78ac5200 x26 0000007f92475bc0 x27 0000000000000001
03-23 13:25:56.811 1976-1976/? A/DEBUG: x28 0000007f64056100 x29 0000007f59dfe8b0 x30 0000007f96077ad4
03-23 13:25:56.811 1976-1976/? A/DEBUG: sp 0000007f59dfe8b0 pc 0000007f9607a340 pstate 0000000020000000
03-23 13:25:56.821 1976-1976/? A/DEBUG: backtrace:
03-23 13:25:56.821 1976-1976/? A/DEBUG: #00 pc 0000000000069340 /system/lib64/libc.so (tgkill+8)
03-23 13:25:56.821 1976-1976/? A/DEBUG: #01 pc 0000000000066ad0 /system/lib64/libc.so (pthread_kill+68)
03-23 13:25:56.821 1976-1976/? A/DEBUG: #02 pc 0000000000023910 /system/lib64/libc.so (raise+28)
03-23 13:25:56.821 1976-1976/? A/DEBUG: #03 pc 000000000001e240 /system/lib64/libc.so (abort+60)
03-23 13:25:56.821 1976-1976/? A/DEBUG: #04 pc 0000000000430e38 /system/lib64/libart.so (_ZN3art7Runtime5AbortEv+304)
03-23 13:25:56.821 1976-1976/? A/DEBUG: #05 pc 00000000001373a4 /system/lib64/libart.so (_ZN3art10LogMessageD2Ev+3136)
03-23 13:25:56.821 1976-1976/? A/DEBUG: #06 pc 0000000000272f88 /system/lib64/libart.so (_ZN3art22IndirectReferenceTable3AddEjPNS_6mirror6ObjectE+372)
03-23 13:25:56.821 1976-1976/? A/DEBUG: #07 pc 000000000035bff0 /system/lib64/libart.so (_ZN3art3JNI21GetObjectArrayElementEP7_JNIEnvP13_jobjectArrayi+472)
03-23 13:25:56.821 1976-1976/? A/DEBUG: #08 pc 0000000000156ee0 /system/lib64/libart.so (_ZN3art8CheckJNI21GetObjectArrayElementEP7_JNIEnvP13_jobjectArrayi+524)
03-23 13:25:56.821 1976-1976/? A/DEBUG: #09 pc 0000000000052ef4 /data/app/de.everskill.everskill.debug-3/lib/arm64/librealm-jni.so (Java_io_realm_internal_TableQuery_nativeBatchUpdateQueries+616)
03-23 13:25:56.821 1976-1976/? A/DEBUG: #10 pc 00000000018e6d40 /data/app/de.everskill.everskill.debug-3/oat/arm64/base.odex (offset 0xddf000) (long[] io.realm.internal.TableQuery.nativeBatchUpdateQueries(long, long[], long[][], long[][], boolean[][])+244)
03-23 13:25:56.821 1976-1976/? A/DEBUG: #11 pc 0000000001903578 /data/app/de.everskill.everskill.debug-3/oat/arm64/base.odex (offset 0xddf000) (void io.realm.internal.async.QueryUpdateTask.run()+588)
03-23 13:25:56.821 1976-1976/? A/DEBUG: #12 pc 0000000001900748 /data/app/de.everskill.everskill.debug-3/oat/arm64/base.odex (offset 0xddf000) (void io.realm.internal.async.BgPriorityRunnable.run()+140)
03-23 13:25:56.821 1976-1976/? A/DEBUG: #13 pc 0000000003492ec0 /system/framework/arm64/boot.oat (offset 0x2f48000)
What I got from googleing is that I am basically not cleaning up the memory I allocate and since I never leave the activity it is not done by the garbage collector automatically.
So I need to manullay release the allocated memory. But can you hint me towards anything on what to look for?
What kind of elements do allocate memory in this JNI Table?
And what is the JNI table?
How do I free memory in the table?
Thanks a lot guys!
Best
TobHo

Fatal Signal 11 (SIGSEGV) occurred in Android Studio program

An error occurs at times (more often than not, actually).
A/libc: Fatal signal 11 (SIGSEGV) at 0x830ab2cc (code=1), thread 24294 (Thread-1174)
The code is as follows:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.displaygraph);
Intent intent = getIntent();
GraphView graph = (GraphView) findViewById(R.id.graph);
series = new LineGraphSeries<DataPoint>();
graph.addSeries(series);
Viewport viewport = graph.getViewport();
viewport.setYAxisBoundsManual(true);
viewport.setXAxisBoundsManual(true);
viewport.setMinY(0);
double max=data[0];
for (int i = 0; i < data.length; i++) {
if (data[i] > max) {
max = data[i];
Log.w(TAG,"max"+max);
}
}
viewport.setMaxY(max);
viewport.setMinX(0);
viewport.setMaxX(450);
graph.getViewport().setScalable(true);
graph.getViewport().setScalableY(true);
seriesecg = new LineGraphSeries<DataPoint>();
GraphView graphecg = (GraphView) findViewById(R.id.graphecg);
graphecg.addSeries(seriesecg);
Viewport viewportecg = graphecg.getViewport();
viewportecg.setYAxisBoundsManual(true);
viewportecg.setXAxisBoundsManual(true);
viewportecg.setMinY(0);
viewportecg.setMaxY(3000);
viewportecg.setMinX(0);
viewportecg.setMaxX(450);
graphecg.getViewport().setScalable(true);
graphecg.getViewport().setScalableY(true);
}
#Override
protected void onResume() {
super.onResume();
new Thread(new Runnable() {
#Override
public void run() {
// we add 450 new entries
for (int i = 0; i <= 449; i++) {
final int finalI = i;
final int finalII = i;
Log.w(TAG, "finalI"+finalI);
runOnUiThread(new Runnable() {
#Override
public void run() {
addEntry(finalI,ppg);
}
});
// sleep to slow down the add of entries
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// manage error ...
}
}
}
}).start();
}
// add random data to graph
private void addEntry(int i,double[] data) {
if(i<=449) {
Log.w(TAG, "ppg" + data[i]+"/"+i);
series.appendData(new DataPoint(i, data[i]), false, 450);
}
}
The logcat is as follows:
01-22 19:27:01.650 1041-1370/? I/KeyguardUpdateMonitor: visibility is same
01-22 19:27:01.650 818-818/? D/CrashAnrDetector: Build: samsung/lt03ltezs/lt03lte:4.4.2/KOT49H/P605ZSUCOD1:user/release-keys
Hardware: MSM8974
Revision: 11
Bootloader: P605ZSUCOD1
Radio: unknown
Kernel: Linux version 3.4.0-4665213 (dpi#SWDD5621) (gcc version 4.7 (GCC) ) #1 SMP PREEMPT Mon Apr 13 11:19:19 KST 2015
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Build fingerprint: 'samsung/lt03ltezs/lt03lte:4.4.2/KOT49H/P605ZSUCOD1:user/release-keys'
Revision: '11'
pid: 12476, tid: 12476, name: elerometergraph >>> com.android.accelerometergraph <<<
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 82f5583c
r0 402aaedb r1 82f55838 r2 402aaed8 r3 42caa968
r4 bedfd1b8 r5 42277008 r6 bedfd20c r7 402aaaa8
r8 00000000 r9 42caad98 sl 416b049c fp 80000000
ip 00000003 sp bedfd010 lr 4172ff51 pc 4172ff3e cpsr 900f0030
d0 0080000000001000 d1 0200000000004000
d2 0000000000000008 d3 0000888800000000
d4 0000004080000000 d5 0000200000000000
d6 1000000000200000 d7 0000800000000010
d8 44618b1844624bf2 d9 3e99999a4040da00
d10 43380000c3892666 d11 c389266644618b18
d12 4252ccd044624bf2 d13 c07124cccccccccd
d14 4034000000000000 d15 43a38000c3892666
d16 0100000000000000 d17 0004400000020000
d18 0004400000000000 d19 2000010000440000
d20 000a402000088100 d21 0000000000044000
d22 0022000000008800 d23 1100000000000000
d24 3fd1b10853a79915 d25 3fd554fa9ca0567a
d26 3fdb6db71408e660 d27 3fe33333332d4313
d28 3ff0000000000000 d29 0000000000000001
d30 4059000000000000 d31 4024000000000000
scr 20000013
backtrace:
#00 pc 00075f3e /system/lib/libdvm.so (mspace_bulk_free+89)
#01 pc 00076e63 /system/lib/libdvm.so (dvmHeapSourceFreeList(unsigned int, void**)+70)
#02 pc 0003a7b4 /system/lib/libdvm.so
#03 pc 0002c4ec /system/lib/libdvm.so (dvmHeapBitmapSweepWalk(HeapBitmap const*, HeapBitmap const*, unsigned int, unsigned int, void (*)(unsigned int, void**, void*), void*)+176)
#04 pc 0003b53c /system/lib/libdvm.so (dvmHeapSweepUnmarkedObjects(bool, bool, unsigned int*, unsigned int*)+284)
#05 pc 0002c94c /system/lib/libdvm.so (dvmCollectGarbageInternal(GcSpec const*)+452)
#06 pc 0002d45c /system/lib/libdvm.so (dvmMalloc(unsigned int, int)+356)
#07 pc 0006cb03 /system/lib/libdvm.so
#08 pc 0002c36f /dev/ashmem/dalvik-jit-code-cache (deleted)
stack:
bedfcfd0 bedfd1ec [stack]
bedfcfd4 40129d5d /system/lib/libc.so (realloc+12)
bedfcfd8 00000008
bedfcfdc bedfd2a8 [stack]
bedfcfe0 78e476f8
bedfcfe4 00000000
bedfcfe8 00000003
bedfcfec bedfd100 [stack]
bedfcff0 42ca9b88 /dev/ashmem/dalvik-heap (deleted)
bedfcff4 bedfd174 [stack]
bedfcff8 42277008 /dev/ashmem/dalvik-heap (deleted)
bedfcffc bedfd20c [stack]
bedfd000 42caa968 /dev/ashmem/dalvik-heap (deleted)
bedfd004 00000000
bedfd008 42caa950 /dev/ashmem/dalvik-heap (deleted)
bedfd00c 4172ff51 /system/lib/libdvm.so (mspace_bulk_free+108)
#00 bedfd010 00029864
bedfd014 416b0438
bedfd018 00000065
bedfd01c 00000065
bedfd020 bedfd078 [stack]
bedfd024 416b0438
bedfd028 42277008 /dev/ashmem/dalvik-heap (deleted)
bedfd02c 41730e67 /system/lib/libdvm.so (dvmHeapSourceFreeList(unsigned int, void**)+74)
#01 bedfd030 00000065
bedfd034 402abf98 /system/lib/libandroidfw.so
bedfd038 bedfd2cc [stack]
bedfd03c bedfd2cc [stack]
bedfd040 00000065
bedfd044 61fff040 /dev/ashmem/dalvik-bitmap-2 (deleted)
bedfd048 617ff040 /dev/ashmem/dalvik-bitmap-1 (deleted)
bedfd04c 0001acbf
bedfd050 bedfd078 [stack]
bedfd054 416f47b8 /system/lib/libdvm.so
#02 bedfd058 00000000
bedfd05c 00000000
bedfd060 00000030
bedfd064 00015010
bedfd068 01501
01-22 19:27:01.650 818-818/? D/CrashAnrDetector: processName:com.android.accelerometergraph
01-22 19:27:01.650 818-818/? D/CrashAnrDetector: broadcastEvent : com.android.accelerometergraph SYSTEM_TOMBSTONE
01-22 19:27:01.660 1041-1055/? D/KeyguardUpdateMonitor: sendKeyguardVisibilityChanged(true)
01-22 19:27:01.660 1041-1055/? I/KeyguardUpdateMonitor: visibility is same
Sometimes the code works but sometimes it doesn't... but when it occurs, it does so before the value of i reaches 449. I thought it had something to do with my jni code. but after commenting and deleting everything that would call a c code, the error still occurred.
Thank you for your help...

I got following error while exec shell in android jni

I need to change the file name(/system/etc/asound.conf) in android native jni.
I can do this in serial port by run shell cmd:
mount -o remount rw /system
busybox mv /system/etc/asound.conf /system/etc/asoundback.conf
mount -o remount r /system
First, I run above shell script in in java by invoking Runtime.getRuntiem(String). Ihis will result in all android system services reload. So I didn't do like this.
I run above shell script in jni by invoking system() like this:
android_media_AudioSystem_changeFileName(JNIEnv *env, jobject thiz, jstring from, jstring to)
{
const jchar* c_from = env->GetStringCritical(from, 0);
String8 c_from8;
if (from) {
c_from8 = String8(c_from, env->GetStringLength(from));
env->ReleaseStringCritical(from, c_from);
}
const jchar* c_to = env->GetStringCritical(to, 0);
String8 c_to8;
if (to) {
c_to8 = String8(c_to, env->GetStringLength(to));
env->ReleaseStringCritical(to, c_to);
}
LOGV("*********** android_media_AudioSystem_changeFileName from: %s ,to: %s" ,c_from8 ,c_to8);
char buff[4096];
sprintf(buff ,"mount -o remount rw /system;busybox mv %s %s;mount -o remount r /system" ,c_from8 ,c_to8);
if(system(buff) == -1) return -1;
return 0;
}
It does not work. The log is:
[ 197.520000] mclkdiv = 2, bitclkdiv = 12
D/ALSAModule( 1160): open called for devices 00000002 in mode 0...
E/ALSALib ( 1160): external/alsa-lib/src/pcm/pcm.c:2203:(snd_pcm_open_noupdate) Unknown PCM AndroidPlayback_Speaker_normal
E/ALSALib ( 1160): external/alsa-lib/src/pcm/pcm.c:2203:(snd_pcm_open_noupdate) Unknown PCM AndroidPlayback_Speaker
E/ALSALib ( 1160): external/alsa-lib/src/pcm/pcm.c:2203:(snd_pcm_open_noupdate) Unknown PCM AndroidPlayback
I/ALSAModule( 1160): Initialized ALSA PLAYBACK device defaul
D/SoundSettings( 2041): ******* audio channel: codec
D/SoundSettings( 2041): ******* before asound-----> asoundback
I/AudioSystem( 2041): *********** android_media_AudioSystem_changeFileName
F/libc ( 2041): Fatal signal 11 (SIGSEGV) at 0xdeadbaad (code=1)
I/DEBUG ( 1155): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
I/DEBUG ( 1155): Build fingerprint: 'android:4.0.3/IML74K/eng.android.20120717.210618:eng/test-keys'
I/DEBUG ( 1155): pid: 2041, tid: 2041 >>> com.android.settings <<<
I/DEBUG ( 1155): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr deadbaadI/DEBUG ( 1155): r0 deadbaad r1 00000001 r2 40000000 r3 00000000
I/DEBUG ( 1155): r4 00000000 r5 00000027 r6 62100021 r7 411afa18
I/DEBUG ( 1155): r8 be9b8644 r9 be9b864c 10 4786445b fp be9b8684
I/DEBUG ( 1155): ip ffffffff sp be9b8618 lr 40068f01 pc 40065660 cpsr 60000030
I/DEBUG ( 1155): #00 pc 00017660 /system/lib/libc.so
I/DEBUG ( 1155): #01 pc 0006f9de /system/lib/libandroid_runtime.so
I/DEBUG ( 1155): #02 pc 0001ebf0 /system/lib/libdvm.so (dvmPlatformInvoke)
I/DEBUG ( 1155): #03 pc 00058c38 /system/lib/libdvm.so (_Z16dvmCallJNIMethodPKjP6JValuePK6MethodP6Thread)
I/DEBUG ( 1155):
I/DEBUG ( 1155): code around pc:
I/DEBUG ( 1155): 40065640 4623b15c 2c006824 e026d1fb b12368db \.#F$h.,..&..h#.
I/DEBUG ( 1155): 40065650 21014a17 6011447a 48124798 24002527 .J.!zD.`.G.H'%.$
I/DEBUG ( 1155): 40065660 f7f47005 2106ef70 effef7f5 460aa901 .p..p..!.......F
I/DEBUG ( 1155): 40065670 f04f2006 94015380 94029303 ebc8f7f5 . O..S..........
I/DEBUG ( 1155): 40065680 4622a905 f7f52002 f7f4ebd2 2106ef5c .."F. ......\..!
I/DEBUG ( 1155):
I/DEBUG ( 1155): code around lr:
I/DEBUG ( 1155): 40068ee0 41f0e92d 46804c0c 447c2600 68a56824 -..A.L.F.&|D$h.h
I/DEBUG ( 1155): 40068ef0 e0076867 300cf9b5 dd022b00 47c04628 gh.....0.+..(F.G
I/DEBUG ( 1155): 40068f00 35544306 37fff117 6824d5f4 d1ee2c00 .CT5...7..$h.,..
I/DEBUG ( 1155): 40068f10 e8bd4630 bf0081f0 000285fa 41f0e92d 0F..........-..A
I/DEBUG ( 1155): 40068f20 fb01b086 9004f602 461f4815 4615460c .........H.F.F.F
I/DEBUG ( 1155):
I/DEBUG ( 1155): memory map around addr deadbaad:
Someelse can help me ? Thanks a lot!!!
I am not an expert in the tracelogs, but from what I can make of it you have :
1. Fatal signal 11 (SIGSEGV) at 0xdeadbaad (code=1)
this means memory corruption, deadbaad means corrupted memory..
2. I/DEBUG ( 1155): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr deadbaadI/DEBUG ( 1155): r0 deadbaad r1 00000001 r2 40000000 r3 00000000
this means the registries are null or 0..
I cannot help further, since I have no idea what you'r doing, but I guess that you are making a wrong read somewhere..

Categories