x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Crashing passing Java object back to Java

I'm attempting some Bitmap manipulation in Java with C++ reading the data. I'm about to work on a roundabout that eliminates the jobject passing to and fro causing me problems but would like to know what I'm doing wrong.

Basic flow is:

  1. Java grabs a Bitmap from the device.

  2. Bitmap is passed to C++ (received as jobject).

  3. C++ asks Java for sub crop of object, or for its data as jpg data that we then load into a UTexture2D.

This flow is not my first choice, but a work around for ReadPixels not working on mobile devices.

The problem I have is that the Java jobject I am returned is being complained about by the JNI when I pass it back to Java (my workaround is going to be to store it in the java only).

This is the output

 10-06 17:41:07.831 23059 23059 E ARToolKitLog: LOOKHERE: ***Test scale fn (1)
 10-06 17:41:07.831 23059 23059 E ARToolKitLog: LOOKHERE: ***AndroidThunkJava_ScaleImage: android.graphics.Bitmap@dd06274 w:32 h:32
 10-06 17:41:07.833 23059 23059 E ARToolKitLog: LOOKHERE: ***Returning to C++

This line comes next, from C++ (function - the image resolution returned to C++ is probably correct I haven't checked)

 10-06 17:41:07.834 23059 23059 I CameraLOG: LOOKHERE: test scale of image: ff8229c0 (3036 x 4048)

And then a JNI error.

 10-06 17:41:07.874 23059 23059 F zygote  : java_vm_ext.cc:504] JNI DETECTED ERROR IN APPLICATION: thread Thread[1,tid=23059,Native,Thread*=0xe8ac5000,peer=0x72cd9568,"main"] using JNIEnv* from thread Thread[12,tid=23100,Runnable,Thread*=0xdf5a3400,peer=0x12dc06e8,"Thread-2"]

A little further in the output we see this. 10-06 17:41:07.875 23059 23059 F zygote : java_vm_ext.cc:504] native: #13 pc 093a59ec /data/app/com.MatchyMaximus.Matchoo-udeLgRRxh3lx5V2366qIaA==/lib/arm/libUE4.so (_Z26AndroidThunkCpp_ScaleImageP8_jobjectii+152)

In Java we have this (response to a game activity)

 try {
   bmp = android.provider.MediaStore.Images.Media.getBitmap(cr, mImageUri);
 
   android.util.Log.e("ARToolKitLog", "LOOKHERE: ***Test scale fn (1)");
   AndroidThunkJava_ScaleImage(bmp, 32, 32);
 
   android.util.Log.e("ARToolKitLog", "LOOKHERE: ***Returning to C++");
   CPPOnCameraResult(true, bmp, bmp.getWidth(), bmp.getHeight());
 } catch (FileNotFoundException ex)

The Java scale image function looks like this:

    public Object AndroidThunkJava_ScaleImage(Object _img, int width, int height)
     {
       android.util.Log.e("ARToolKitLog", "LOOKHERE: ***AndroidThunkJava_ScaleImage: " + _img + " w:" + width + " h:" + height);
 
       Bitmap bmp = (Bitmap)_img;
       return Bitmap.createScaledBitmap(bmp, width, height, false);
     }
 

This function tries (for testing purposes) to throw the image back to java and fails.

 extern "C" void Java_com_epicgames_ue4_GameActivity_CPPOnCameraResult(JNIEnv* LocalJNIEnv, jobject LocalThiz, jboolean success, jobject img, jint width, jint height)
 {
     if (success)
     {
         __android_log_print(ANDROID_LOG_INFO, LOG_TAG, "LOOKHERE: test scale of image: %x (%d x %d)", (int)img, width, height);
         AndroidThunkCpp_ScaleImage(img, 32, 32);
         __android_log_print(ANDROID_LOG_INFO, LOG_TAG, "LOOKHERE: test scale of image PASSED");
     }
     FAndroidCameraModule::ReturnImageToCPP(success, img, width, height);
 }
 
 

Full log is attached.

Product Version: UE 4.17
Tags:
more ▼

asked Oct 07 '17 at 01:13 AM in C++ Programming

avatar image

theonecalledtom
1.3k 61 70 271

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question