Skip to content
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

<view> GameObject is not removed after Restart #76

Closed
Muchaszewski opened this issue Nov 29, 2022 · 6 comments
Closed

<view> GameObject is not removed after Restart #76

Muchaszewski opened this issue Nov 29, 2022 · 6 comments
Labels
bug Something isn't working

Comments

@Muchaszewski
Copy link
Contributor

NOTE: The error, in this case, does not matter, but I will include it at the end because it might provide a hint for debugging.

Every time an error occurs the <view> GameObject is not removed from the scene view when restarting. This also is happening when auto restart/hot reload mechanism triggers.

On an unrelated note should not it be part of the Canvas view for easier management?

Video.mp4

The view is part of an error
image

[2022-11-29 17:40:28.110] [Error] The above error occurred in the <App> component:

    at App (<input>:16)
    at GlobalsProvider (<input>:54)
    at ErrorBoundary (<input>:47)
    at DefaultView (<input>:12)

React will try to recreate this component tree from scratch using the error boundary you provided, ErrorBoundary.
 at ReactUnity.Scripting.DomProxies.ConsoleProxy:GenericLog (object,System.Action`1<string>,object[]) (at Library/PackageCache/com.reactunity.core@712c19ae9f/Runtime/Scripting/DomProxies/Console.cs:40)
ReactUnity.Scripting.DomProxies.ConsoleProxy:error (object,object[]) (at Library/PackageCache/com.reactunity.core@712c19ae9f/Runtime/Scripting/DomProxies/Console.cs:65)
System.Reflection.MonoMethod:Invoke (object,System.Reflection.BindingFlags,System.Reflection.Binder,object[],System.Globalization.CultureInfo)
System.Reflection.MethodBase:Invoke (object,object[])
QuickJS.Binding.DynamicVariadicMethod:Invoke (QuickJS.Native.JSContext,QuickJS.Native.JSValue,int,QuickJS.Native.JSValue[]) (at Library/PackageCache/com.reactunity.quickjs@0.13.0/Runtime/Source/Binding/DynamicMethod.cs:366)
QuickJS.Utils.TypeDB:_DynamicMethodInvoke (QuickJS.Native.JSContext,QuickJS.Native.JSValue,int,QuickJS.Native.JSValue[],int) (at Library/PackageCache/com.reactunity.quickjs@0.13.0/Runtime/Source/Utils/TypeDB.cs:428)
QuickJS.ScriptFunction:_Invoke (QuickJS.Native.JSContext,int,QuickJS.Native.JSValue*) (at Library/PackageCache/com.reactunity.quickjs@0.13.0/Runtime/Source/ScriptFunction.cs:207)
QuickJS.ScriptFunction:Invoke (System.Type,object[]) (at Library/PackageCache/com.reactunity.quickjs@0.13.0/Runtime/Source/ScriptFunction.cs:190)
QuickJS.ScriptFunction:Invoke<object> (object[]) (at Library/PackageCache/com.reactunity.quickjs@0.13.0/Runtime/Source/ScriptFunction.cs:173)
ReactUnity.Helpers.Callback:Call (object[]) (at Library/PackageCache/com.reactunity.core@712c19ae9f/Runtime/Helpers/Callback.cs:131)
ReactUnity.Helpers.Callback:Call () (at Library/PackageCache/com.reactunity.core@712c19ae9f/Runtime/Helpers/Callback.cs:63)
ReactUnity.Scheduling.DefaultScheduler/<>c__DisplayClass7_0:<setImmediate>b__0 () (at Library/PackageCache/com.reactunity.core@712c19ae9f/Runtime/Scheduling/DefaultScheduler.cs:41)
ReactUnity.Scheduling.BaseDispatcher`1/<OnUpdateCoroutine>d__23<UnityEngine.Coroutine>:MoveNext () (at Library/PackageCache/com.reactunity.core@712c19ae9f/Runtime/Scheduling/BaseDispatcher.cs:168)
ReactUnity.Scheduling.BaseDispatcher`1<UnityEngine.Coroutine>:StartAndStopDeferreds (bool) (at Library/PackageCache/com.reactunity.core@712c19ae9f/Runtime/Scheduling/BaseDispatcher.cs:136)
ReactUnity.Scheduling.BaseDispatcher`1<UnityEngine.Coroutine>:Update () (at Library/PackageCache/com.reactunity.core@712c19ae9f/Runtime/Scheduling/BaseDispatcher.cs:199)
ReactUnity.Scheduling.RuntimeDispatcherBehavior:Update () (at Library/PackageCache/com.reactunity.core@712c19ae9f/Runtime/Scheduling/RuntimeDispatcher.cs:28)
@Muchaszewski
Copy link
Contributor Author

The same <view> component is part of Canvas
image

@KurtGokhan KurtGokhan added the bug Something isn't working label Dec 9, 2022
@KurtGokhan
Copy link
Member

Unity doesn't have a way to create objects but not place them in the scene. Ideally, we could place all newly created objects in [Offscreen], but I guess that would affect performance just by changing an object's parent. Alternative way would be to remove every object individually after canvas is destroyed, but that would also cost performance.

In an ideal case, there shouldn't be an error in the React rendering. So I don't want to implement this in a way that would affect performance much.

@Thundernerd
Copy link

Thundernerd commented Feb 21, 2023

Unity doesn't have a way to create objects but not place them in the scene.

I believe you are correct in saying this, but can't you disable the objects to "fake" them not being there?

Alternative way would be to remove every object individually after canvas is destroyed, but that would also cost performance.

It might depend on how the canvas is destroyed, but if views are children of a specific canvas and you remove the canvas, I would expect it to remove the children as well, even if it would affect performance or not, because it needs to clean up after itself.

@KurtGokhan
Copy link
Member

@Thundernerd Thanks for your suggestions.

Normally, when a view is created it is placed under the canvas. But in this case, an error happens before they are placed under the canvas. That is the root cause of this issue. So your second suggestion would not work.

Disabling and enabling objects can affect performance, even if it would be minor. Also objects would still be there, so I don't think that is a solution as well.

I have some plans to fix this, but haven't started working on it yet.

@KurtGokhan
Copy link
Member

I misunderstood the issue first. I can see the issue after trying it again.

It may be caused by a bug in React. I reported it here: facebook/react#26518

Let's see what React devs say about it. If it doesn't get fixed in React, I will fix it with a workaround in ReactUnity.

@KurtGokhan KurtGokhan added the pending fix This issue is already fixed, but not released yet. label Mar 30, 2023
@KurtGokhan
Copy link
Member

Applied the workaround in 0.15.2. This is still a bug in React side. But shouldn't be a problem in ReactUnity anymore.

@KurtGokhan KurtGokhan removed the pending fix This issue is already fixed, but not released yet. label Mar 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants