public void Close()
 {
     Debug.WriteLine($"PreviewerApplication.Close for asset={currentAsset}");
     urhoScene?.Exit();
     urhoScene = null;
 }
        public async Task <UrhoScene> Show(string file, IEditor editor, int initialWidth = 1000, int initialHeight = 1000)
        {
            try
            {
                this.editor    = editor;
                lastLoadedFile = file;
                cancellationSource.Cancel();
                cancellationSource = new CancellationTokenSource();
                await semaphoreSlim.WaitAsync();

                var token = cancellationSource.Token;
                token.Register(Close);

                var asset = await assetsResolver.ResolveAsset(file, token);

                if (asset == null)
                {
                    throw new NotSupportedException($"{file} is not supported");
                }
                token.ThrowIfCancellationRequested();

                token.ThrowIfCancellationRequested();
                Debug.WriteLine($"PreviewerApplication.Show for: {file}, resolved asset={asset}, asm.location={Assembly.GetExecutingAssembly().Location}");

                if (Application.HasCurrent)
                {
                    await Application.Current.Exit();
                }
                token.ThrowIfCancellationRequested();

                IsPaused = false;

                IntPtr surfacePtr = SurfaceRecreationRequested?.Invoke() ?? IntPtr.Zero;
                if (surfacePtr == IntPtr.Zero)
                {
                    return(null);
                }

                urhoScene = new UrhoScene(new ApplicationOptions
                {
                    ExternalWindow = surfacePtr,
                    ResourcePaths  = new[] { asset.RootDirectory, "ViewerAssets" },

                    Width               = initialWidth,
                    Height              = initialHeight,
                    AutoloadCoreData    = false,
                    LimitFps            = false,
                    ResizableWindow     = true,
                    Multisampling       = Environment.OSVersion.Platform == PlatformID.Win32NT ? 0 : 8,
                    ResourcePrefixPaths = new[] { Environment.CurrentDirectory },
                    DelayedStart        = true,
                });

                token.ThrowIfCancellationRequested();
                urhoScene.Run();
                token.ThrowIfCancellationRequested();

                currentAsset = asset;
                urhoScene.ShowAsset(asset, editor);
                RunFrames();
                return(urhoScene);
            }
            catch (Exception)
            {
                Close();
                throw;
            }
            finally
            {
                semaphoreSlim.Release();
            }
        }
 public void Close()
 {
     Log.Write(LogLevel.Debug, $"PreviewerApplication.Close for asset={currentAsset}");
     urhoScene?.Exit();
     urhoScene = null;
 }