Skip to content

Clear static data on destory, fixes error during scene change #324

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
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
2 changes: 2 additions & 0 deletions com.unity.robotics.ros-tcp-connector/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a

## Unreleased

Clear static data on destroy

### Upgrade Notes

### Known Issues
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public class HudPanel : MonoBehaviour
static SortedList<int, IHudTab> s_HUDTabs = new SortedList<int, IHudTab>();
static SortedList<int, Action> s_HeaderContents = new SortedList<int, Action>();
static List<HudWindow> s_ActiveWindows = new List<HudWindow>();
static int s_NextWindowID = 101;
const int INITIAL_NEXT_WINDOW_ID = 101;
static int s_NextWindowID = INITIAL_NEXT_WINDOW_ID;

// ROS Message variables
internal bool isEnabled;
Expand Down Expand Up @@ -123,6 +124,13 @@ public static void RegisterHeader(Action headerContent, int index = 0)

s_HeaderContents.Add(index, headerContent);
}
public static void ClearStaticContent()
{
s_HUDTabs.Clear();
s_HeaderContents.Clear();
s_ActiveWindows.Clear();
s_NextWindowID = INITIAL_NEXT_WINDOW_ID;
}

public static void AddWindow(HudWindow window)
{
Expand Down Expand Up @@ -204,24 +212,5 @@ public bool IsFreeWindowRect(Rect rect, out float maxX, out float maxY)

return result;
}

#if UNITY_EDITOR
// automatically clear all static content on pressing play
[UnityEditor.InitializeOnLoadMethod]
static void InitializeOnLoad()
{
UnityEditor.EditorApplication.playModeStateChanged += OnPlayMode;
}

static void OnPlayMode(UnityEditor.PlayModeStateChange change)
{
if (change == UnityEditor.PlayModeStateChange.ExitingEditMode)
{
s_HUDTabs.Clear();
s_HeaderContents.Clear();
s_ActiveWindows.Clear();
}
}
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,11 @@ void Start()
if (ConnectOnStart)
Connect();
}
void OnDestroy()
{
HudPanel.ClearStaticContent();
Disconnect();
}

public void Connect(string ipAddress, int port)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@ public static TFSystem GetOrCreateInstance()
return instance;
}

public static void ClearStaticData()
{
if (instance != null)
{
instance.m_TFTopics.Clear();
instance = null;
}
}
public IEnumerable<string> GetTransformNames(string tfTopic = "/tf")
{
return GetOrCreateTFTopic(tfTopic).GetTransformNames();
Expand Down
2 changes: 2 additions & 0 deletions com.unity.robotics.visualizations/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a

## Unreleased

Clear static data on destroy

### Upgrade Notes

### Known Issues
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ public void Start()
if (color.a == 0)
color.a = 1;
}
void OnDestroy()
{
TFSystem.ClearStaticData();
}

void EnsureSettings(TFStream stream)
{
Expand Down