Skip to content

Commit

Permalink
1.32.1 hotfix : fixed issue where the IMGUIOptimization patch was bre…
Browse files Browse the repository at this point in the history
…aking some mods UIs due to not resetting some internal state correctly
  • Loading branch information
gotmachine committed Dec 7, 2023
1 parent 1c2d0ef commit 934ff50
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 17 deletions.
2 changes: 1 addition & 1 deletion GameData/KSPCommunityFixes/KSPCommunityFixes.version
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"NAME": "KSPCommunityFixes",
"URL": "https://raw.githubusercontent.com/KSPModdingLibs/KSPCommunityFixes/master/GameData/KSPCommunityFixes/KSPCommunityFixes.version",
"DOWNLOAD": "https://github.com/KSPModdingLibs/KSPCommunityFixes/releases",
"VERSION": {"MAJOR": 1, "MINOR": 32, "PATCH": 0, "BUILD": 0},
"VERSION": {"MAJOR": 1, "MINOR": 32, "PATCH": 1, "BUILD": 0},
"KSP_VERSION": {"MAJOR": 1, "MINOR": 12, "PATCH": 5},
"KSP_VERSION_MIN": {"MAJOR": 1, "MINOR": 8, "PATCH": 0},
"KSP_VERSION_MAX": {"MAJOR": 1, "MINOR": 12, "PATCH": 5}
Expand Down
11 changes: 1 addition & 10 deletions KSPCommunityFixes/KSPCommunityFixes.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,7 @@
<DoNotPublicize Include="Assembly-CSharp:BaseField`1.OnValueModified" />
<DoNotPublicize Include="Assembly-CSharp:SaveUpgradePipeline.SaveUpgradePipeline.OnSetCfgNodeVersion" />
<Publicize Include="UnityEngine.CoreModule:UnityEngine.Object.m_CachedPtr" />
<Publicize Include="UnityEngine.IMGUIModule:UnityEngine.GUILayoutUtility" />
<Publicize Include="UnityEngine.IMGUIModule:UnityEngine.GUILayoutUtility.current" />
<Publicize Include="UnityEngine.IMGUIModule:UnityEngine.GUILayoutUtility.Begin" />
<Publicize Include="UnityEngine.IMGUIModule:UnityEngine.GUILayoutUtility.SelectIDList" />
<Publicize Include="UnityEngine.IMGUIModule:UnityEngine.GUILayoutUtility+LayoutCache" />
<Publicize Include="UnityEngine.IMGUIModule:UnityEngine.GUILayoutUtility+LayoutCache.topLevel" />
<Publicize Include="UnityEngine.IMGUIModule:UnityEngine.GUILayoutUtility+LayoutCache.layoutGroups" />
<Publicize Include="UnityEngine.IMGUIModule:UnityEngine.GUILayoutUtility+LayoutCache.windows" />
<Publicize Include="UnityEngine.IMGUIModule:UnityEngine.GUILayoutEntry" />
<Publicize Include="UnityEngine.IMGUIModule:UnityEngine.GUILayoutGroup" />
<Publicize Include="UnityEngine.IMGUIModule" />
<Publicize Include="mscorlib:System.IO.MonoIO" />
<Publicize Include="mscorlib:System.IO.MonoIOError" />
<Publicize Include="mscorlib:System.IO.MonoIOStat" />
Expand Down
44 changes: 40 additions & 4 deletions KSPCommunityFixes/Performance/IMGUIOptimization.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copypasted from https://forum.unity.com/threads/garbage-collector-spikes-because-of-gui.60217/page-2#post-6317280
// Based upon https://forum.unity.com/threads/garbage-collector-spikes-because-of-gui.60217/page-2#post-6317280
// Basically, every OnGUI() method implies a call to GUILayout.Repaint(), itself calling GUILayoutUtility.Begin(),
// which does a bunch of allocations (even if the OnGUI() method does nothing). This replacement method reuse the
// existing objects instead of instantiating new ones, which both reduce GC pressure (about 0.36 KB/frame per OnGUI()
Expand Down Expand Up @@ -33,21 +33,57 @@ static bool GUILayoutUtility_Begin_Prefix(int instanceID)
{
if (layoutCache.topLevel == null)
layoutCache.topLevel = new GUILayoutGroup();
else
ResetGUILayoutGroup(layoutCache.topLevel);

if (layoutCache.windows == null)
layoutCache.windows = new GUILayoutGroup();

layoutCache.topLevel.entries.Clear();
layoutCache.windows.entries.Clear();
else
ResetGUILayoutGroup(layoutCache.windows);

GUILayoutUtility.current.topLevel = layoutCache.topLevel;
GUILayoutUtility.current.layoutGroups.Clear();
GUILayoutUtility.current.layoutGroups.Push(GUILayoutUtility.current.topLevel);
GUILayoutUtility.current.windows = layoutCache.windows;
return false;
}
GUILayoutUtility.current.topLevel = layoutCache.topLevel;
GUILayoutUtility.current.layoutGroups = layoutCache.layoutGroups;
GUILayoutUtility.current.windows = layoutCache.windows;
return false;
}

