• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by ning · Dec 08, 2011 at 08:48 AM · androidpluginjni

SEGV_ACCERR issue in java plugin

Hi there, recently I am experiencing SIGSEGV and SEGV_ACCERR issue in my Unity3D project.

My Unity project is deployed in Android 2.3.1 platform with a java library plug-in. But each time the native method is called, the logcat shows following log messages and then application is shut down:

 12-08 15:40:31.729: I/DEBUG(1238): Build fingerprint: 'hutch_aus/htc_vision/vision:2.3.3/GRI40/91002:user/release-keys'
 12-08 15:40:31.729: I/DEBUG(1238): pid: 29586, tid: 29588  >>> com.mdg.android.unity3dtext <<<
 12-08 15:40:31.729: I/DEBUG(1238): signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 450a89e8
 12-08 15:40:31.729: I/DEBUG(1238):  r0 00001000  r1 005f8a98  r2 00000000  r3 800a7678
 12-08 15:40:31.729: I/DEBUG(1238):  r4 fffffe78  r5 42091000  r6 00c05e7a  r7 460e9ec8
 12-08 15:40:31.729: I/DEBUG(1238):  r8 800903fd  r9 00000008  10 0059eb96  fp 0000000a
 12-08 15:40:31.729: I/DEBUG(1238):  ip 00001000  sp 44e9bd2c  lr 80052dc3  pc 80035f18  cpsr 40000010
 12-08 15:40:31.729: I/DEBUG(1238):  d0  0000000000681300  d1  4051704800323c61
 12-08 15:40:31.729: I/DEBUG(1238):  d2  002e00700070006c  d3  0069007400630020
 12-08 15:40:31.729: I/DEBUG(1238):  d4  00300031002c0035  d5  0033002c00370030
 12-08 15:40:31.729: I/DEBUG(1238):  d6  005b1fe000300030  d7  000000374d9cfcc5
 12-08 15:40:31.729: I/DEBUG(1238):  d8  000039c855517bdf  d9  0000000000000000
 12-08 15:40:31.729: I/DEBUG(1238):  d10 0000000000000000  d11 0000000000000000
 12-08 15:40:31.729: I/DEBUG(1238):  d12 0000000000000000  d13 0000000000000000
 12-08 15:40:31.729: I/DEBUG(1238):  d14 0000000000000000  d15 0000000000000000
 12-08 15:40:31.729: I/DEBUG(1238):  d16 0000000000000000  d17 3ff0000000000000
 12-08 15:40:31.729: I/DEBUG(1238):  d18 a2a2a2a2a2bacdcd  d19 cdcdcdcdbea3a2a2
 12-08 15:40:31.729: I/DEBUG(1238):  d20 4008000000000000  d21 0000000000000000
 12-08 15:40:31.729: I/DEBUG(1238):  d22 00000000000000a2  d23 3fcc7288e957b53b
 12-08 15:40:31.729: I/DEBUG(1238):  d24 3fc74721cad6b0ed  d25 3fc39a09d078c69f
 12-08 15:40:31.729: I/DEBUG(1238):  d26 0000000000000000  d27 0000000000000000
 12-08 15:40:31.729: I/DEBUG(1238):  d28 0000000000000000  d29 0000000000000000
 12-08 15:40:31.729: I/DEBUG(1238):  d30 0000000000000000  d31 0000000000000000
 12-08 15:40:31.729: I/DEBUG(1238):  scr 80000012

Here is my c# script of calling jni function:

 using UnityEngine;
 using System.Collections;
 using System.Runtime.InteropServices;
 using System;

 public class CallJavaCode : MonoBehaviour {
     [DllImport("javabridge")]
     private static extern void testFunction();
 
     private string cacheDir = "Click Me!";
     void OnGUI ()
     {
         if (GUI.Button(new Rect (15, 125, 450, 100), cacheDir))
         {
             testFunction();
         }
     }
 }

The jni function in *.so looks like this:

 void testFunction()
 {
     JNIEnv* jni_env = 0;
     java_vm->AttachCurrentThread(&jni_env, 0);
     __android_log_print(ANDROID_LOG_INFO, "JavaBridge", "[%s] called, attached to %08x\n", __FUNCTION__, jni_env);
     
     jni_env->CallObjectMethod(JavaClass, testMethodId);
 }

Here is my java library code in testMethod:

 public void testMethod(){    
         HttpParams params = new BasicHttpParams();
         HttpPost httppost = new HttpPost("some url ");
         HttpResponse response;
         
         params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
         HttpClient httpclient = new DefaultHttpClient(params);
         
         try {
             response = httpclient.execute(httppost);
         } catch (ClientProtocolException e) {
             // TODO Auto-generated catch block
         } catch (IOException e) {
             // TODO Auto-generated catch block
         }
 }

I am aware that the application crashes in code “response = httpclient.execute(httppost);”

So is it because there might be compatible issue between Unity3d and Android platform in httpclient.execute() or just something wrong with jni?

Can someone help?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by eriQue · Apr 13, 2012 at 02:37 PM

It's hard to say exactly where the problem is - the crash output is incomplete, and there could be possible hints just before the output above (if debug.checkjni is set), and right after you usually see the callstack etc.

If we assume that you get the __android_log_print output in the logcat, then the params to CallObjectMethod() could be invalid (there is no code showing how those are fetched).

But I would suggest to use the AndroidJavaObject et. al. if you only care about calling Java code from C# code - instead of writing the native bridge yourself. The code would then look something like:

 using(AndroidJavaObject javaClass = new AndroidJavaObject("java.class.name.here"))
 {
     javaClass.Call("testMethod");
 }

and only keep the .jar with your Java code in the plugins folder (there is no need for that libjavabridge.so then).

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Now that Unity 4.1.2 broke the Android plugin examples, what do you use to learn them? 1 Answer

using shared libraries generated by Android project in Unity 0 Answers

How to call an android notification plugin if it's not the main activity? 1 Answer

Using two Unity Android Plugins that want to be the main activity? 1 Answer

CreateJavaRuntime problem 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges