Conflicts between Env->getbytearrayelements and Androidbitmap_getinfo in JNI (formerly)

Source: Internet
Author: User

Not very sure, the code of the previous period did not have problems, but today debugging for half a day, has been crashing: VM aborting.

Previous part of the code:

1JniexportvoidJnicall XXX2(jnienv*env,jobject Thiz, Jobject bitmap, Jbytearray databuf, jint width, jint height)3 {4jboolean* Parraydata = (jboolean*) env->getprimitivearraycritical (Databuf,0);5 androidbitmapinfo info;6     intret;7     if(ret = Androidbitmap_getinfo (env, Bitmap, &info)) <0)8     {9 XXX;Ten     } One     if(Info.format! =android_bitmap_format_rgba_8888) A     { - XXX; -     } the     if(ret = androidbitmap_lockpixels (env, Bitmap, &pixels)) <0) -     { - XXX; -     } + androidbitmap_unlockpixels (env, bitmap); -Env->releaseprimitivearraycritical (Databuf, Parraydata,0); +}

Later found that do not bitmap the code program is correct, or comment out the getprimitivearraycritical of the relevant code program is correct. But when both come together, the program crashes.

Then think about not using getprimitivearraycritical, and try it with another code.

1UnsignedChariscopy;2jbyte* parrayimgdata = env->getbytearrayelements (databuf,&iscopy); % It doesn't matter if you use iscopy here, as long as the last release corresponds to the line.
3   if(ret = Androidbitmap_getinfo (env, bitmaps, &info)) <0)
4 {5 XXX;6 } 7 XXX;8Env->releasebytearrayelements (databuf,parrayimgdata,iscopy);

The program will not crash.

PS: Still do not understand why the previous code can be used, today is not available (of course, there are other code in the previous code, today only use the part of the code).

Conflicts between Env->getbytearrayelements and Androidbitmap_getinfo in JNI (formerly)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.