Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

return std::vector<float> as FloatBuffer error #786

Open
HeiUer opened this issue Nov 11, 2024 · 0 comments
Open

return std::vector<float> as FloatBuffer error #786

HeiUer opened this issue Nov 11, 2024 · 0 comments

Comments

@HeiUer
Copy link

HeiUer commented Nov 11, 2024

I have a c++ function like this:std::vector test();
when i use FloatBuffer to get the return of cpp function,it's get exception

here is the source code :
<NativeLibrary.h>

#include <vector>

std::vector<float> test(std::vector<short>& input){
    std::vector<float> result(input.size());
    for(int i = 0; i< input.size() ; ++i){
    result[i] = input[i];
    }

    return std::move(result);
}

NativeLibraryConfig.java

package org.example;

import org.bytedeco.javacpp.annotation.Platform;
import org.bytedeco.javacpp.annotation.Properties;
import org.bytedeco.javacpp.tools.InfoMap;
import org.bytedeco.javacpp.tools.InfoMapper;

@Properties(
        value = {
                @Platform(include={"NativeLibrary.h"}
        }
        ,target = "org.example.NativeLibrary"
)


public class NativeLibraryConfig implements InfoMapper{
    @Override
    public void map(InfoMap infoMap) {

    }
}

main.java

package org.example;
import java.nio.FloatBuffer;
import java.nio.ShortBuffer;

public class Main {
  public static void main(String[] args) throws InterruptedException {
    FloatBuffer output= NativeLibrary.test(ShortBuffer.allocate(256));
    System.out.printf("cap:%d\n", output.capacity()); // Expected capacity is 256, actual is 1024.
    output.array();
    System.out.println(output.getClass().getName());
  }
}

STDOUT:

cap:1024
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x0000000077940422, pid=21564, tid=0x00000000000028e4
#
# JRE version: OpenJDK Runtime Environment (8.0_432-b06) (build 1.8.0_432-b06)
# Java VM: OpenJDK 64-Bit Server VM (25.432-b06 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# V  [jvm.dll+0x1e0422]
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
# E:\test\javacpp_thread\hs_err_pid21564.log
#
# If you would like to submit a bug report, please visit:
#   https://github.com/adoptium/adoptium-support/issues
#

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants