With the TRTLCriticalSection fix, the game can now run for several minutes. Sometimes it still crashes, not as frequently as before, but the crashes remain random.
I’m not using Platform_NetOpen, but I assume reading an embedded 3DS file uses ReadAssetFile. Since we’ve already replaced all the other ...MethodV calls with ...MethodA, let’s do the same here.
Here's the new ReadAssetFile:
Code: Select all
procedure ReadAssetFile(Filename: PAnsiChar; var Memory: pointer; var Size: integer);
var
Env: PJNIEnv;
AppClass: JClass;
Mid: JMethodID;
jniParams: array[0..0] of JValue; // For the (String) parameter
JStr: jstring;
Buffer: jbyteArray;
PBuffer: pointer;
IsCopy: JBoolean;
BufferSize: JSize;
begin
// Get the JNI environment
CurVM^.GetEnv(CurVM, @Env, JNI_VERSION_1_6);
// Log filename
AndroidLog(PAnsiChar('Opening: ' + Filename));
// Get class and method ID
AppClass := Env^.GetObjectClass(Env, jobject(AndroidThis));
Mid := Env^.GetMethodID(Env, AppClass, 'openAssetFile', '(Ljava/lang/String;)[B');
// Create Java string and assign it to the parameter array
JStr := Env^.NewStringUTF(Env, Filename);
jniParams[0].l := JStr;
// Call Java method using CallObjectMethodA
Buffer := Env^.CallObjectMethodA(Env, jobject(AndroidThis), Mid, @jniParams[0]);
// Clean up local ref for the string
Env^.DeleteLocalRef(Env, JStr);
// If Buffer is valid, extract data
if Buffer <> nil then
begin
BufferSize := Env^.GetArrayLength(Env, Buffer);
PBuffer := Env^.GetByteArrayElements(Env, Buffer, IsCopy);
if PBuffer = nil then
AndroidLog('Could not get buffer')
else
begin
GetMem(Memory, BufferSize);
Move(PBuffer^, Memory^, BufferSize);
Size := BufferSize;
// Release Java array
Env^.ReleaseByteArrayElements(Env, Buffer, PBuffer, 0);
end;
end
else
AndroidLog('CallObjectMethodA returned null');
end;
And Platform_NetOpen:
Code: Select all
procedure Platform_NetOpen(Url: PAnsiChar; InBrowser: boolean; WebOpen: pointer);
var
Env: PJNIEnv;
AppClass: JClass;
Mid: JMethodID;
jniParams: array[0..0] of JValue;
JStr: jstring;
begin
if InBrowser then
begin
// Get JNI environment
CurVM^.GetEnv(CurVM, @Env, JNI_VERSION_1_6);
AndroidLog(PAnsiChar('Opening: ' + Url));
// Get class and method ID
AppClass := Env^.GetObjectClass(Env, jobject(AndroidThis));
Mid := Env^.GetMethodID(Env, AppClass, 'openURL', '(Ljava/lang/String;)V');
// Create Java string and set as argument
JStr := Env^.NewStringUTF(Env, Url);
jniParams[0].l := JStr;
// Call Java method using CallVoidMethodA
Env^.CallVoidMethodA(Env, jobject(AndroidThis), Mid, @jniParams[0]);
// Clean up local reference
Env^.DeleteLocalRef(Env, JStr);
end;
end;
However, it still crashes randomly without any clear hint in the logs. That’s why I was trying to change the NativeInt warnings to NativeUInt.
********** Crash dump: **********
Build fingerprint: 'google/cheetah/cheetah:15/BP1A.250305.019/13003188:user/release-keys'
#00 0x0000000000000010 <anonymous:7f1917b000>
Crash dump is completed