Esempio n. 1
0
        private static unsafe void OnRuntimeChanged()
        {
            if (SharedRuntimeState.IsActiveRuntime)
            {
                if (!File.Exists(mainAssemblyPath))
                {
                    SharedRuntimeState.SetHotReloadData(null);

                    // Cancel the runtime swap
                    SharedRuntimeState.Instance->NextRuntime             = EDotNetRuntime.None;
                    SharedRuntimeState.Instance->IsActiveRuntimeComplete = 0;
                    return;
                }

                if (!mainContextRef.IsInvalid)
                {
                    UnloadMainContext();
                }
                Debug.Assert(mainContextRef.IsInvalid, "UnloadMainContext failed?");
                Debug.Assert(!LoadAssemblyWithoutContexts, "Assembly context loading is required in order to swap runtimes");

                SharedRuntimeState.Instance->IsActiveRuntimeComplete = 1;
            }
            else if (SharedRuntimeState.Instance->NextRuntime == SharedRuntimeState.CurrentRuntime)
            {
                SharedRuntimeState.Instance->ActiveRuntime           = SharedRuntimeState.CurrentRuntime;
                SharedRuntimeState.Instance->NextRuntime             = EDotNetRuntime.None;
                SharedRuntimeState.Instance->IsActiveRuntimeComplete = 0;
                ReloadMainContext();
            }
        }
Esempio n. 2
0
 private static bool LoadWithoutUsingContexts()
 {
     try
     {
         AssemblyLoader loader = new AssemblyLoader(
             mainAssemblyPath, entryPointType, entryPointMethod, entryPointArg, false, Runtime.AssemblyContextRef.Invalid);
         loader.Load();
         return(true);
     }
     catch (Exception e)
     {
         MessageBox("Failed to load assembly \"" + mainAssemblyPath + "\" " +
                    Environment.NewLine + Environment.NewLine + e, errorMsgBoxTitle);
         SharedRuntimeState.SetHotReloadData(null);
         return(false);
     }
 }
Esempio n. 3
0
        private static unsafe void OnRuntimeChanged()
        {
            if (SharedRuntimeState.IsActiveRuntime)
            {
                if (!File.Exists(mainAssemblyPath))
                {
                    SharedRuntimeState.SetHotReloadData(null);                    

                    // Cancel the runtime swap
                    SharedRuntimeState.Instance->NextRuntime = EDotNetRuntime.None;
                    SharedRuntimeState.Instance->IsActiveRuntimeComplete = 0;
                    SharedRuntimeState.Instance->Reload = false;
                    return;
                }

                if (SharedRuntimeState.Instance->Reload)
                {
                    // This is a reload as opposed to a runtime swap, reload it now and return
                    SharedRuntimeState.Instance->Reload = false;

                    // Only reload if we are using assembly contexts (AppDomain / AssemblyLoadContext)
                    if (!LoadAssemblyWithoutContexts)
                    {
                        ReloadMainContext();
                    }
                    return;
                }

                if (!mainContextRef.IsInvalid)
                {
                    UnloadMainContext();
                }
                Debug.Assert(mainContextRef.IsInvalid, "UnloadMainContext failed?");
                Debug.Assert(!LoadAssemblyWithoutContexts, "Assembly context loading is required in order to swap runtimes");
                
                SharedRuntimeState.Instance->IsActiveRuntimeComplete = 1;
            }
            else if (SharedRuntimeState.Instance->NextRuntime == SharedRuntimeState.CurrentRuntime)
            {
                SharedRuntimeState.Instance->ActiveRuntime = SharedRuntimeState.CurrentRuntime;
                SharedRuntimeState.Instance->NextRuntime = EDotNetRuntime.None;
                SharedRuntimeState.Instance->IsActiveRuntimeComplete = 0;
                ReloadMainContext();
            }
        }
Esempio n. 4
0
        public static void Unload()
        {
            DateTime beginUnloadTime = DateTime.Now;

            FMessage.Log("BeginUnload: " + beginUnloadTime.TimeOfDay);

            HotReload.OnUnload();

            HotReload.Data.BeginUnloadTime = beginUnloadTime;
            byte[] data = HotReload.Data.Save();
            HotReload.Data.Close();

            SharedRuntimeState.SetHotReloadData(data);

            TimeSpan endUnloadTime = DateTime.Now.TimeOfDay;

            FMessage.Log("EndUnload: " + endUnloadTime + " (" + (endUnloadTime - beginUnloadTime.TimeOfDay) + ")");
        }
Esempio n. 5
0
        private static bool ReloadMainContext(bool threaded = true)
        {
            if (!GameThreadHelper.IsInGameThread())
            {
                bool result = false;
                GameThreadHelper.Run(delegate { result = ReloadMainContext(); });
                return(result);
            }

            if (!SharedRuntimeState.IsActiveRuntime)
            {
                return(false);
            }

            if (!File.Exists(mainAssemblyPath))
            {
                SharedRuntimeState.SetHotReloadData(null);
                return(false);
            }

            if (!mainContextRef.IsInvalid)
            {
                UnloadMainContext(threaded);
            }

            string entryPointArgEx = entryPointArg;
            bool   firstLoad       = preloadContextWaitHandle == null;

            if (firstLoad)
            {
                PreloadNextContext(threaded);
            }
            else
            {
                entryPointArgEx += "|Reloading=true";
            }

            preloadContextWaitHandle.WaitOne(Timeout.Infinite);
            preloadContextWaitHandle.Reset();

            if (!preloadFailed)
            {
                Debug.Assert(!preloadedContextRef.IsInvalid, "Preloaded context shouldn't be invalid");

                mainContextRef      = preloadedContextRef;
                preloadedContextRef = Runtime.AssemblyContextRef.Invalid;

                entryPointArgEx += "|AssemblyContext=" + mainContextRef.Format();

                try
                {
                    AssemblyLoader loader = new AssemblyLoader(mainAssemblyPath, entryPointType, entryPointMethod, entryPointArgEx, false, mainContextRef);
                    mainContextRef.DoCallBack(loader.Load);
                    UpdateAssemblyWatchers();
                }
                catch (Exception e)
                {
                    MessageBox("Failed to create assembly context for \"" + mainAssemblyPath + "\" " +
                               Environment.NewLine + Environment.NewLine + e, errorMsgBoxTitle);
                }
            }

            PreloadNextContext(threaded);
            SharedRuntimeState.SetHotReloadData(null);
            return(true);
        }