Freetype2 returning pointers with negative value when seen as long

50 Views Asked by At

I am trying out FreeType2 with NDK in an android app.

The workflow I used is

  1. download freetype, unzip into my cpp folder 2.included freetype in the Cmakelists 3.It all compiles and sucessfully ran on emulator

But I have problems on real device connected.

Here is my activity/class do

  1. load the library using System.loadlibrary('mylib')
  2. Call cpp thru JNI
  3. function call , initializes FT (FT_Init_FreeType) and just returns the library handle (jlong)

On EMULATOR, it seems to be returning a proper handle BUT on real device I get large negative number back as handle..ie, something is going wrong...perhaps , in casting FT_Library (freetype) type to jlong which I am returning back to app.

Here is my cpp code for the call

   /*********THIS DOESNT WORK ON real USB connected device ******    
extern "C"
JNIEXPORT jlong JNICALL
Java_com_pearlspotsystems_nativecppwithft_MainActivity_getFTLibrary(JNIEnv *env, jobject thiz) 
{
      FT_Library library;

      int major, minor, patch;
      long err = FT_Init_FreeType(&library);
      if(err) {
        return 0;
      } else {
         return (jlong) library;
      }

}

On real device I am getting something like "-547637666626..." as handle back in app which doesnt look like a proper pointer/handle

1.Is this a problem of casting FT_Library to jlong ? or something else. 2. Why would it work on Emulator ? 3. Interestingly, my another function which initialises FT and get the version and return the details in a string works even on real device. Here is the CPP for that..

**/********THIS WORKS ON BOTH EMULATOR and REAL DEVICE!!!!***/**
extern "C"
JNIEXPORT jstring JNICALL
Java_com_pearlspotsystems_nativecppwithft_MainActivity_getFreeTypeVersion(JNIEnv *env,
                                                                     jobject thiz) {
FT_Library library;
int major, minor, patch;
long err = FT_Init_FreeType(&library);
if(err) {
    std::string err_string = "Error!!!!!!!";
    return env->NewStringUTF(err_string.c_str());
} else {
    FT_Library_Version((FT_Library) library, &major, &minor, &patch);
    std::string ret_string = "FT-Version:" + std::to_string(major) + "." + 
    std::to_string(minor);
    return env->NewStringUTF(ret_string.c_str());
}
}

What is going wrong ? Can someone point me in the right direction?

0

There are 0 best solutions below