Android - crash in ofLog

Hi,

I’ve run into a crash. By examining the log, I narrowed it down to a specific ofLogNotice line, here’s the crash log:

10-18 10:57:43.910: I/DEBUG(13362): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
10-18 10:57:43.910: I/DEBUG(13362): Build fingerprint: 'htc/htc_europe/htc_m8:5.0.1/LRX22C/448934.10:user/release-keys'
10-18 10:57:43.910: I/DEBUG(13362): Revision: '0'
10-18 10:57:43.910: I/DEBUG(13362): ABI: 'arm'
10-18 10:57:43.910: I/DEBUG(13362): pid: 4961, tid: 6383, name: Thread-39082  >>> com.trailze.client <<<
10-18 10:57:43.910: I/DEBUG(13362): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x94b91000
10-18 10:57:44.160: I/DEBUG(13362):     r0 00000000  r1 94b91003  r2 94b91000  r3 00000000
10-18 10:57:44.160: I/DEBUG(13362):     r4 94b8fe1c  r5 ffffffff  r6 0000011d  r7 94b8fe4c
10-18 10:57:44.160: I/DEBUG(13362):     r8 94b8fea0  r9 94b91008  sl 00000000  fp 00000041
10-18 10:57:44.170: I/DEBUG(13362):     ip 00000001  sp 94b8fd90  lr 0000011d  pc b6f6b4de  cpsr 600f0030
10-18 10:57:44.170: I/DEBUG(13362): backtrace:
10-18 10:57:44.170: I/DEBUG(13362):     #00 pc 000344de  /system/lib/libc.so (__vfprintf+1733)
10-18 10:57:44.170: I/DEBUG(13362):     #01 pc 00037dc5  /system/lib/libc.so (vsnprintf+88)
10-18 10:57:44.170: I/DEBUG(13362):     #02 pc 00002001  /system/lib/liblog.so (__android_log_print+44)
10-18 10:57:44.170: I/DEBUG(13362):     #03 pc 003c82b8  /mnt/asec/com.trailze.client-1/lib/arm/libOFAndroidApp.so (ofxAndroidLogChannel::log(ofLogLevel, std::string const&, std::string const&)+176)
10-18 10:57:44.170: I/DEBUG(13362):     #04 pc 00520c6c  /mnt/asec/com.trailze.client-1/lib/arm/libOFAndroidApp.so (ofLog::_log(ofLogLevel, std::string const&, std::string const&)+112)
10-18 10:57:44.170: I/DEBUG(13362):     #05 pc 00520a88  /mnt/asec/com.trailze.client-1/lib/arm/libOFAndroidApp.so (ofLog::~ofLog()+124)
10-18 10:57:44.170: I/DEBUG(13362):     #06 pc 002d2844  /mnt/asec/com.trailze.client-1/lib/arm/libOFAndroidApp.so (ofLogNotice::~ofLogNotice()+52)

I tried to see if there is any foul play in how I’m writing the log, but couldn’t find it. It’s basically like this:

{
MyStruct myStruct = fillTheStruct();
ofLogNotice(“someTag”) << “the value is: “ << myStruct.value;
}

The crash happens about 1 in 10 times. Removing the log line rectified the problem, but I guess the root cause is still present. There are two things that are special in this call. One is that I’m streaming “myStruct.value”, and not a precompiled value. It’s an std::string. Second, that string is quite large (a few thousand characters). But it doesn’t explain the issue, does it?

I couldn’t extract the line numbers (gdb stuff still doesn’t work for some reason), but it’s pretty clear that it crashes in ofxAndroidLogChannel.cpp, line #38:

__android_log_print(androidPrio,module.c_str(),msg.c_str());

I just can’t figure it out. Any ideas?

Thanks,

Tal

is the value a 0 terminated string? otherwise ift might be trying to access further than the actual string and making the app crash

It’s a std::string, not char*, so I don’t need to delimit it. Or do I???

no, you shouldn’t need to. are you accessing from different threads?

ofLog? Yes, I do. And sometimes I see in the log that the different log lines are getting jumbled together. But it supposed to be thread safe, isn’t it? Every log line is held in a different instance, and __android___log___print is thread safe AFAIK, isn’t it? Do you think it’s something related to that?

i’d say so but i’m not completely sure if it’s crashing consistently in the same call i’d say it’s not but if it’s crashing after a while and not always in from the same call then it’s probably a thread issue.

also setting the log level while loging is not thread safe

I do ofSetLogLevel() once in main. I do allot of logs in different threads, but this single log (a long one from a worker thread) is the one crashing, but not every time. It seems that it’s related to if some other logs are accidentally called on the same time. So no leads for now, huh? :confused:

no idea really it might be a bug in android with too long texts, you could try dividing it in several chunks to see if it fixes the problem

searching “__android_log_print crash”, “__android_log_print sigsegv”, etc, but couldn’t find any useful information. I removed the offending log line and the problem is resolved. For now. We’ll see if it will pop up some other place. Thanks!

Just a test; I print a string of 15K characters to the logcat: no error happening since 5 minutes (thousand times output). The problem doesn’t look like a long string issue.

Thanks for the test, @Rancs! I was too lazy to to make it myself…

UPDATE: after some more divide and conquer, I realized that it’s not a printing of a std::string but a printing of a JsonCpp:Value. So this may very well be a bug there. I also found out that the log in question is a log bigger than I thought, 180,000+ characters… So, I just removed the line for now and all is good. Thanks all.