Skip to content

Commit

Permalink
Fix JNI ERROR
Browse files Browse the repository at this point in the history
  • Loading branch information
123edi10 authored Oct 28, 2024
1 parent a3b0de5 commit 00af796
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,29 +214,20 @@ class Runtime {
const { vm, api } = this;
const env = vm.getEnv();

const classHandles = [];
const addGlobalReference = api['art::JavaVMExt::AddGlobalRef'];
const { vm: vmHandle } = api;
withRunnableArtThread(vm, env, thread => {
const collectClassHandles = makeArtClassVisitor(klass => {
classHandles.push(addGlobalReference(vmHandle, thread, klass));
const handle = addGlobalReference(vmHandle, thread, klass);
const className = env.getClassName(handle);
callbacks.onMatch(className, handle);
env.deleteGlobalRef(handle);
return true;
});

api['art::ClassLinker::VisitClasses'](api.artClassLinker.address, collectClassHandles);
});

try {
classHandles.forEach(handle => {
const className = env.getClassName(handle);
callbacks.onMatch(className, handle);
});
} finally {
classHandles.forEach(handle => {
env.deleteGlobalRef(handle);
});
}

callbacks.onComplete();
}

Expand Down

0 comments on commit 00af796

Please sign in to comment.