gpt4 book ai didi

java - 如何从 jna 引用指针检索 java 类

转载 作者:行者123 更新时间:2023-12-01 09:33:01 25 4
gpt4 key购买 nike

我正在移植 openvr samplejogl ,在我们创建 binding 之后与jna。

几乎在最后(在渲染 Controller 和跟踪基站之前),我在尝试从 C++ 中的引用指针检索 java 中的模型类时陷入困境。

C++ 代码 here :

while ( 1 )
{
error = vr::VRRenderModels()->LoadRenderModel_Async( pchRenderModelName, &pModel );
if ( error != vr::VRRenderModelError_Loading )
break;

ThreadSleep( 1 );
}

LoadRenderModel_Async here :

/** Loads and returns a render model for use in the application. pchRenderModelName should be a render model name
* from the Prop_RenderModelName_String property or an absolute path name to a render model on disk.
*
* The resulting render model is valid until VR_Shutdown() is called or until FreeRenderModel() is called. When the
* application is finished with the render model it should call FreeRenderModel() to free the memory associated
* with the model.
*
* The method returns VRRenderModelError_Loading while the render model is still being loaded.
* The method returns VRRenderModelError_None once loaded successfully, otherwise will return an error. */
virtual EVRRenderModelError LoadRenderModel_Async( const char *pchRenderModelName, RenderModel_t **ppRenderModel ) = 0;

jna 将其翻译为 ( here ):

public interface LoadRenderModel_Async_callback extends Callback {

int apply(Pointer pchRenderModelName, PointerByReference ppRenderModel);
};

在java上,我尝试以这种方式加载模型(here):

int error;
PointerByReference modelPtrRef = new PointerByReference();

while (true) {

Pointer stringPointer = new Memory(modelName.length());

error = renderModels.LoadRenderModel_Async.apply(stringPointer, modelPtrRef);

if (error != VR.EVRRenderModelError.VRRenderModelError_Loading) {
break;
}

try {
Thread.sleep(1);
} catch (InterruptedException ex) {
Logger.getLogger(ModelsRender.class.getName()).log(Level.SEVERE, null, ex);
}
}

RenderModel_t m = new RenderModel_t(modelPtrRef.getValue());
m.read();

但是m为空,即vertexData为空,vertexCount为0,在c++上我有有效值..

如何从 C++ 中的引用指针检索 java 类?

最佳答案

这里有一些更简单的内容:

if (errorBuffer.get(0) != VR.EVRRenderModelError.VRRenderModelError_None) {
return null;
}

int error;
PointerByReference pref = new PointerByReference();

while (true) {

error = renderModels.LoadRenderModel_Async.apply(modelName, pref);

if (error != VR.EVRRenderModelError.VRRenderModelError_Loading) {
break;
}

try {
Thread.sleep(1);
} catch (InterruptedException ex) {
Logger.getLogger(ModelsRender.class.getName()).log(Level.SEVERE, null, ex);
}
}
RenderModel_t model = new RenderModel_t(pref.getValue());


public class RenderModel_t {
public RenderModel_t(Pointer p) {
super(p);
read();
}
}

关于java - 如何从 jna 引用指针检索 java 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39244264/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com