[FIXED] Retrieving something from an Array crash on Linux

Found a bug? Post information about it here so we can fix it!

Moderator: Moderators

User avatar
Ats
Posts: 703
Joined: Fri Sep 28, 2012 10:05 am
Contact:

[FIXED] Retrieving something from an Array crash on Linux

Post by Ats »

I made a very simple test.

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="ZGameEditor application" FileVersion="2">
  <OnLoaded>
    <ZExpression>
      <Expression>
<![CDATA[//
Names[0]="MOON";
Names[1]="PLANET";
trace(Names[0]);]]>
      </Expression>
    </ZExpression>
  </OnLoaded>
  <Content>
    <Array Name="Names" Type="2" SizeDim1="2"/>
  </Content>
</ZApplication>
On Windows, "trace(Names[0]);" returns MOON.

But on Linux, it crashes:
An unhandled exception occurred at $00000000004018E7:
EAccessViolation: Access violation
$00000000004018E7
Last edited by Ats on Fri Apr 30, 2021 9:11 am, edited 1 time in total.
User avatar
Ats
Posts: 703
Joined: Fri Sep 28, 2012 10:05 am
Contact:

Re: Retrieving something from an Array crash on Linux

Post by Ats »

It works with array full of int, but not with arrays full of strings:

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="ZGameEditor application" FileVersion="2">
  <OnLoaded>
    <ZExpression>
      <Expression>
<![CDATA[//
Numbers[0]= 0;
Numbers[1]= 1;

Names[0]="MOON";
Names[1]="PLANET";

trace(intToStr(Numbers[0]));
trace(Names[0]);]]>
      </Expression>
    </ZExpression>
  </OnLoaded>
  <Content>
    <Array Name="Numbers" Type="1" SizeDim1="2"/>
    <Array Name="Names" Type="2" SizeDim1="2"/>
  </Content>
</ZApplication>
Last edited by Ats on Wed Apr 28, 2021 1:57 pm, edited 1 time in total.
User avatar
VilleK
Site Admin
Posts: 2316
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: Retrieving something from an Array crash on Linux

Post by VilleK »

That is very strange. I don't have an explanation for this yet.

It could be something 64-bit specific but your example is working fine here on 64-bit windows.
User avatar
Ats
Posts: 703
Joined: Fri Sep 28, 2012 10:05 am
Contact:

Re: Retrieving something from an Array crash on Linux

Post by Ats »

Array of float, byte and vec works too.
But array of model crashes.

I didn't try xptr and mat4.
User avatar
VilleK
Site Admin
Posts: 2316
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: Retrieving something from an Array crash on Linux

Post by VilleK »

Ats wrote: Wed Apr 28, 2021 8:22 pm But array of model crashes.
How did you test this exactly?
User avatar
Ats
Posts: 703
Joined: Fri Sep 28, 2012 10:05 am
Contact:

Re: Retrieving something from an Array crash on Linux

Post by Ats »

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="ZGameEditor application" FileVersion="2">
  <OnLoaded>
    <ZExpression>
      <Expression>
