Coder Social home page Coder Social logo

Comments (4)

argv-minus-one avatar argv-minus-one commented on June 16, 2024

Which errors do you get, and at which line of code?

from jni-rs.

ShenFeng312 avatar ShenFeng312 commented on June 16, 2024

Which errors do you get, and at which line of code?

75  | (env: JNIEnv, _class: JClass) -> jintArray {
    |                                  --------- expected `*mut _jobject` because of return type
...
109 |     array
    |     ^^^^^ expected `*mut _jobject`, found `JPrimitiveArray<'_, i32>`

I dont know how to fix it @argv-minus-one

from jni-rs.

ShenFeng312 avatar ShenFeng312 commented on June 16, 2024

I tried using the following code. It compiles successfully, but when I call it in Java, I encounter the following error: free(): invalid pointer. It seems like the reference to the array has become invalid. However, when I tested it in Rust, everything worked fine except for the last JNI-related call. What can I do to test it further?@argv-minus-one

#[allow(non_snake_case)]
#[no_mangle]
 pub unsafe extern "C" fn method_name<'a>
 (mut env: JNIEnv<'a>, _class: JClass<'a>)->JIntArray<'a> {
  .......
  let rust_slice: &[i32] = &vec;
    // println!("{}", 1);
    env.set_int_array_region(&result, 0,rust_slice);
    result 
}

from jni-rs.

argv-minus-one avatar argv-minus-one commented on June 16, 2024

Sorry! I seem to have missed that you replied here. Didn't mean to ignore you like that.

I need to see more of your code. The code you've listed so far looks sound, so you must have omitted whatever is causing the problem.

I will say that your extern fn should not be unsafe. Something in the function is causing undefined behavior, and because the function is marked unsafe, you aren't getting any compile errors about it.

from jni-rs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.