Author Topic: Adding GUI controls to the PlayGui causes the game to crash on first spawn  (Read 1198 times)

This happens no matter how I do it. I create a new GuiSwatchCtrl, add it to the PlayGui and crash the next time the PlayGui wakes (on the first spawn).
This causes a guaranteed crash on every spawn:

new GuiSwatchCtrl(TestControl)
{
    ...
};

PlayGui.add(TestControl);




This causes a crash if it takes longer than 600ms to render the first frame. Increasing the schedule to something absurd like 3000s is not a reliable solution:

package TestPackage
{
   function PlayGui::onRender(%this)
   {
      Parent::onRender(%this);

      if (!PlayGui.isMember(TestControl))
         PlayGui.schedule(600, "add", TestControl);
   }
};

activatePackage("TestPackage");




These are the attributes used for the swatch control:

      profile = GuiDefaultProfile;
      horizSizing = "right";
      vertSizing = "bottom";
      position = "0 0";
      extent = "8 2";
      minExtent = "8 2";
      visible = 1;
      color = "0 0 0 0";

Why are you adding it to the playGui? What is the swatches purpose?

"...the next time the PlayGui wakes..."

...so why not try adding it there?

Code: [Select]
package bluh
{
    function PlayGUI::onWake(%this)
    {
        Parent::onWake(%this);
        PlayGUI.add(TestControl);
    }
};
activatePackage("bluh");

"...the next time the PlayGui wakes..."

...so why not try adding it there?

Code: [Select]
package bluh
{
    function PlayGUI::onWake(%this)
    {
        Parent::onWake(%this);
        PlayGUI.add(TestControl);
    }
};
activatePackage("bluh");

Surprisingly enough I think that fixed it. ::onRender is supposed to run when a GUI control wakes for the first time or whenever the resolution is changed while it's awake. Doesn't explain why it crashes though, especially not with this code:

new GuiSwatchCtrl(TestControl)
{
    ...
};

PlayGui.add(TestControl);


Practically every single HUD add-on does that.

Yes, they do, but their GUIs are set to not be visible until a keybind is pressed. Why that should make a game-crashing difference, I don't know, but that's why it works for them.

Not the Z view add-on, it's gui was made to be visible. However it did playGui.add($pref); instead of playGui.add(object); But it also uses a GameTSCtrl instead of a GuiSwatchCtrl.