Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Changes

- [UUM-131032] Added a reset of static variables when entering playmode to allow fast enter playmode compatibility.
- [UUM-138539] Removed the pb_ObjectArray file that was deprecated 8 years ago and is not used amymore.
- [UUM-138960] Removed a large utility dictionary to reduce binary size and runtime memory overhead.

Expand Down
8 changes: 8 additions & 0 deletions Debug/Scripts/ShowHoveredInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ public class ShowHoveredInfo : MonoBehaviour
static Material m_Material;
bool m_IsHovering;

#if UNITY_EDITOR
[RuntimeInitializeOnLoadMethod]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high
The default load type for RuntimeInitializeOnLoadMethod is AfterSceneLoad, which executes after the scene has loaded and Awake has been called. If an instance of ShowHoveredInfo exists in the scene, its Start method may run before this reset, causing it to initialize m_Material only for it to be immediately nulled here. This can lead to NullReferenceExceptions if the material is used later and also results in a resource leak.

Using BeforeSceneLoad ensures the static reference is cleared before any instance logic runs.

Suggested change
[RuntimeInitializeOnLoadMethod]
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]

🤖 Helpful? 👍/👎

static void ResetStaticsOnLoad()
{
m_Material = null;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium
When 'Enter Play Mode' is used with Domain Reload disabled, static material instances created via new Material() will leak if the reference is nulled without the material being destroyed. It is recommended to explicitly destroy the material before clearing the reference to prevent memory accumulation in the Editor.

Suggested change
m_Material = null;
if (m_Material != null) UnityEngine.Object.DestroyImmediate(m_Material);
m_Material = null;

🤖 Helpful? 👍/👎

}
#endif

void Start()
{
if (m_Material == null)
Expand Down
26 changes: 13 additions & 13 deletions Editor/EditorCore/CutTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
namespace UnityEditor.ProBuilder
{
[EditorTool("Cut Tool", typeof(ProBuilderMesh), typeof(PositionToolContext))]
[Icon("Packages/com.unity.probuilder/Editor Default Resources/Icons/Toolbar/CutTool.png")]
class CutTool : EditorTool
{
ProBuilderMesh m_Mesh;
Expand Down Expand Up @@ -85,12 +86,6 @@

Color m_CurrentHandleColor = k_HandleColor;

GUIContent m_IconContent;
public override GUIContent toolbarIcon
{
get { return m_IconContent; }
}

//Handles and point placement
int m_ControlId;
bool m_PlacingPoint;
Expand Down Expand Up @@ -169,13 +164,6 @@

void OnEnable()
{
m_IconContent = new GUIContent()
{
image = IconUtility.GetIcon("Toolbar/CutTool"),
text = "Cut Tool",
tooltip = "Cut Tool"
};

s_HandleColorUseExistingVertex = Handles.selectedColor;
s_HandleColorAddVertexOnEdge = Handles.selectedColor;

Expand All @@ -201,6 +189,7 @@
Undo.undoRedoPerformed += UndoRedoPerformed;
MeshSelection.objectSelectionChanged += UpdateTarget;
ProBuilderEditor.selectModeChanged += OnSelectModeChanged;
EditorApplication.playModeStateChanged += OnPlayModeStateChanged;
}

public override void OnWillBeDeactivated()
Expand All @@ -210,6 +199,7 @@
Undo.undoRedoPerformed -= UndoRedoPerformed;
MeshSelection.objectSelectionChanged -= UpdateTarget;
ProBuilderEditor.selectModeChanged -= OnSelectModeChanged;
EditorApplication.playModeStateChanged -= OnPlayModeStateChanged;

Check warning on line 202 in Editor/EditorCore/CutTool.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Editor/EditorCore/CutTool.cs#L202

Added line #L202 was not covered by tests
}

/// <summary>
Expand Down Expand Up @@ -242,6 +232,16 @@
ToolManager.RestorePreviousTool();
}

private void OnPlayModeStateChanged(PlayModeStateChange state)
{

Check warning on line 236 in Editor/EditorCore/CutTool.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Editor/EditorCore/CutTool.cs#L236

Added line #L236 was not covered by tests
if (state == PlayModeStateChange.ExitingEditMode || state == PlayModeStateChange.ExitingPlayMode)
{
// Reset tool state when entering/exiting playmode
if (ToolManager.IsActiveTool(this))
ExitTool();

Check warning on line 241 in Editor/EditorCore/CutTool.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Editor/EditorCore/CutTool.cs#L241

Added line #L241 was not covered by tests
}
}

/// <summary>
/// Undo/Redo callback: Reset and recompute lines, and update the targeted face if needed
/// </summary>
Expand Down
Loading