<![CDATA[//
ArrayFloat[0]= 0.123;
ArrayFloat[1]= 0.456;

ArrayInt[0]= 0;
ArrayInt[1]= 1;

ArrayString[0]="MOON";
ArrayString[1]="PLANET";

for (int i=0; i<2; i++)
{
  model m = createModel(Model);
  m.ModelNumber = i;
  ArrayModel[i] = m;
}

ArrayByte[0]= 0;
ArrayByte[1]= 1;

ArrayVec[0]= vector2(1,2);
ArrayVec[1]= vector2(3,4);

//trace(intToStr(ArrayInt[0])); // ok
//trace(intToStr(ArrayFloat[0]*1000)); // ok
//trace(ArrayString[0]); // crash
//trace(intToStr(ArrayModel[0].ModelNumber)); // crash
model m = ArrayModel[0]; // ok
trace(intToStr(m.ModelNumber)); // crash
//trace(intToStr(ArrayByte[0])); // ok
//trace(intToStr(ArrayVec[0].X)); // ok]]>
      </Expression>
    </ZExpression>
  </OnLoaded>
  <Content>
    <Array Name="ArrayFloat" SizeDim1="2"/>
    <Array Name="ArrayInt" Type="1" SizeDim1="2"/>
    <Array Name="ArrayString" Type="2" SizeDim1="2"/>
    <Array Name="ArrayModel" Type="3" SizeDim1="2"/>
    <Array Name="ArrayByte" Type="4" SizeDim1="2"/>
    <Array Name="ArrayVec" Type="6" SizeDim1="2"/>
    <Model Name="Model">
      <Definitions>
        <Variable Name="ModelNumber" Type="1"/>
      </Definitions>
    </Model>
  </Content>
</ZApplication>
I started with directly tracing "ArrayModel[0].ModelNumber" yesterday, but in fact, "model m = ArrayModel[0]" is working. So it's not directly array of models that crashes.
User avatar
VilleK
Site Admin
Posts: 2316
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: Retrieving something from an Array crash on Linux

Post by VilleK »

I still can't figure it out. Do you have any way to try this on Linux 32-bit?
User avatar
Ats
Posts: 703
Joined: Fri Sep 28, 2012 10:05 am
Contact:

Re: Retrieving something from an Array crash on Linux

Post by Ats »

I have the old i386 ready. It's working on it.

I can also test it on raspberry by flashing a new 32bits OS on a card, but I'll do that after lunch, as I need to setup everything.

(And I'll test on the same rasp with the 64bits OS too)
User avatar
VilleK
Site Admin
Posts: 2316
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: Retrieving something from an Array crash on Linux

Post by VilleK »

Please try this code on the crashing system and tell me what it outputs:

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="ZGameEditor application" FileVersion="2">
  <OnLoaded>
    <ZExpression>
      <Expression>
<![CDATA[model[1] arr;

model m = createModel(Model);
arr[0]=m;
trace( intToStr(reinterpret_cast<int>(m)) );
m.ModelNumber = 1;

m = arr[0]; // ok
trace( intToStr(reinterpret_cast<int>(m)) );
trace(intToStr(m.ModelNumber)); // crash]]>
      </Expression>
    </ZExpression>
  </OnLoaded>
  <Content>
    <Model Name="Model">
      <Definitions>
        <Variable Name="ModelNumber" Type="1"/>
      </Definitions>
    </Model>
  </Content>
</ZApplication>
User avatar
Ats
Posts: 703
Joined: Fri Sep 28, 2012 10:05 am
Contact:

Re: Retrieving something from an Array crash on Linux

Post by Ats »

Here's the result on linux x86_64:

Code: Select all

1506279808
1506279808
An unhandled exception occurred at $000000000042691D:
EAccessViolation: Access violation
  $000000000042691D
Last edited by Ats on Thu Apr 29, 2021 3:48 pm, edited 1 time in total.
User avatar
VilleK
Site Admin
Posts: 2316
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: Retrieving something from an Array crash on Linux

Post by VilleK »

Please try passing "-gl" option to Freepascal when building binary. That should hopefully make it display line number and source file when it shows the EAccessViolation: Access violation error.
User avatar
Ats
Posts: 703
Joined: Fri Sep 28, 2012 10:05 am
Contact:

Re: Retrieving something from an Array crash on Linux

Post by Ats »

I didn't know I could build a debug version of Player_linux.bin :o
So the fault is coming from line 2849 of ZExpressions.pas
User avatar
VilleK
Site Admin
Posts: 2316
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: Retrieving something from an Array crash on Linux

Post by VilleK »

Ats wrote: Thu Apr 29, 2021 2:39 pm So the fault is coming from line 2849 of ZExpressions.pas
Interesting. And what if you run the string array example instead, where does it crash?
User avatar
Ats
Posts: 703
Joined: Fri Sep 28, 2012 10:05 am
Contact:

Re: Retrieving something from an Array crash on Linux

Post by Ats »

I verified several times that I had everything right:
- Clean download of recent ZGE code
- Built Player_linux.bin for x86_64 debug

Your previous test still gives the same result, but test with array full of strings doesn't return a line number. Just:

Code: Select all

An unhandled exception occurred at $0000000000402A27:
EAccessViolation: Access violation
  $0000000000402A27

...
But I got better information of the crash thanks to the Raspberry aarch64:

Your test:

Code: Select all

-1825435264
-1825435264
An unhandled exception occurred at $0000000000446210:
EAccessViolation: Access violation
  $0000000000446210  EXECUTE,  line 2849 of ZExpressions.pas
  $0000000000443850  EXECUTE,  line 764 of ZExpressions.pas
  $000000000042FE8C  EXECUTECOMMANDS,  line 3676 of ZClasses.pas
  $0000000000436094  RUN,  line 582 of ZApplication.pas
  $0000000000401640  main,  line 90 of ZzDC.dpr
  $0000007F9AB73218
  $00000000004015E8
My test with array of string:

Code: Select all

An unhandled exception occurred at $0000000000402FF4:
EAccessViolation: Access violation
  $0000000000402FF4
  $0000000000422034
  $0000000000444510  EXECUTE,  line 1164 of ZExpressions.pas
  $00000000004436BC  RUNCODE,  line 700 of ZExpressions.pas
  $0000000000443850  EXECUTE,  line 764 of ZExpressions.pas
  $000000000042FE8C  EXECUTECOMMANDS,  line 3676 of ZClasses.pas
  $0000000000436094  RUN,  line 582 of ZApplication.pas
  $0000000000401640  main,  line 90 of ZzDC.dpr
  $0000007F8CEF1218
  $00000000004015E8
User avatar
VilleK
Site Admin
Posts: 2316
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: Retrieving something from an Array crash on Linux

Post by VilleK »

What about a even simpler test:

Code: Select all

string s="moon";

trace(s);
Post Reply