java - 在 JNI.H 上调用 NewObject 时的 UknownFunction
问题描述
好的,所以我正在尝试将嵌入式 JDK 包含到 UnrealEngine 中以运行 JavaSE 代码。代码通过游戏中的文本 oanel 动态输入,然后编写和编译。当我尝试从此类构造新对象时,调用 JNI NewObjec 时失败。这是我在 c++ 中的实现:
FString javacCommand = (javacPath + filePath);
string stringCommand = string(TCHAR_TO_UTF8(*javacCommand));
UE_LOG(LogTemp, Warning, TEXT("File Created: %s"), *javacCommand);
cout << worked << "\n";
system(stringCommand.c_str());
UE_LOG(LogTemp, Warning, TEXT("Class compiled successfuly"));
try {
jclass clazz = env->FindClass("UserCode");
UE_LOG(LogTemp, Warning, TEXT("Class loaded successfuly"));
// Get the method that you want to call
jmethodID createMaterial = env->GetMethodID(clazz, "createJson", "()V");
UE_LOG(LogTemp, Warning, TEXT("CreateMaterial Method loaded Successfully"));
jmethodID constructor = env->GetMethodID(clazz, "<init>", "void(V)");
UE_LOG(LogTemp, Warning, TEXT("Constructor Method Loaded Successfuly"));
jobject object = env->NewObject(clazz, constructor);
UE_LOG(LogTemp, Warning, TEXT("Created New Object Sucessfully"));
// Call the method on the object
jobject result = env->CallObjectMethod(object, createMaterial);
jstring resultString = (jstring) result;
// Get a C-style string
const char *str = env->GetStringUTFChars(resultString, NULL);
env->ReleaseStringUTFChars(resultString, str);
UE_LOG(LogTemp, Warning, TEXT("Class method invoked successfuly with result: %s"), str);
std::cout << str;
}
的java代码:
import com.fasterxml.jackson.databind.ObjectMapper;
import com.gamifycode.*;
import com.gamifycode.craftableitem.*;
import com.gamifycode.enumeration.State;
import java.io.File;
import java.io.IOException;
public class UserCode
{
public UserCode()
{
}
public CraftableItem createCraftableItem() {
return null;
}
public void createJson() throws IOException {
CraftableItem createdItem = createCraftableItem();
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.writeValue(new File("JsonFile.json"), createdItem);
}
}
和堆栈跟踪:
Signal 11 caught.
Malloc Size=65538 LargeMemoryPoolOffset=65554
CommonUnixCrashHandler: Signal=11
Malloc Size=65535 LargeMemoryPoolOffset=131119
Malloc Size=728176 LargeMemoryPoolOffset=859312
[2020.02.01-02.29.54:237][976]LogCore: === Critical error: ===
Unhandled Exception: SIGSEGV: invalid attempt to read memory at address 0x0000000000000000
[2020.02.01-02.29.54:237][976]LogCore: Fatal error!
0x00007fc65569f9bc libjvm.so!JVM_handle_linux_signal(+0x11c)
0x00007fc6556928e8 libjvm.so!UnknownFunction(0x90b8e7)
0x00007fc6ad1f8890 libpthread.so.0!UnknownFunction(0x1288f)
0x00007fc655449067 libjvm.so!UnknownFunction(0x6c2066)
0x00007fc65545de5d libjvm.so!UnknownFunction(0x6d6e5c)
0x00007fc65ddf0742 libUE4Editor-CryptydGameJam-9268.so!JNIEnv_::NewObject(_jclass*, _jmethodID*, ...) [/home/levant/Documents/Repos/Unreal/SlimeCrimeLabs/CryptydGameJam/Source/ThirdParty/jdk1.8.0_211/include/../../jdk1.8.0_211/include/jni.h:872]
0x00007fc65ddefbcb libUE4Editor-CryptydGameJam-9268.so!UCodeInputWidget::compileCode(FText) [/home/levant/Documents/Repos/Unreal/SlimeCrimeLabs/CryptydGameJam/Source/CryptydGameJam/Private/CodeInputWidget.cpp:124]
知道为什么会发生这种情况吗?
解决方案
推荐阅读
- mysql - 自引用表时删除数据
- node.js - Mongoose - 两个有条件的查询的聚合
- c# - 使用多个参数(模型和 ViewDataDictionary)创建 RenderPartialViewToString
- java - 学习用 Java Servlet 连接到 db 编程
- java - JMH 捐赠
使用 perf 进行分析时的值 - javascript - 控制台中奇怪的 JS 行为
- firebase - 我可以发送 2 个主题的推送消息吗?流式细胞仪
- azure - Azure 数据工厂复制数据动态获取最后一个 blob
- actions-on-google - 谷歌智能家居限制从同步返回的设备数量
- struct - Julia:修改可变结构数组中的相同字段