[FIXED] Simple var test, different results on Windows and Linux

All topics about ZGameEditor goes here.

Moderator: Moderators

Post Reply
User avatar
Ats
Posts: 445
Joined: Fri Sep 28, 2012 10:05 am
Contact:

[FIXED] Simple var test, different results on Windows and Linux

Post by Ats » Fri Apr 23, 2021 2:29 pm

While trying to make Rado1's ZgeBullet examples to work, I've stumbled on a weird bug. So I stripped out the thing to make a simple test:

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="ZGameEditor application" FileVersion="2">
  <OnLoaded>
    <ZLibrary>
      <Source>
<![CDATA[//
int IsClicked;
int WasClicked;]]>
      </Source>
    </ZLibrary>
    <ZExpression>
      <Expression>
<![CDATA[//
WasClicked = 0;]]>
      </Expression>
    </ZExpression>
  </OnLoaded>
  <OnUpdate>
    <ZExpression>
      <Expression>
<![CDATA[//
IsClicked = 0;]]>
      </Expression>
    </ZExpression>
    <KeyPress Comment="space bar" CharCode="32">
      <OnPressed>
        <ZExpression>
          <Expression>
<![CDATA[//
IsClicked = 1;]]>
          </Expression>
        </ZExpression>
      </OnPressed>
    </KeyPress>
    <ZExpression>
      <Expression>
<![CDATA[//
if (IsClicked)
{
  App.ClearColor.R=1;
  App.ClearColor.G=0;
}
else
{
  if (WasClicked)
  {
    App.ClearColor.R=0;
    App.ClearColor.G=1;
  }
  else
  {
    App.ClearColor.R=0;
    App.ClearColor.G=0;
  }
}

WasClicked = IsClicked;
//trace(intToStr(IsClicked));
//trace(intToStr(WasClicked));]]>
      </Expression>
    </ZExpression>
  </OnUpdate>
</ZApplication>
Pressing the space bar will change the screen color.

Here's what's happening on Windows:
no key press = black
key pressed = red
key released = green during one frame

And on Linux:
no key press = black
key pressed = screen
key released = stay green and no more black

Both trace are correct on linux:
1 = pressed
0 = not pressed

(by the way, thanks for the trace working on linux :wink: )
Last edited by Ats on Sun Apr 25, 2021 4:30 am, edited 3 times in total.

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

Re: Simple test, different results on Windows and Linux

Post by Ats » Fri Apr 23, 2021 4:45 pm

I found where the problem is coming from:
It's working on Linux if variables IsClicked and WasCliked are set as Variable components instead of being declared in the ZLibrary.
Weird... :|

Edit:
I tried initiating both var in ZLibrary, but it's not working:
int IsClicked = 0;
int WasClicked = 0;

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

Re: Simple var test, different results on Windows and Linux

Post by Ats » Fri Apr 23, 2021 9:01 pm

Even simpler test:

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="ZGameEditor application" FileVersion="2">
  <OnLoaded>
    <ZLibrary HasInitializer="1">
      <Source>
<![CDATA[//
int a = 0;
int b = 1;]]>
      </Source>
    </ZLibrary>
  </OnLoaded>
  <OnUpdate>
    <ZExpression>
      <Expression>
<![CDATA[//
a=b;
trace(intToStr(a));]]>
      </Expression>
    </ZExpression>
  </OnUpdate>
</ZApplication>
Traces 1 on Windows, and 0 on Linux.
If I move the ZExpression to OnLoad or OnClose, it works, but not on OnUpdate, OnBeginRenderPass or OnRender.

One last thing, if I set b as a constant, it works on linux:
int a = 0;
const int b = 1;

It's possible that all weird Linux player problem comes from that sole bug.

User avatar
VilleK
Site Admin
Posts: 2174
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: Simple var test, different results on Windows and Linux

Post by VilleK » Sat Apr 24, 2021 1:57 pm

Indeed, nice find and analysis. It was a bug related to a recent optimization I did for library-declared variables. It should work now if you rebuild ZDesigner.

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

Re: Simple var test, different results on Windows and Linux

Post by Ats » Sat Apr 24, 2021 6:07 pm

Thanks. This is working perfectly now :D

Post Reply