Closed GoogleCodeExporter closed 9 years ago
I fixed one more thing with named FunctionPointer:
http://code.google.com/p/javacpp/source/detail?r=342553da4575bf89494cbf8de713a7b
8da76b46e
Does it still crash with that update? And does it crash on normal Java SE too?
Original comment by samuel.a...@gmail.com
on 12 Dec 2012 at 2:11
No it doesn't fix this. When I try to run it on Java SE I got:
libjniManager.so: undefined symbol: _ZN9Private7Manager10s_instanceE
Original comment by Dariusz.Luksza
on 13 Dec 2012 at 8:45
Hum, I haven't tested nested FunctionPointer classes, although I agree it
should work.
Original comment by samuel.a...@gmail.com
on 15 Dec 2012 at 1:23
Let's see, your sample code contains a lot errors. I fixed it to the following
namespace Private {
class Event {
public:
unsigned char GetEventId() { return 42; };
};
class Manager {
public:
typedef void (*pnfEvent_t)(Event const* event, void* pointer);
bool addEventListener(pnfEvent_t event, void* pointer) { return true; }
};
}
@Namespace("Private")
@Platform(include = "Foo.h")
public class Foo {
static { Loader.load(); }
public static class Event extends Pointer {
static { Loader.load(); }
public native @Cast("unsigned char") byte GetEventId();
}
public static class Manager extends Pointer {
public Manager() { allocate(); }
private native void allocate();
@Name("pnfEvent_t")
public static class OnEvent extends FunctionPointer {
static { Loader.load(); }
public OnEvent() { allocate(); }
public OnEvent(Pointer p) { super(p); }
private native void allocate();
public native void call(@Const Event event, Pointer pointer);
}
public native @Cast("bool") boolean addEventListener(OnEvent event, Pointer pointer);
}
public static void main(String[] args) {
Manager m = new Manager();
Manager.OnEvent e = new Manager.OnEvent();
m.addEventListener(e, null);
}
}
But nothing bad happens when I run
$ javac -cp javacpp.jar Foo.java
$ java -jar javacpp.jar Foo
$ java -cp javacpp.jar Foo
So, there is no problem on Java SE? Can you provide some code that crashes on
Android?
Original comment by samuel.a...@gmail.com
on 15 Dec 2012 at 1:42
Unfortunate my native Manager implementation uses "singleton pattern" and do
not define public constructors. This is third party API designed in a way that
you need to call Manger::Create() first an then you can obtain single instance
using Manager::Get().
Original comment by Dariusz.Luksza
on 16 Dec 2012 at 10:01
btw. if I don't create objects on java side using 'new' keyword should I also
define public constructors and allocate() methods for such objects?
In this example instance of event will come from native code therefore I didn't
declare constructors and allocate() method.
Original comment by Dariusz.Luksza
on 16 Dec 2012 at 10:04
No, we don't need to, and I don't think it's related to the issue at hand.
I am only looking for some sample code that actually crashes and that I can run
here. If you can produce some other examples that works with JavaCV 0.2, but
crashes with 0.3, that's fine too.
Original comment by samuel.a...@gmail.com
on 17 Dec 2012 at 3:18
I use JavaCPP on my small startup POC project and for now debugging this issue
seams to be much hassle for me, therefore will stay on 0.2. If my POC will work
out then for suser will try upgrade to current version of JavaCPP.
Original comment by Dariusz.Luksza
on 29 Dec 2012 at 1:54
I see, that's alright. BTW, @Name("pnfEvent_t") doesn't actually do anything
with JavaCV 0.2, so you should remove it. With JavaCV 0.3, maybe this is
causing some naming conflicts, so you should also try to remove it. Let me know
when you have some time to test that! Thanks
Original comment by samuel.a...@gmail.com
on 30 Dec 2012 at 6:27
I can confirm that removing @Name("pnfEvent_t") didn't brake anything in 0.2
but also didn't change anything in 0.3. So the problem still exists.
Original comment by Dariusz.Luksza
on 17 Feb 2013 at 5:16
yet another hint, it looks like 'env->FindClass' cannot find nested class.
During my investigations call env->FindClass("Manager$OnEvent")' in
JavaCPP_getClass always returns NULL.
Any hints?
Original comment by Dariusz.Luksza
on 17 Feb 2013 at 6:57
Another hint here is that Manager.OnEvent can be called from different thread
and this was working in 0.2
Original comment by Dariusz.Luksza
on 17 Feb 2013 at 8:50
Oh, yes, "Foo$Manager$OnEvent" would need to get preloaded to work on Android.
I didn't think of updating that part when making changes to the callback code.
That's why it worked with Java SE, but not Android. This update should fix this:
http://code.google.com/p/javacpp/source/browse/src/main/java/com/googlecode/java
cpp/Generator.java#1432
Let me know, and thanks for looking into this!
Original comment by samuel.a...@gmail.com
on 24 Feb 2013 at 2:42
I can confirm that 0.3-10-ga41cb1d works on Android. Thanks for fixing this!
btw. do you plan to do release in nearest future? maybe something like 0.3.1 or
0.4?
Original comment by Dariusz.Luksza
on 24 Feb 2013 at 2:53
Next weekend, if all goes well...
Original comment by samuel.a...@gmail.com
on 24 Feb 2013 at 2:54
Ok, it's released! Enjoy
Original comment by samuel.a...@gmail.com
on 3 Mar 2013 at 11:56
Original issue reported on code.google.com by
Dariusz.Luksza
on 11 Dec 2012 at 8:40