Openfl.utils.JNI is there any documentation and examples?

Hey guys,

I’m on my way to create some extensions for my app, and I noticed that in most of the tutorials ( actually there are few tutorials about this ), we need to make calls to static java functions.

It seems that a memory issue was introduced in hxcpp 3.2.102, then fixed in version 3.2.186. Issue thread

I have version 3.2.192 and the issue is still happening to me. It happens just after calling one of theese static java methods, passing a HaxeObject as a parameter( My idea is to call haxe functions when my backend work is done ).

My Haxe callback is being called fine but then the app crashes with the same error in the link above. So there’s some memory’s black magic in there which is breaking everything. If I comment the JNI call to the static method, this doesn’t crash anymore. It seems that java doesn’t like my HaxeObject( It’s a “State” class which inherits from openfl.display.Sprite ).

So I was wondering what should happen if I call a member method to java instead of an static one, but I didn’t find too much information about calling member functions.

Is there any documentation about this JNI calls? I’ll appreciate it. Building Android takes some time and I want to avoid “trial an error” because it’s frustating :stuck_out_tongue:

How do you guys often test your openfl extensions? Is there any good practice about that?

Thanks in advance,

Frano

Be aware that Java and your C++ in Haxe run in different threads – this is the most common problem (and one of the headaches/realities) of Android development. If Java calls back into Haxe, you need to use a special callback in order to run on the correct (render) thread

Oh I didn’t know that. What do you mean with “Special Callback”? What I’m doing it’s to invoke methods from the HaxeObject passing to Java.

I’ts working but it’s still crashing just after my method is called so, I’ll check version 3.188 of HXCPP to see if it’s still happening.

Thanks!

You’re right!! I forgot to add the runOnUIThread call to put my callback in there. This is how my java method now looks like:

public void callHaxeFunctionMember( final HaxeObject obj )
{
	mActivity.runOnUiThread(new Runnable() {
		public void run() {
			obj.call0("onCalledFromJava");
		}
	});
}

Now I understand that “special callback” you mentioned haha

Thanks Josh!

1 Like