Hello Guest

native c code is int casting a byte array

  • 6 Replies
  • 14495 Views
native c code is int casting a byte array
« on: May 20, 2007, 04:56:30 »
Code: [Select]
/*
 * Class:     org_lwjgl_openal_ALC11
 * Method:    nalcCaptureSamples
 * Signature: (JLjava/nio/ByteBuffer;I)V
 */
static void JNICALL Java_org_lwjgl_openal_ALC11_nalcCaptureSamples(JNIEnv *env, jclass clazz, jlong device, jobject buffer, jint position, jint samples) {
ALuint *buffer_address = ((ALuint *)(*env)->GetDirectBufferAddress(env, buffer)) + position;
alcCaptureSamples((ALCdevice*) ((intptr_t)device), buffer_address, samples);
}

it's suppose to be a byte array so I'm getting JVM crashes when my buffer reaches 25%.

I also noticed that all the AL11 things dont check for errors after calls like most of the al10 and alc10 methods do. Not sure if this was intentional or not. just wanted to mention it.

thanks,
karl

*

Offline Matzon

  • *****
  • 2242
Re: native c code is int casting a byte array
« Reply #1 on: May 20, 2007, 05:36:38 »
I'll investigate this asap

*

Offline Matzon

  • *****
  • 2242
Re: native c code is int casting a byte array
« Reply #2 on: May 20, 2007, 06:09:31 »
I am not sure there are any errors in the code actually - the native code deals with address locations and stuff like that.
From my point of view, you're passing a too high sample count and the alcCaptureSamples methods is probably overwriting your buffer argument.

For this to be safe, the device probably has to store the arguments passed to alcCaptureOpenDevice and ensure that the size of samples is correct.
Note that the ALCCaptureTest works flawlessly.

As for error checking, thats in ALC code and casued by the fact that its hand coded and the other stuff is generated. I will add some error checks.

Re: native c code is int casting a byte array
« Reply #3 on: May 20, 2007, 16:12:20 »
hmm ok thanks Matzon. Ill check out the example and play around some more.  I was just testing and no matter how big i made my bytebuffer when i set it's position to around 25% it's capacity i would get a JVM crash.

-karl

Re: native c code is int casting a byte array
« Reply #4 on: May 20, 2007, 16:20:36 »
actually now that i think about it that is the exact problem

Code: [Select]
((ALuint *)(*env)->GetDirectBufferAddress(env, buffer)) + position;
you int cast the pointer and then add the position. So now every position offset is multiplied by 4.  The reason your example works fine is you never set the position to something other than 0.

-karl

Re: native c code is int casting a byte array
« Reply #5 on: May 20, 2007, 17:18:34 »
capture samples should look like alBufferData:

Code: [Select]
static void JNICALL Java_org_lwjgl_openal_AL10_nalBufferData(JNIEnv *env, jclass clazz, jint buffer, jint format, jobject data, jint data_position, jint size, jint freq) {
ALvoid *data_address = ((ALvoid *)(((char *)(*env)->GetDirectBufferAddress(env, data)) + data_position));
alBufferData(buffer, format, data_address, size, freq);
}

*

Offline Matzon

  • *****
  • 2242
Re: native c code is int casting a byte array
« Reply #6 on: May 20, 2007, 17:49:04 »
sry - fixed in trunk