29.03.2016, 11:01
So I was trying to implement array support for callPublic by myself. Everything works great with primitive arrays, but if I pass an object wrapper, for example Float it does not work. If I treat it as an jobjectArray it crashes and if I cast it to jfloatArray the values are all 0. Crashdump http://pastebin.com/ar1zXbDP
This code works for primitives, but prints 0s with Float object array:
Код:
jobjectArray ar = (jobjectArray)object; int len = env->GetArrayLength(ar); cell data[10]; for (int i = 0; i < len; i++) { auto o = env->GetObjectArrayElement(ar, i); auto oclass = env->GetObjectClass(o); // This line crashes auto bjf = env->GetMethodID(objectclass, "floatValue", "()F"); auto ffloat = env->CallFloatMethod(object, bjf); data[i] = amx_ftoc(ffloat); }
Код:
jfloatArray ar = (jfloatArray)object; int len = env->GetArrayLength(ar); float *fdata = env->GetFloatArrayElements(ar, 0); cell data[10]; for (int i = 0; i < len; i++) { printf("I:%d val:%f\n", i, fdata[i]); data[i] = amx_ftoc(fdata[i]); } env->ReleaseFloatArrayElements(ar, fdata, 0); cell arrCell; amx_PushArray(amx, &arrCell, NULL, data, len);