Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: a6ff5b0c6d65
Choose a base ref
...
head repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 3473dbc3727a
Choose a head ref
  • 2 commits
  • 1 file changed
  • 1 contributor

Commits on Nov 13, 2021

  1. Copy the full SHA
    c22ca72 View commit details
  2. Merge pull request #3201 from pleroy/3064

    Use static styles to prevent Unity leaks
    pleroy authored Nov 13, 2021
    Copy the full SHA
    3473dbc View commit details
Showing with 17 additions and 9 deletions.
  1. +17 −9 ksp_plugin_adapter/style.cs
26 changes: 17 additions & 9 deletions ksp_plugin_adapter/style.cs
Original file line number Diff line number Diff line change
@@ -2,6 +2,15 @@
namespace ksp_plugin_adapter {

internal static class Style {
static Style() {
horizontal_line_style_ =
new UnityEngine.GUIStyle(UnityEngine.GUI.skin.horizontalSlider);
horizontal_line_style_.fixedHeight /= 5;
horizontal_line_style_.normal.background = ultra_cool_grey_texture;
line_spacing_style_ = new UnityEngine.GUIStyle(UnityEngine.GUI.skin.label);
line_spacing_style_.fixedHeight /= 5;
}

public static UnityEngine.Color Tangent { get; } = XKCDColors.NeonYellow;
public static UnityEngine.Color Normal { get; } = XKCDColors.AquaBlue;
public static UnityEngine.Color Binormal { get; } = XKCDColors.PurplePink;
@@ -61,18 +70,11 @@ public static UnityEngine.GUIStyle Multiline(UnityEngine.GUIStyle style) {
}

public static void HorizontalLine() {
var horizontal_line_style =
new UnityEngine.GUIStyle(UnityEngine.GUI.skin.horizontalSlider);
horizontal_line_style.fixedHeight /= 5;
horizontal_line_style.normal.background = ultra_cool_grey_texture;
UnityEngine.GUILayout.Label("", horizontal_line_style);
UnityEngine.GUILayout.Label("", horizontal_line_style_);
}

public static void LineSpacing() {
var horizontal_line_style =
new UnityEngine.GUIStyle(UnityEngine.GUI.skin.label);
horizontal_line_style.fixedHeight /= 5;
UnityEngine.GUILayout.Label("", horizontal_line_style);
UnityEngine.GUILayout.Label("", line_spacing_style_);
}

private static UnityEngine.Texture2D ultra_cool_grey_texture {
@@ -90,6 +92,12 @@ private static UnityEngine.Texture2D ultra_cool_grey_texture {
// Close to XKCD "cool grey", but hue-neutral
private static readonly UnityEngine.Color ultra_cool_grey_ =
new UnityEngine.Color(0.64f, 0.64f, 0.64f);

// It is very important to use *static* styles for these elements. If we use
// local variables at the place of use, the stupid Unity ends up burning 9 kiB
// for each horizontal line we display. See #3064.
private static readonly UnityEngine.GUIStyle horizontal_line_style_;
private static readonly UnityEngine.GUIStyle line_spacing_style_;
}

} // namespace ksp_plugin_adapter