LWJGL
May 18, 2013, 19:38:41 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: LWJGL 2.9.0 released!
 
   Home   Help Search Login Register  



Pages: [1]
  Print  
Author Topic: native c code is int casting a byte array  (Read 4626 times)
ksabo_lwjgl
Newbie
*
Posts: 13


« on: May 19, 2007, 21:56:30 »

Code:
/*
 * 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
Logged
Matzon
Administrator
Demigod
*****
Posts: 2237



« Reply #1 on: May 19, 2007, 22:36:38 »

I'll investigate this asap
Logged

Matzon
Administrator
Demigod
*****
Posts: 2237



« Reply #2 on: May 19, 2007, 23: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.
Logged

ksabo_lwjgl
Newbie
*
Posts: 13


« Reply #3 on: May 20, 2007, 09: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
Logged
ksabo_lwjgl
Newbie
*
Posts: 13


« Reply #4 on: May 20, 2007, 09:20:36 »

actually now that i think about it that is the exact problem

Code:
((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
Logged
ksabo_lwjgl
Newbie
*
Posts: 13


« Reply #5 on: May 20, 2007, 10:18:34 »

capture samples should look like alBufferData:

Code:
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);
}
Logged
Matzon
Administrator
Demigod
*****
Posts: 2237



« Reply #6 on: May 20, 2007, 10:49:04 »

sry - fixed in trunk
Logged

Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines
SMFAds for Free Forums
Valid XHTML 1.0! Valid CSS!