LogicalError / realtime-CSG-for-unity

Realtime-CSG, CSG level editor for Unity
https://realtimecsg.com
MIT License
735 stars 77 forks source link

Leaving playmode with RCSG turned ON glitches RCSG #307

Closed hickVieira closed 3 years ago

hickVieira commented 4 years ago

Whenever I leave playmode, I get a missing CSGBrush reference error along with the entire geometry of my level disappearing. The only way I know to un-glitch RCSG is to restart Unity or cause a code refresh.

Linked to https://github.com/LogicalError/realtime-CSG-for-unity/issues/299#issue-486431058

Error message: NullReferenceException: Object reference not set to an instance of an object RealtimeCSG.InternalCSGModelManager.SetBrushMesh (RealtimeCSG.Components.CSGBrush brush) (at Assets/Tools/RealtimeCSG/Editor/Scripts/Control/Managers/InternalCSGModelManager.Registration.cs:691) RealtimeCSG.InternalCSGModelManager.SetBrushMeshSurfaces (RealtimeCSG.Components.CSGBrush brush) (at Assets/Tools/RealtimeCSG/Editor/Scripts/Control/Managers/InternalCSGModelManager.Registration.cs:717) RealtimeCSG.InternalCSGModelManager.CheckSurfaceModifications (RealtimeCSG.Components.CSGBrush brush, System.Boolean surfacesModified) (at Assets/Tools/RealtimeCSG/Editor/Scripts/Control/Managers/InternalCSGModelManager.Registration.cs:1044) RealtimeCSG.InternalCSGModelManager.CheckSurfaceModifications (RealtimeCSG.Components.CSGBrush[] brushes, System.Boolean surfacesModified) (at Assets/Tools/RealtimeCSG/Editor/Scripts/Control/Managers/InternalCSGModelManager.Registration.cs:954) RealtimeCSG.EditModePlace.MoveBoundsCenter (UnityEngine.Camera camera, System.Int32 boundsCenterIndex, UnityEngine.Vector3 offset, UnityEngine.Vector3& snappedOffset, RealtimeCSG.SnapMode snapMode) (at Assets/Tools/RealtimeCSG/Editor/Scripts/View/GUI/EditModeGUI/EditModes/EditMode.Place.cs:1000) RealtimeCSG.EditModePlace.HandleEvents (UnityEditor.SceneView sceneView, UnityEngine.Rect sceneRect) (at Assets/Tools/RealtimeCSG/Editor/Scripts/View/GUI/EditModeGUI/EditModes/EditMode.Place.cs:2185) RealtimeCSG.EditModeManager.OnSceneGUI (UnityEditor.SceneView sceneView) (at Assets/Tools/RealtimeCSG/Editor/Scripts/View/GUI/EditModeGUI/EditModeManager.cs:525) RealtimeCSG.SceneViewEventHandler.OnScene (UnityEditor.SceneView sceneView) (at Assets/Tools/RealtimeCSG/Editor/Scripts/Control/Managers/SceneViewEventHandler.cs:66) UnityEditor.SceneView.CallOnSceneGUI () (at <78f1ad0f25c84e3ca853e639f50d95f5>:0) UnityEditor.SceneView.HandleSelectionAndOnSceneGUI () (at <78f1ad0f25c84e3ca853e639f50d95f5>:0) UnityEditor.SceneView.OnGUI () (at <78f1ad0f25c84e3ca853e639f50d95f5>:0) System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <437ba245d8404784b9fbab9b439ac908>:0) Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation. System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <437ba245d8404784b9fbab9b439ac908>:0) System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at <437ba245d8404784b9fbab9b439ac908>:0) UnityEditor.HostView.Invoke (System.String methodName, System.Object obj) (at <78f1ad0f25c84e3ca853e639f50d95f5>:0) UnityEditor.HostView.Invoke (System.String methodName) (at <78f1ad0f25c84e3ca853e639f50d95f5>:0) UnityEditor.HostView.InvokeOnGUI (UnityEngine.Rect onGUIPosition, UnityEngine.Rect viewRect) (at <78f1ad0f25c84e3ca853e639f50d95f5>:0) UnityEditor.DockArea.DrawView (UnityEngine.Rect viewRect, UnityEngine.Rect dockAreaRect) (at <78f1ad0f25c84e3ca853e639f50d95f5>:0) UnityEditor.DockArea.OldOnGUI () (at <78f1ad0f25c84e3ca853e639f50d95f5>:0) UnityEngine.UIElements.IMGUIContainer.DoOnGUI (UnityEngine.Event evt, UnityEngine.Matrix4x4 parentTransform, UnityEngine.Rect clippingRect, System.Boolean isComputingLayout, UnityEngine.Rect layoutSize, System.Action onGUIHandler, System.Boolean canAffectFocus) (at <3736d7cfd1f845a5922f99478cb469e7>:0) UnityEngine.UIElements.IMGUIContainer.HandleIMGUIEvent (UnityEngine.Event e, UnityEngine.Matrix4x4 worldTransform, UnityEngine.Rect clippingRect, System.Action onGUIHandler, System.Boolean canAffectFocus) (at <3736d7cfd1f845a5922f99478cb469e7>:0) UnityEngine.UIElements.IMGUIContainer.HandleIMGUIEvent (UnityEngine.Event e, System.Action onGUIHandler, System.Boolean canAffectFocus) (at <3736d7cfd1f845a5922f99478cb469e7>:0) UnityEngine.UIElements.IMGUIContainer.HandleIMGUIEvent (UnityEngine.Event e, System.Boolean canAffectFocus) (at <3736d7cfd1f845a5922f99478cb469e7>:0) UnityEngine.UIElements.IMGUIContainer.SendEventToIMGUI (UnityEngine.UIElements.EventBase evt, System.Boolean canAffectFocus) (at <3736d7cfd1f845a5922f99478cb469e7>:0) UnityEngine.UIElements.IMGUIContainer.HandleEvent (UnityEngine.UIElements.EventBase evt) (at <3736d7cfd1f845a5922f99478cb469e7>:0) UnityEngine.UIElements.CallbackEventHandler.HandleEventAtTargetPhase (UnityEngine.UIElements.EventBase evt) (at <3736d7cfd1f845a5922f99478cb469e7>:0) UnityEngine.UIElements.MouseCaptureDispatchingStrategy.DispatchEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel) (at <3736d7cfd1f845a5922f99478cb469e7>:0) UnityEngine.UIElements.EventDispatcher.ApplyDispatchingStrategies (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel, System.Boolean imguiEventIsInitiallyUsed) (at <3736d7cfd1f845a5922f99478cb469e7>:0) UnityEngine.UIElements.EventDispatcher.ProcessEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel) (at <3736d7cfd1f845a5922f99478cb469e7>:0) UnityEngine.UIElements.EventDispatcher.ProcessEventQueue () (at <3736d7cfd1f845a5922f99478cb469e7>:0) UnityEngine.UIElements.EventDispatcher.OpenGate () (at <3736d7cfd1f845a5922f99478cb469e7>:0) UnityEngine.UIElements.EventDispatcherGate.Dispose () (at <3736d7cfd1f845a5922f99478cb469e7>:0) UnityEngine.UIElements.EventDispatcher.ProcessEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel) (at <3736d7cfd1f845a5922f99478cb469e7>:0) UnityEngine.UIElements.EventDispatcher.Dispatch (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel, UnityEngine.UIElements.DispatchMode dispatchMode) (at <3736d7cfd1f845a5922f99478cb469e7>:0) UnityEngine.UIElements.BaseVisualElementPanel.SendEvent (UnityEngine.UIElements.EventBase e, UnityEngine.UIElements.DispatchMode dispatchMode) (at <3736d7cfd1f845a5922f99478cb469e7>:0) UnityEngine.UIElements.UIElementsUtility.DoDispatch (UnityEngine.UIElements.BaseVisualElementPanel panel) (at <3736d7cfd1f845a5922f99478cb469e7>:0) UnityEngine.UIElements.UIElementsUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr) (at <3736d7cfd1f845a5922f99478cb469e7>:0) UnityEngine.GUIUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr) (at <817eebdd70f8402280b9cb11fff8b976>:0)

hickVieira commented 4 years ago

I did a quick debug in the code and apparently the Brush.ChildData.Model loses the reference to the Model after leaving playmode.

Adding a check to see if its null and return removes the error message, but it also keeps RCSG from generating any geometry.

LogicalError commented 3 years ago

Hi, what unity version is this in?

hickVieira commented 3 years ago

It was 2019.x something, I dont remember. I just updated to unity 2020.1 and I am currently unable to recreate it. Also, it could be my fault, I have a script that modifies Brush.ControlMesh.Vertices, maybe that is causing issues.

Anyway, gonna close issue perform more tests.

vncastanheira commented 3 years ago

I'm having this problem as well, using 2020.3. Still can't figure it out what the issue is but the step to make it break are:

MissingReferenceException: The object of type 'CSGBrush' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
RealtimeCSG.BoundsUtilities.GetLocalBounds (RealtimeCSG.Components.CSGBrush[] brushes, UnityEngine.Matrix4x4 worldToLocal) (at Assets/Plugins/RealtimeCSG/Editor/Scripts/Data/SceneQuery/BoundsUtilities.cs:328)
RealtimeCSG.EditModePlace.UpdateTargetBounds () (at Assets/Plugins/RealtimeCSG/Editor/Scripts/View/GUI/EditModeGUI/EditModes/EditMode.Place.cs:304)
RealtimeCSG.EditModePlace.HandleEvents (UnityEditor.SceneView sceneView, UnityEngine.Rect sceneRect) (at Assets/Plugins/RealtimeCSG/Editor/Scripts/View/GUI/EditModeGUI/EditModes/EditMode.Place.cs:1426)
RealtimeCSG.EditModeManager.OnSceneGUI (UnityEditor.SceneView sceneView) (at Assets/Plugins/RealtimeCSG/Editor/Scripts/View/GUI/EditModeGUI/EditModeManager.cs:525)
RealtimeCSG.SceneViewEventHandler.OnScene (UnityEditor.SceneView sceneView) (at Assets/Plugins/RealtimeCSG/Editor/Scripts/Control/Managers/SceneViewEventHandler.cs:66)
UnityEditor.SceneView.CallOnSceneGUI () (at <015079d9a4ea4f97b4381e694d2310c1>:0)
UnityEditor.SceneView.HandleSelectionAndOnSceneGUI () (at <015079d9a4ea4f97b4381e694d2310c1>:0)
UnityEditor.SceneView.OnGUI () (at <015079d9a4ea4f97b4381e694d2310c1>:0)
UnityEditor.HostView.InvokeOnGUI (UnityEngine.Rect onGUIPosition, UnityEngine.Rect viewRect) (at <015079d9a4ea4f97b4381e694d2310c1>:0)
UnityEditor.DockArea.DrawView (UnityEngine.Rect viewRect, UnityEngine.Rect dockAreaRect) (at <015079d9a4ea4f97b4381e694d2310c1>:0)
UnityEditor.DockArea.OldOnGUI () (at <015079d9a4ea4f97b4381e694d2310c1>:0)
UnityEngine.UIElements.IMGUIContainer.DoOnGUI (UnityEngine.Event evt, UnityEngine.Matrix4x4 parentTransform, UnityEngine.Rect clippingRect, System.Boolean isComputingLayout, UnityEngine.Rect layoutSize, System.Action onGUIHandler, System.Boolean canAffectFocus) (at <1fd6bc3af931450b977286a218b046fb>:0)
UnityEngine.UIElements.IMGUIContainer.HandleIMGUIEvent (UnityEngine.Event e, UnityEngine.Matrix4x4 worldTransform, UnityEngine.Rect clippingRect, System.Action onGUIHandler, System.Boolean canAffectFocus) (at <1fd6bc3af931450b977286a218b046fb>:0)
UnityEngine.UIElements.IMGUIContainer.DoIMGUIRepaint () (at <1fd6bc3af931450b977286a218b046fb>:0)
UnityEngine.UIElements.UIR.RenderChainCommand.ExecuteNonDrawMesh (UnityEngine.UIElements.UIR.DrawParams drawParams, System.Single pixelsPerPoint, System.Exception& immediateException) (at <1fd6bc3af931450b977286a218b046fb>:0)
Rethrow as ImmediateModeException
UnityEngine.UIElements.UIR.RenderChain.Render () (at <1fd6bc3af931450b977286a218b046fb>:0)
UnityEngine.UIElements.UIRRepaintUpdater.Update () (at <1fd6bc3af931450b977286a218b046fb>:0)
UnityEngine.UIElements.VisualTreeUpdater.UpdateVisualTreePhase (UnityEngine.UIElements.VisualTreeUpdatePhase phase) (at <1fd6bc3af931450b977286a218b046fb>:0)
UnityEngine.UIElements.Panel.UpdateForRepaint () (at <1fd6bc3af931450b977286a218b046fb>:0)
UnityEngine.UIElements.Panel.Repaint (UnityEngine.Event e) (at <1fd6bc3af931450b977286a218b046fb>:0)
UnityEngine.UIElements.UIElementsUtility.DoDispatch (UnityEngine.UIElements.BaseVisualElementPanel panel) (at <1fd6bc3af931450b977286a218b046fb>:0)
UnityEngine.UIElements.UIElementsUtility.UnityEngine.UIElements.IUIElementsUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr, System.Boolean& eventHandled) (at <1fd6bc3af931450b977286a218b046fb>:0)
UnityEngine.UIElements.UIEventRegistration.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr) (at <1fd6bc3af931450b977286a218b046fb>:0)
UnityEngine.UIElements.UIEventRegistration+<>c.<.cctor>b__1_2 (System.Int32 i, System.IntPtr ptr) (at <1fd6bc3af931450b977286a218b046fb>:0)
UnityEngine.GUIUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr, System.Boolean& result) (at <6ddf8eac3856492ab1b8cf42618915cc>:0)
LogicalError commented 3 years ago

Hi @vncastanheira 'sceneRanges.empty()' is a Unity error and has nothing to do with Realtime CSG As for the rest, in Project Settings/Editor, what are your "Enter Play Mode Settings"? They should be set to the default values image

vncastanheira commented 3 years ago

Hi @vncastanheira 'sceneRanges.empty()' is a Unity error and has nothing to do with Realtime CSG As for the rest, in Project Settings/Editor, what are your "Enter Play Mode Settings"? They should be set to the default values image

The error stopped! Could it be this?

LogicalError commented 3 years ago

I suspect this is it then, entering playmode without a domain reload is not supported by realtime-CSG, it simply was not designed with that in mind (this feature is much newer than realtime-CSG)