Page 1 of 1

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

Posted: Fri Apr 23, 2021 2:29 pm
by Ats
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: )

Re: Simple test, different results on Windows and Linux

Posted: Fri Apr 23, 2021 4:45 pm
by Ats
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;

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

Posted: Fri Apr 23, 2021 9:01 pm
by Ats
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.

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

Posted: Sat Apr 24, 2021 1:57 pm
by VilleK
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.

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

Posted: Sat Apr 24, 2021 6:07 pm
by Ats
Thanks. This is working perfectly now :D