tags:

views:

49

answers:

1

Hello,

Having a peculiar problem. When I call the following JNI method.

jobjectArray array = env->NewObjectArray(list->size, jclass, 0);

Now, list->size is set to 54. But as soon as the code above is run the same pointer returns, 2405015736 whats going on? As affects the values held in the rest of the struct also. Setting a static value i.e.

jobjectArray array = env->NewObjectArray(54, jclass, 0)

Also has no effect. Any ideas? I'm stumped.

(jclass is a loaded class object jclass = env->FindClass("name"); )

Thanks

A: 

Your problem is that size may not be of 'jsize' type so conversion has to take place. Now, this would be all well and good, but JNI is an absolute pain with this stuff. I think what is happening is that your stack is getting corrupted from a number which is interpreted as being too big. Or something like that. Just do the size conversion like so:

jint msize = list->size;
jobjectArray array = env->NewObjectArray(msize, jclass, 0);

This should do the trick.

Chris Dennett
Thats interesting it worked, but why is interfering with everything in the list struct?
James Moore
Stack corruption :) The size variable problem was causing the allocation to eat up all available memory, I believe. If it worked, accept as answer please! :DAlso, if you return a number from a function, make sure you do something similar and use an intermediary holder first! JNI is such a pain :)
Chris Dennett
Actually, I'm not too sure why it works, maybe its not stack corruption. Perhaps other people can shed more light on the problem? Maybe it's heap corruption instead with a dodgy pointer.
Chris Dennett