Hi again guys,

I found what was causing the random freeze/crash problem.

Thing is that I didn't know the JNIEnv pointer was thread-dependent. As a
result I was using the main thread's JNIEnv in GL thread to call my java
layer from c++

With the proper JNIEnv pointer things go smoothly.

Thanks for your efforts & time,

Florent.

2010/12/15 Bob Kerns <[email protected]>

> Ah. That should be easy enough to debug.
>
> Set a breakpoint at the log statement, and look at the stack. I bet
> you're doing something from the UI thread, that doesn't return. Thus
> the dialog code never gets run. If the breakpoint is not triggering in
> the UI thread, pause the UI thread and see what it is doing at the
> time.
>
> So long as you have something running on the UI thread, it's blocked
> for anything else, including dialogs.  If you are on the UI thread,
> and have some loop going on or something, you're going to need to
> return from it before the the Android dialog can be displayed.
>
> ANRs really aren't that hard to debug, though perhaps not always easy
> to fix. Just see what the UI thread is doing.
>
> On Dec 15, 12:50 am, Цветко ЛАГАЈОВИЋ <[email protected]>
> wrote:
> > Hi,
> >
> > Yes sorry, I have not been precise enough.
> >
> > When I say it's not working, what I meen is that the execution gets
> through
> > to the Java layer (the Log.i methods get called, and my message is logged
> in
> > logcat) but the dialog is not displayed, and the application does not
> > respond anymore. After some time I get an ANR notification and the app
> force
> > closes.
> >
> > Florent.
> >
> >
> >
> >
> >
> >
> >
> > On Wed, Dec 15, 2010 at 2:28 AM, Bob Kerns <[email protected]> wrote:
> > > What does "can't get it to work" mean?
> >
> > > Is mActivity really a reference to the correct activity?
> > > Does is successfully find the method, or take the 'return false;'
> > > exit? (Which is rather odd in a void method!)
> > > Does it crash?
> > > Does it call the Java code, but with a corrupted message?
> >
> > > If it's that last, I'd look for the usual C++ headaches, such as using
> > > a std::string() that has been destructed by the time you use it.
> >
> > > If it's crashing: Where is it crashing? How is mJNIEnv declared and
> > > assigned?
> >
> > > Have you stepped through it in a debugger? I don't know hard that is
> > > to do on a device (or emulator) with the NDK, but you could certainly
> > > write a little test app on your PC and test the C++ side there. You'd
> > > have to substitute on the Java side, of course; a simple
> > > System.out.println("Success: " + pMsg); would suffice.
> >
> > > If none of that helps, I'd suggest asking the question in a list that
> > > relates to the NDK rather than the SDK. You'd find a larger pool of
> > > people able to understand and answer your questions on the topic.
> >
> > > On Dec 14, 10:30 am, Floof <[email protected]> wrote:
> > > > Hi list !
> >
> > > > I'm having this problem:
> >
> > > > In my application, I use a GLSurfaceView for 3D rendering. The real
> > > > rendering is done by calling native methods, coded in C++.
> >
> > > > Once in a while (upon user clicks on 3D scene objects) the native
> > > > rendering engine should be able to call Java methods (through JNI)
> > > > that display a dialog box.
> >
> > > > I can't get it to work, that's driving me crazy.
> >
> > > > Here is the native method:
> >
> > > > [CODE]
> > > > void MyCPlusPlusClass::showDialog(const std::string& pMsg)
> > > > {
> > > >     jclass lClass = mJNIEnv->GetObjectClass(mActivity);
> > > >     if (!lClass)
> > > >     {
> > > >         return false;
> > > >     }
> > > >     jmethodID lMethId = mJNIEnv->GetMethodID(lClass,
> > > > "showMessageDialog", "(Ljava/lang/String;)V");
> > > >     if (!lMethId)
> > > >     {
> > > >         return false;
> > > >     }
> > > >     jstring lJavaString = mJNIEnv->NewStringUTF(pMessage.c_str());
> > > >     mJNIEnv->CallVoidMethod(mActivity, lMethId, lJavaString);}
> >
> > > > [/CODE]
> >
> > > > Then, the method showMessageDialog, coded in Java, in my activity:
> >
> > > > [CODE]
> > > > public void showMessageDialog(String pMsg)
> > > > {
> > > >     Log.i("Vg", "Create dialog with message " + pMsg);
> > > >     Log.i("Vg", "Show dialog");
> > > >     runOnUiThread(
> > > >         new Runnable () {
> > > >             public void run () {
> > > >                 AlertDialog.Builder lAlertBox = new
> > > > AlertDialog.Builder(this);
> > > >                 TextView lTextView = new TextView(MyActivity.this);
> > > >                 lTextView.setText(mMessage);
> > > >                 lAlertBox.setView(lTextView);
> > > >                 lAlertBox.setNeutralButton("Ok", MyActivity.this);
> > > >                 lAlertBox.setOnCancelListener(MyActivity.this);
> > > >                 lAlertBox.show();
> > > >             }
> > > >         }
> > > >     );}
> >
> > > > [/CODE]
> >
> > > > I thought this would work, but it doesn't. What am I doing wrong ?
> >
> > > > Thanks
> > > > Florent.
> >
> > > --
> > > You received this message because you are subscribed to the Google
> > > Groups "Android Developers" group.
> > > To post to this group, send email to
> [email protected]
> > > To unsubscribe from this group, send email to
> > > [email protected]<android-developers%[email protected]><android-developers%2Bunsubs
> [email protected]>
> > > For more options, visit this group at
> > >http://groups.google.com/group/android-developers?hl=en
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]<android-developers%[email protected]>
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to