Page 19 of 19

Re: Google Play New problem : 64bits

Posted: Tue Apr 22, 2025 7:33 am
by VilleK
Ats wrote: Mon Apr 21, 2025 7:51 pm So I've been trying to fix the warnings: "Converting pointers to signed integers may result in wrong comparison results and range errors, use an unsigned type instead."
You could try if changing to NativeUInt helps with the crashes. But otherwise I would not bother. The Delphi compiler does not warn about these lines.

If you load files using the File component during the game then the comment that Gemini had about ReadAssetFile would be good to take a look at.

The TRTLCriticalSection change is most likely the main bug here. It makes sense too since you already figured out it was somehow related to threaded code. How frequent are crashes after you fixed this bug?

Re: Google Play New problem : 64bits

Posted: Tue Apr 22, 2025 9:22 am
by Kjell
Hi guys,

I'm no Pascal / Delphi expert .. but why not use (regular) pointer arithmetic instead of converting back & forth between a integer and pointer?

And the "does not seem to be initialized" warnings are the compiler being dumb ( afaik ):

- In case of "ScaledGravity" it's only being initialized when UseGravity is TRUE, but it's only being used when UseGravity is TRUE anyway.
- In case of "TextBuf" it's because when Self.Text isn't NULL, it uses ZStrCopy for "initialization" .. which the compiler doesn't know/understand.

In both cases the warning can be easily suppressed by setting the variable to a default value at the beginning of the procedure.

K

Re: Google Play New problem : 64bits

Posted: Tue Apr 22, 2025 9:29 am
by Ats
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

Re: Google Play New problem : 64bits

Posted: Tue Apr 22, 2025 9:53 am
by Kjell
Hi Ats,
Ats wrote: Tue Apr 22, 2025 9:29 amI assume reading an embedded 3DS file uses ReadAssetFile.
The MeshImport component uses TZInputStream and its CreateFromMemory constructor specifically, so no Platform_ReadFile ( nor ReadAssetFile ) is involved.

K