[gdal-dev] SWIG JNI binding question with GetMetadataItem function

Even Rouault even.rouault at mines-paris.org
Fri Aug 12 17:02:15 EDT 2011


> 
> Indeed I was lacking the -fno-strict-aliasing switch in the C++ flags in
> my
> Android.mk file.
> 
> However, I've added this switch to both LOCAL_CFLAGS and LOCAL_CPPFLAGS
> for the libgdaljni.so build and I continue to get the error during
> execution.

At least now you have eliminated one potential source for issues ;-)

> 
> To add some more info to my original message, the actual error comes
> from
> within Java_org_gdal_gdal_gdalJNI_MajorObject_1GetMetadataItem_1_1SWIG10
> in
> gdal_wrap.cpp on the call to jenv->GetStringUTFChars(jarg2, 0).  First a
> JNI
> warning is issued, then the access violation appears to occur before
> that
> function can return, or at least before a debug statement I've added
> after
> the call can send its output to the Android LogCat output.

This is really weird. Did you test that in a Linux environement that the same 
code, with the same GDAL driver queried, works fine (hopefully yes...) ?

> 
> The error that's issued is related to jarg2 which is supposed to be a
> jstring, versus the jarg1 argument you mentioned which requires the
> upcast to GDALMajorObjectShadow.
> 
> I think I'll need to further debug the pointers that are being passed
> down to the *GetMetadataItem*1SWIG10* function.  None of them look
> outrageous at first glance.
> 
> Again, there's every reason to believe I'm missing something that's
> otherwise obvious to the experts so please feel free to continue
> sending ideas my way!

My only suggestion at that point is to use GetMetadata() instead to see if it 
works better. You'd be able to extract the item you are looking for in the 
list of strings it returns.

But I'm afraid that you'll encounter similar issues to one sooner or later 
with other JNI calls. There must be some memory corruption at some point. 
Obviously, there's no Valgrind like tool for Android... ?

> 
> Jim P.


More information about the gdal-dev mailing list