OSVR / OSVR-Android-Build

Repo with submodules for building OSVR for Android
Apache License 2.0
24 stars 17 forks source link

Crash on GearVR with Unity #10

Open janoc opened 9 years ago

janoc commented 9 years ago

I am getting this crash with Unity. The same code works OK when called from a Java app via JNI. Memory management problem? The same code works OK on PC/Windows.

This was tested against an external server with Razer Hydra (default empty config file) running on a PC, with both the localhost rewriting and the yet unmerged remote server API patches.

I/Unity   (13506):

I/Unity   (13506): (Filename: C Line: 0)

I/Unity   (13506):

I/Unity   (13506): [OSVR] Starting with app ID: com.reviatech.testapp4 and hostName2: 10.10.28.104

I/Unity   (13506): UnityEngine.Debug:Internal_Log(Int32, String, Object)

I/Unity   (13506): UnityEngine.Debug:Log(Object)

I/Unity   (13506): OSVR.Unity.ClientKit:EnsureStarted() (at C:\R\Dev\OSVR-Unity\OSVR-Unity\Assets\OSVRUnity\src\ClientKit.cs:79)

I/Unity   (13506): OSVR.Unity.ClientKit:OnEnable() (at C:\R\Dev\OSVR-Unity\OSVR-Unity\Assets\OSVRUnity\src\ClientKit.cs:101)

I/Unity   (13506):

I/Unity   (13506): (Filename: C Line: 0)

I/Unity   (13506):

I/DEBUG   (12910): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

I/DEBUG   (12910): Build fingerprint: 'samsung/zerofltexx/zeroflte:5.0.2/LRX22G/G920FXXU1AOE3:user/release-keys'

I/DEBUG   (12910): Revision: '11'

I/DEBUG   (12910): ABI: 'arm'

I/DEBUG   (12910): pid: 13506, tid: 13524, name: UnityMain  >>> com.Reviatech.gearvrosvr <<<

I/DEBUG   (12910): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0xe08005d8

I/DEBUG   (12910):     r0 0000007a  r1 e08005b8  r2 00000001  r3 f772cfac

I/DEBUG   (12910):     r4 e0800000  r5 ffffff28  r6 e087be94  r7 f7720650

I/DEBUG   (12910):     r8 f033ffc0  r9 0000000c  sl da682c98  fp efdfec3c

I/DEBUG   (12910):     ip e0875ec8  sp efdfebc8  lr f76c9819  pc f7700510  cpsr 20000030

I/DEBUG   (12910):

I/DEBUG   (12910): backtrace:

I/DEBUG   (12910):     #00 pc 00049510  /system/lib/libc.so (ifree+47)

I/DEBUG   (12910):     #01 pc 00012817  /system/lib/libc.so (free+10)

I/DEBUG   (12910):     #02 pc 001e81c4  /data/app/com.Reviatech.gearvrosvr-1/lib/arm/libosvrCommon.so (std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()+80)

I/DEBUG   (12910):     #03 pc 0017aa48  /data/app/com.Reviatech.gearvrosvr-1/lib/arm/libosvrCommon.so (Json::Reader::~Reader()+28)

I/DEBUG   (12910):     #04 pc 001a5f7c  /data/app/com.Reviatech.gearvrosvr-1/lib/arm/libosvrCommon.so (void osvr::common::serialization::JSONSerializationTraitsBase<osvr::common::serialization::JsonOn

lyMessageTag, osvr::common::serialization::StringOnlyMessageTag>::deserialize<osvr::common::BufferReader<osvr::common::ExternalBufferReadingWrapper<char> > >(osvr::common::BufferReader<osvr::common::E

xternalBufferReadingWrapper<char> >&, Json::Value&, osvr::common::serialization::JsonOnlyMessageTag const&)+268)

I/DEBUG   (12910):     #05 pc 001a5c60  /data/app/com.Reviatech.gearvrosvr-1/lib/arm/libosvrCommon.so (void osvr::common::serialization::deserializeRaw<Json::Value, osvr::common::BufferReader<osvr::co

