Jump to content

Mod GUI hang-up


Recommended Posts

Houston, I have a problem:

I’ve updated a mod to KSP 1.3 (this one), and now, the moment before the GUI of the mod should appear the first time, KSP hangs up for an unpredictable time (0.2 to 10 seconds) for unknown reason.

The log shows nothing, but I can trace that the hang-up occurs somewhere in the middle of DrawWindow() method (called form GUI.Window() in my OnGUI() method) between arbitrary GUI element rendering method calls.

Apparently, this is not connected with localization since even the not localized KSP-1.2.2 version of the mod hangs up in KSP 1.3.

The same thing also happened when I tried to update my another mod to 1.3.

 

What causes those hang-ups, and how can I treat them?

Edited by Teilnehmer
Link to comment
Share on other sites

What causes them? Normal culprits are File IO (eg. logging) and/or heavy use of reflection, but anything can do it if you do it too much. In this case, throw debug statements at the function and check the timestamps in the log would be the simplest IMO

Treatment depends on the culprit. 90% of the time, you'll find that you're just doing something more often than is actually required. The other 10% you have to play smarter (coroutine to divide work across several frames, separate thread for the really heavy stuff, caching results, preloading, ...)

Edited by Crzyrndm
Link to comment
Share on other sites

Hm…

I do not actually do anything but drawing the GUI elements.

I’ve already tried to locate the critical place in the code using debug log messages. The log showed that the time delay was during the execution of

var activateGroupB = GUI.TextField(
	new Rect(5 + 3 * unit, 103, 3 * unit, 20),
	_activateGroupB.ToStringValue(nullValue: ""),
	4,
	TextFieldStyle).ParseNullableInt(minValue: 1);

It does not do anything complicated and is not even the first statement among the other similar ones.

Moreover, if I change the order of the statements, then some other statement falls on the delay.

It looks like something happening in a different thread causes the hang-up, not the code I am watching.

Btw, the hang-up occurs only once and does not repeat until restarting KSP.

Edited by Teilnehmer
Link to comment
Share on other sites

I've run into this also as my mods are still using the old GUI system and as far as I can tell the delay is caused by the fact that the old GUI system is no longer pre-loaded in KSP, rather it is loaded the first time an OnGUI call is made and so stalls for a few seconds while everything loads from disk into memory.

I am seeing the same behavior where it happens once per KSP run and behaves normally afterwards. Note that which mod displays first doesn't matter, the first use of OnGUI causes the stall and once the stall is out of the way, all mods are fine.

As I intend to update to the new GUI system at some point soon, I've just posted a warning in my release notes that it happens and left it at that.

D.

 

 

Edited by Diazo
Link to comment
Share on other sites

Thanks a lot, Diazo!

9 hours ago, Diazo said:

As I intend to update to the new GUI system at some point soon, I've just posted a warning in my release notes that it happens and left it at that.

OK, I’ll do the same.

Where can I read something about the new GUI system? (or, which KSP mods use it, so I can look at their source and learn?)

Edited by Teilnehmer
Link to comment
Share on other sites

To go all out and create your own GUI in the unity editor:

Use the more limited built-in system similar to the older OnGUI system:

I'm planning to make my own GUIs from scratch, the complexity of AGX requires it so I'm going to do it the same for all my mods.

D.

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...