static void ResetGUILayoutGroup(GUILayoutGroup layoutGroup)
{
layoutGroup.entries.Clear();
layoutGroup.isVertical = true;
layoutGroup.resetCoords = false;
layoutGroup.spacing = 0f;
layoutGroup.sameSize = true;
layoutGroup.isWindow = false;
layoutGroup.windowID = -1;
layoutGroup.m_Cursor = 0;
layoutGroup.m_StretchableCountX = 100;
layoutGroup.m_StretchableCountY = 100;
layoutGroup.m_UserSpecifiedWidth = false;
layoutGroup.m_UserSpecifiedHeight = false;
layoutGroup.m_ChildMinWidth = 100f;
layoutGroup.m_ChildMaxWidth = 100f;
layoutGroup.m_ChildMinHeight = 100f;
layoutGroup.m_ChildMaxHeight = 100f;
layoutGroup.m_MarginLeft = 0;
layoutGroup.m_MarginRight = 0;
layoutGroup.m_MarginTop = 0;
layoutGroup.m_MarginBottom = 0;
layoutGroup.rect = new Rect(0f, 0f, 0f, 0f);
layoutGroup.consideredForMargin = true;
layoutGroup.m_Style = GUIStyle.none;
layoutGroup.stretchWidth = 1;
layoutGroup.stretchHeight = 0;
layoutGroup.minWidth = 0f;
layoutGroup.maxWidth = 0f;
layoutGroup.minHeight = 0f;
layoutGroup.maxHeight = 0f;
}
}
}
4 changes: 2 additions & 2 deletions KSPCommunityFixes/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
// Revision
//
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.32.0.0")]
[assembly: AssemblyFileVersion("1.32.1.0")]

[assembly: KSPAssembly("KSPCommunityFixes", 1, 32, 0)]
[assembly: KSPAssembly("KSPCommunityFixes", 1, 32, 1)]
[assembly: KSPAssemblyDependency("MultipleModulePartAPI", 1, 0, 0)]
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ If doing so in the `Debug` configuration and if your KSP install is modified to

### Changelog

##### 1.32.1
- **IMGUIOptimization** : fixed issue where the patch was breaking some mods UIs due to not resetting some internal state correctly.

##### 1.32.0
- New KSP bugfix : [**TimeWarpOrbitShift**](https://github.com/KSPModdingLibs/KSPCommunityFixes/issues/170) [KSP 1.8.0 - 1.12.5], fix active vessel orbit moving randomly when engaging timewarp while under heavy CPU load.
- New KSP bugfix : [**ModuleAnimateGenericCrewModSpawnIVA**](https://github.com/KSPModdingLibs/KSPCommunityFixes/issues/169) [KSP 1.8.0 - 1.12.5], fix IVA & crew portrait not spawning/despawning when ModuleAnimateGeneric is used to change the part crew capacity. Notably affect the stock inflatable airlock.
Expand Down

2 comments on commit 934ff50

@x13x54
Copy link

@x13x54 x13x54 commented on 934ff50 Dec 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After updating to this through CKAN i was barely able to click anything properly in editor, i got these stacktraces spamming my screen and logs at the same time:
image
I do not have any idea what PAW is about, and if that's a mod i don't have it

@x13x54
Copy link

@x13x54 x13x54 commented on 934ff50 Dec 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took me a minute but i realized PAW means Part Action Window.
Rolling back to 1.32.0 fixed my issue so you may have to fix something here though @gotmachine let me know if you need my modlist
EDIT: issue re-surfaced after some time of issue-free aircraft design

Please sign in to comment.