Skip to content

Commit d8f9145

Browse files
committed
jni: initialize x/y through the constructor instead of statically
1 parent 2c7538a commit d8f9145

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

src/modules/out_jnibuf.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ int init(void) {
7878
jc_jni_sled = JniEnv->GetObjectClass(pJniEnv, jo_jni_sled);
7979

8080
// determine sizes
81-
jf_matx = JniEnv->GetStaticFieldID(pJniEnv, jc_jni_sled, "MATRIX_X", "I");
82-
jf_maty = JniEnv->GetStaticFieldID(pJniEnv, jc_jni_sled, "MATRIX_Y", "I");
83-
matx = JniEnv->GetStaticIntField(pJniEnv, jc_jni_sled, jf_matx);
84-
maty = JniEnv->GetStaticIntField(pJniEnv, jc_jni_sled, jf_maty);
81+
jf_matx = JniEnv->GetFieldID(pJniEnv, jc_jni_sled, "matrixX", "I");
82+
jf_maty = JniEnv->GetFieldID(pJniEnv, jc_jni_sled, "matrixY", "I");
83+
matx = JniEnv->GetIntField(pJniEnv, jo_jni_sled, jf_matx);
84+
maty = JniEnv->GetIntField(pJniEnv, jo_jni_sled, jf_maty);
8585
JNI_BUFFER_SIZE = matx * maty * sizeof(jint);
8686

8787
// allocate output buffers

src/os/JniSled.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,31 @@ public class JniSled implements Runnable {
88
System.loadLibrary("sled");
99
}
1010

11-
// only set these before starting the thread!!!
12-
public static int MATRIX_X = 256;
13-
public static int MATRIX_Y = 256;
11+
private int matrixX = 256;
12+
private int matrixY = 256;
1413

1514
private int[] currentBuf;
1615

16+
public JniSled(int x, int y) {
17+
matrixX = x;
18+
matrixY = y;
19+
}
20+
1721
public native void main();
1822

1923
@Override
2024
public void run() {
2125
main();
2226
}
2327

28+
public int getMatrixX() {
29+
return matrixX;
30+
}
31+
32+
public int getMatrixY() {
33+
return matrixY;
34+
}
35+
2436
// TODO: maybe make this trigger a callback optionally?
2537
// could use that to let the user immediately render,
2638
// "pushing" instead of polling

0 commit comments

Comments
 (0)