0
votes

I have a swig wrapper for jni @ ndk.

The function header is:

//
// Created by Tomasz on 03/11/2017.
//

#ifndef PC_ANDORID_APP_RESIZE_GIF_H
#define PC_ANDORID_APP_RESIZE_GIF_H

int Version();
int ResizeAnimation(const char * infile, const char * outfile);

#endif //PC_ANDORID_APP_RESIZE_GIF_H

The swig interface is simple as this:

%module GifResizer

%inline %{
    #include "resize-gif.h"

    extern int Version();
    extern int ResizeAnimation(const char * infile, const char * outfile);
%}

and the implementation of ResizeAnimation is:

int ResizeAnimation(const char * infile, const char * outfile) {
    initialize();
    /* ... */
    return 0;
}

The problem is, that value of params in Swig generater wrapper:

SWIGEXPORT jint JNICALL Java_org_imagemagick_GifResizerJNI_ResizeAnimation(JNIEnv *jenv, jclass jcls, jstring jarg1, jstring jarg2) {
  jint jresult = 0 ;
  char *arg1 = (char *) 0 ;
  char *arg2 = (char *) 0 ;
  int result;

  (void)jenv;
  (void)jcls;
  arg1 = 0;
  if (jarg1) {
    arg1 = (char *)(*jenv)->GetStringUTFChars(jenv, jarg1, 0);
    if (!arg1) return 0;
  }
  arg2 = 0;
  if (jarg2) {
    arg2 = (char *)(*jenv)->GetStringUTFChars(jenv, jarg2, 0);
    if (!arg2) return 0;
  }
  result = (int)ResizeAnimation((char const *)arg1,(char const *)arg2);
  jresult = (jint)result; 
  if (arg1) (*jenv)->ReleaseStringUTFChars(jenv, jarg1, (const char *)arg1);
  if (arg2) (*jenv)->ReleaseStringUTFChars(jenv, jarg2, (const char *)arg2);
  return jresult;
}

is okay and the arg1 and arg2 have proper values, but once ResizeAnimation is called, the pointers point to different memory address, and infile (arg1) is null, while outfile (arg2) is some random memory.

All the sources are built with standard android CMake for NDK.

1

1 Answers

0
votes

The problem was caused by running x86_64 code on x86 emulator. Silly :)