A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/bytedeco/javacpp/pull/747 below:

Pointer types don't work on the native side if allocated in java · Issue #747 · bytedeco/javacpp · GitHub

I have a problem where if I allocate something on the java side and pass it to a function on the native side it seems like natively all the properties of that object retain their default value. In other words int , double , long =0 even if they aren't and so on. This happened most recently when I tried to make an std::vectorstd::string and pass it to a c++ function. Here's a short example:

//test_header.hpp
#include <vector>
#include <string>
#include <iostream>
#ifdef EXPORTIMPORT
#define EXPIMP __declspec(dllexport)
#else
#define EXPIMP __declspec(dllimport)
#endif // EXPORTIMPORT
struct Foo {
	EXPIMP int test(std::vector<std::string>* vec);
};
//test_source.cpp
#include "test_header.hpp"
int Foo::test(std::vector<std::string>* vec) {
	std::cout << vec->size() << std::endl;
	return 0;
}
//Mapper
@Properties(
        value=@Platform(
        includepath = {"D:\\JavaProjects\\nativemvntest\\src\\main\\java\\org\\example\\nat"},
                linkpath = {"D:\\JavaProjects\\nativemvntest\\src\\main\\java\\org\\example\\nat"},

        include ={"test_header.hpp"},
                link={"Mvntest"}

),
target = "org.example.parsed.NativeLibrary",
global = "org.example.parsed.global.NativeLibrary")
public class Mapper implements InfoMapper {
    @Override
    public void map(InfoMap infoMap) {
        infoMap.put(new Info("std::vector<std::string>").pointerTypes("StringVector").define());
    }
}
//main
public class Main {
    public static void main(String[] args) {
        Foo foo = new Foo();
        StringVector vec = new StringVector(5);

        foo.test(vec);
    }

}

The cpp gets compiled into a dll, called Mvntest.dll and gets linked against in the mapper. I parse the files, compile them and run the example and it prints out 0. Also If I try to add any strings to this vector via push_back and print them out on the native side I get an ACCESS_VIOLATION


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4