Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Annoying compiler warning, I don't think is correct

Discussion in 'Scripting' started by sebas77, Feb 6, 2020.

  1. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,641
    I got files like this one:

    Code (CSharp):
    1. #if UNITY_5 || UNITY_5_3_OR_NEWER
    2. using Svelto.Tasks.FlowModifiers;
    3. using Svelto.Tasks.Unity.Internal;
    4. using System.Collections;
    5. using System.Collections.Generic;
    6. using Svelto.Tasks.Internal;
    7.  
    8. namespace Svelto.Tasks
    9. {
    10.     namespace Lean.Unity
    11.     {
    12.         public class OnGuiRunner : OnGuiRunner<IEnumerator<TaskContract>>
    13.         {
    14.             public OnGuiRunner(string name) : base(name) {}
    15.             public OnGuiRunner(string name, uint runningOrder) : base(name, runningOrder) {}
    16.         }
    17.  
    18.         public class OnGuiRunner<T> : Svelto.Tasks.Unity.OnGuiRunner<LeanSveltoTask<T>>
    19.             where T : IEnumerator<TaskContract>
    20.         {
    21.             public OnGuiRunner(string name) : base(name) {}
    22.             public OnGuiRunner(string name, uint runningOrder) : base(name, runningOrder) {}
    23.         }
    24.     }
    25.  
    26.     namespace ExtraLean.Unity
    27.     {
    28.         public class OnGuiRunner : OnGuiRunner<IEnumerator>
    29.         {
    30.             public OnGuiRunner(string name) : base(name) {}
    31.             public OnGuiRunner(string name, uint runningOrder) : base(name, runningOrder) {}
    32.         }
    33.  
    34.         public class OnGuiRunner<T> : Svelto.Tasks.Unity.OnGuiRunner<ExtraLeanSveltoTask<T>> where T : IEnumerator
    35.         {
    36.             public OnGuiRunner(string name) : base(name) {}
    37.             public OnGuiRunner(string name, uint runningOrder) : base(name, runningOrder) {}
    38.         }
    39.     }
    40.  
    41.     namespace Unity
    42.     {
    43.         public abstract class OnGuiRunner<T> : OnGuiRunner<T, StandardRunningInfo> where T : ISveltoTask
    44.         {
    45.             protected OnGuiRunner(string name) : base(name, 0, new StandardRunningInfo()) {}
    46.             protected OnGuiRunner(string name, uint runningOrder) : base(name, runningOrder,
    47.                 new StandardRunningInfo()) {}
    48.         }
    49.  
    50.         public abstract class OnGuiRunner<T, TFlowModifier> : BaseRunner<T> where T : ISveltoTask
    51.             where TFlowModifier : IFlowModifier
    52.         {
    53.             protected OnGuiRunner(string name, uint runningOrder, TFlowModifier modifier) : base(name)
    54.             {
    55.                 modifier.runnerName = name;
    56.  
    57.                 _processEnumerator =
    58.                     new SveltoTaskRunner<T>.Process<TFlowModifier>
    59.                         (_newTaskRoutines, _coroutines, _flushingOperation, modifier);
    60.  
    61.                 UnityCoroutineRunner.StartOnGuiCoroutine(_processEnumerator, runningOrder);
    62.             }
    63.         }
    64.     }
    65. }
    66. #endif
    Code (CSharp):
    1. using System;
    2. using Svelto.Common;
    3. using Svelto.DataStructures;
    4. using Svelto.Tasks.DataStructures;
    5. using Svelto.Tasks.Internal;
    6.  
    7. namespace Svelto.Tasks
    8. {
    9.     /// <summary>
    10.     /// Remember, unless you are using the StandardSchedulers, nothing hold your runners. Be careful that if you
    11.     /// don't hold a reference, they will be garbage collected even if tasks are still running
    12.     /// </summary>
    13.     public abstract class BaseRunner<T> : IRunner, IRunner<T> where T : ISveltoTask
    14.     {
    15.         public bool isStopping => _flushingOperation.stopping;
    16.         public bool isKilled   => _flushingOperation.kill;
    17.         public bool hasTasks   => numberOfProcessingTasks != 0;
    18.  
    19.         public uint numberOfRunningTasks    => _coroutines.count;
    20.         public uint numberOfQueuedTasks     => _newTaskRoutines.Count;
    21.         public uint numberOfProcessingTasks => _newTaskRoutines.Count + _coroutines.count;
    22.  
    23.         protected BaseRunner(string name, int size)
    24.         {
    25.             _name = name;
    26.             _newTaskRoutines = new ThreadSafeQueue<T>(size);
    27.             _coroutines = new FasterList<T>((uint) size);
    28.         }
    29.  
    30.         protected BaseRunner(string name)
    31.         {
    32.             _name = name;
    33.             _newTaskRoutines = new ThreadSafeQueue<T>(NUMBER_OF_INITIAL_COROUTINE);
    34.             _coroutines = new FasterList<T>(NUMBER_OF_INITIAL_COROUTINE);
    35.         }
    36.  
    37.         ~BaseRunner()
    38.         {
    39.             Console.LogWarning(this._name.FastConcat(" has been garbage collected, this could have serious" +
    40.                                                      "consequences, are you sure you want this? "));
    41.  
    42.             Stop();
    43.         }
    44.  
    45.         public void Flush()
    46.         {
    47.             Stop();
    48.             Step();
    49.         }
    50.  
    51.         public void Pause()
    52.         {
    53.             _flushingOperation.paused = true;
    54.         }
    55.  
    56.         public void Resume()
    57.         {
    58.             _flushingOperation.paused = false;
    59.         }
    60.  
    61.         public void Step()
    62.         {
    63.             using (var platform = new PlatformProfiler(this._name))
    64.             {
    65.                 _processEnumerator.MoveNext(false, platform);
    66.             }
    67.         }
    68.  
    69.         /// <summary>
    70.         /// TaskRunner doesn't stop executing tasks between scenes it's the final user responsibility to stop the tasks
    71.         /// if needed
    72.         /// </summary>
    73.         public virtual void Stop()
    74.         {
    75.             SveltoTaskRunner<T>.StopRoutines(_flushingOperation);
    76.  
    77.             _newTaskRoutines.Clear();
    78.         }
    79.  
    80.         void IRunner<T>.StartCoroutine(in T task /*, bool immediate*/)
    81.         {
    82.             _newTaskRoutines.Enqueue(task);
    83.  
    84.             //if (immediate)
    85.             //  _processEnumerator.MoveNext(true);
    86.         }
    87.  
    88.         public virtual void Dispose()
    89.         {
    90.             Stop();
    91.  
    92.             SveltoTaskRunner<T>.KillProcess(_flushingOperation);
    93.  
    94.             GC.SuppressFinalize(this);
    95.         }
    96.  
    97.         protected IProcessSveltoTasks InitializeRunner<TFlowModified>(TFlowModified modifier) where TFlowModified:IFlowModifier
    98.         {
    99.             _processEnumerator =
    100.                 new SveltoTaskRunner<T>.Process<TFlowModified>
    101.                     (_newTaskRoutines, _coroutines, _flushingOperation, modifier);
    102.  
    103.             return _processEnumerator;
    104.         }
    105.  
    106.  
    107.         IProcessSveltoTasks _processEnumerator;
    108.         readonly ThreadSafeQueue<T> _newTaskRoutines;
    109.         readonly FasterList<T>      _coroutines;
    110.         readonly SveltoTaskRunner<T>.FlushingOperation _flushingOperation = new SveltoTaskRunner<T>.FlushingOperation();
    111.  
    112.         readonly string _name;
    113.  
    114.         const int NUMBER_OF_INITIAL_COROUTINE = 3;
    115.     }
    116. }
    never had problems with them, but since 2019.3 I get this warning:

    Class OnGuiRunner can not exist in multiple namespaces in the same file, even if one is excluded with preprocessor directives. Please move these to separate files if this is the case.
    UnityEditor.Scripting.ScriptCompilers:GetClassAndNamespace(String, String, String&, String&)


    I understand this warning makes sense if the class was a Monobehaviour, but it is not. Thoughts?
     
    Last edited: Apr 15, 2020
    YurySedyakin likes this.
  2. epare025

    epare025

    Joined:
    Oct 9, 2017
    Posts:
    10
    I've come across the same issue concerning other frameworks. I haven't observed any negative effects. Since this is supposed to target classes that inherit from Monobehaviour or ScriptableObject, I think this may be a Unity bug.
     
  3. shanepadgett

    shanepadgett

    Joined:
    Jan 4, 2020
    Posts:
    3
    Happens with the UniRX library as well.
     
    YurySedyakin likes this.