mmon::ExternalBufferReadingWrapper<char> >, osvr::common::serialization::JsonOnlyMessageTag>(osvr::common::BufferReader<osvr::common::ExternalBufferReadingWrapper<char> >&, Json::Value&, osvr::common:

:serialization::JsonOnlyMessageTag const&)+36)

I/DEBUG   (12910):     #06 pc 001a58fc  /data/app/com.Reviatech.gearvrosvr-1/lib/arm/libosvrCommon.so (void osvr::common::serialization::DeserializeFunctor<osvr::common::BufferReader<osvr::common::Ext

ernalBufferReadingWrapper<char> > >::apply<Json::Value, osvr::common::serialization::JsonOnlyMessageTag>(boost::call_traits<Json::Value>::reference, osvr::common::serialization::JsonOnlyMessageTag con

st&)+44)

I/DEBUG   (12910):     #07 pc 001a55b0  /data/app/com.Reviatech.gearvrosvr-1/lib/arm/libosvrCommon.so (void osvr::common::serialization::DeserializeFunctor<osvr::common::BufferReader<osvr::common::Ext

ernalBufferReadingWrapper<char> > >::operator()<osvr::common::serialization::JsonOnlyMessageTag, Json::Value>(Json::Value&, osvr::common::serialization::JsonOnlyMessageTag const&)+36)

I/DEBUG   (12910):     #08 pc 001a5020  /data/app/com.Reviatech.gearvrosvr-1/lib/arm/libosvrCommon.so (void osvr::common::messages::ReplacementTreeFromServer::MessageSerialization::processMessage<osvr

::common::serialization::DeserializeFunctor<osvr::common::BufferReader<osvr::common::ExternalBufferReadingWrapper<char> > > >(osvr::common::serialization::DeserializeFunctor<osvr::common::BufferReader

<osvr::common::ExternalBufferReadingWrapper<char> > >&)+40)

I/DEBUG   (12910):     #09 pc 001a4844  /data/app/com.Reviatech.gearvrosvr-1/lib/arm/libosvrCommon.so (void osvr::common::deserialize<osvr::common::BufferReader<osvr::common::ExternalBufferReadingWrap

per<char> >, osvr::common::messages::ReplacementTreeFromServer::MessageSerialization>(osvr::common::BufferReader<osvr::common::ExternalBufferReadingWrapper<char> >&, osvr::common::messages::Replacemen

tTreeFromServer::MessageSerialization&)+48)

I/DEBUG   (12910):     #10 pc 001a41e4  /data/app/com.Reviatech.gearvrosvr-1/lib/arm/libosvrCommon.so (osvr::common::SystemComponent::m_handleReplaceTree(void*, vrpn_HANDLERPARAM)+132)

I/DEBUG   (12910):     #11 pc 001accd8  /data/app/com.Reviatech.gearvrosvr-1/lib/arm/libosvrCommon.so (vrpn_TypeDispatcher::doCallbacksFor(int, int, timeval, unsigned int, char const*)+456)

I/DEBUG   (12910):     #12 pc 001b3458  /data/app/com.Reviatech.gearvrosvr-1/lib/arm/libosvrCommon.so (vrpn_Endpoint::dispatch(int, int, timeval, unsigned int, char*)+164)

I/DEBUG   (12910):     #13 pc 001b30e0  /data/app/com.Reviatech.gearvrosvr-1/lib/arm/libosvrCommon.so (vrpn_Endpoint_IP::getOneTCPMessage(int, char*, unsigned int)+772)

I/DEBUG   (12910):     #14 pc 001b176c  /data/app/com.Reviatech.gearvrosvr-1/lib/arm/libosvrCommon.so (vrpn_Endpoint_IP::handle_tcp_messages(timeval const*)+604)

I/DEBUG   (12910):     #15 pc 001b06c8  /data/app/com.Reviatech.gearvrosvr-1/lib/arm/libosvrCommon.so (vrpn_Endpoint_IP::mainloop(timeval*)+1152)

I/DEBUG   (12910):     #16 pc 001b7450  /data/app/com.Reviatech.gearvrosvr-1/lib/arm/libosvrCommon.so (vrpn_Connection_IP::mainloop(timeval const*)+268)

I/DEBUG   (12910):     #17 pc 0013765c  /data/app/com.Reviatech.gearvrosvr-1/lib/arm/libosvrCommon.so (osvr::common::DeviceWrapper::m_update()+92)

I/DEBUG   (12910):     #18 pc 00126ab8  /data/app/com.Reviatech.gearvrosvr-1/lib/arm/libosvrCommon.so (osvr::common::BaseDevice::update()+168)

I/DEBUG   (12910):     #19 pc 000b0a08  /data/app/com.Reviatech.gearvrosvr-1/lib/arm/libosvrClient.so (osvr::client::PureClientContext::m_update()+272)

I/DEBUG   (12910):     #20 pc 000b0394  /data/app/com.Reviatech.gearvrosvr-1/lib/arm/libosvrClient.so (osvr::client::PureClientContext::PureClientContext(char const*, char const*)+1680)

I/DEBUG   (12910):     #21 pc 000a07b4  /data/app/com.Reviatech.gearvrosvr-1/lib/arm/libosvrClient.so (osvr::client::createContext(char const*, char const*)+172)

I/DEBUG   (12910):     #22 pc 00017e0c  /data/app/com.Reviatech.gearvrosvr-1/lib/arm/libosvrClientKit.so (osvrClientInitHost+132)

I/DEBUG   (12910):     #23 pc 0000f2cc  <unknown>

W/ActivityManager( 3522):   Force finishing activity com.Reviatech.gearvrosvr/com.unity3d.player.UnityPlayerActivity

I/DEBUG   (12910):

I/DEBUG   (12910): Tombstone written to: /data/tombstones/tombstone_00
janoc commented 9 years ago

Some additional info - this bug seems to be a known bug with JsonCPP on Android, probably due to some incompatibility with the Android NDK's C++ library implementation.

Here is a mention of this crash in Json::Reader destructor http://tech.bingfengsa.com/a/20131231/6513.html (translation: https://translate.google.fr/translate?sl=auto&tl=en&js=y&prev=_t&hl=en&ie=UTF-8&u=http%3A%2F%2Ftech.bingfengsa.com%2Fa%2F20131231%2F6513.html&edit-text=&act=url )

Basically the reporter suggests to use char * instead of std::string and/or use a single global instance of the Json::Reader() so that it is never destructed, thus avoiding the bug.

Here is a similar report where it was happening on PC, but with an old GCC version: http://stackoverflow.com/questions/17911438/jsoncpp-very-simple-test-crashes-when-jsonreader-goes-ot-of-scope

There is also this report of another crash problem from 2013 that was only fixed this year and it also mentions some sort of issue with the free() implementation on Android in the comment: http://sourceforge.net/p/jsoncpp/bugs/46/

Updating JSON to the latest version 1.6.2 vs. 1.2.1 doesn't fix the original crash, but it is probably a good idea anyway because of the fix from March this year.

janoc commented 9 years ago

OK, we have managed to get rid of this crash by:

I have tested the code with both GCC 4.9 and Clang 3.5 and it works with either, so I suspect it was a corner case caused by the gnustl_static linking.

araujobsd commented 8 years ago

Hello,

I guess we could close this issue, couldn't we?

Best,

janoc commented 8 years ago

@araujobsd I am not against, but please verify jsoncpp was updated since this. I know it has been in the mainstream OSVR, but not sure the fixes were merged to the Android repo as well. I am not working on Android right now.

araujobsd commented 8 years ago

OK, I will double check it.

Thanks for the prompt reply janoc :)

janoc commented 8 years ago

Welcome.