Runtime System.ArgumentException: область просмотра недопустима - PullRequest
0 голосов
/ 07 октября 2019

У меня есть Main, который создает объект, производный от Monocle.Engine (где выбрасывается исключение). Любая и вся помощь будет оценена, я был в этом в течение 2 дней. Спасибо.

все эти фрагменты находятся в одном пространстве имен и файла. Следующий код также включает любые упоминания о Viewport.

//called once per frame
        protected override void Draw(GameTime gameTime)
        {
            RenderCore();

            base.Draw(gameTime);
            if (Commands.Open)
                Commands.Render();

            //Frame counter
            fpsCounter++;
            counterElapsed += gameTime.ElapsedGameTime;
            if (counterElapsed >= TimeSpan.FromSeconds(1))
            {
#if DEBUG
                Window.Title = Title + " " + fpsCounter.ToString() + " fps - " + (GC.GetTotalMemory(false) / 1048576f).ToString("F") + " MB";
#endif
                FPS = fpsCounter;
                fpsCounter = 0;
                counterElapsed -= TimeSpan.FromSeconds(1);
            }
        }



        protected virtual void RenderCore()
        {
            if (scene != null)
                scene.BeforeRender();

            GraphicsDevice.SetRenderTarget(null);
            GraphicsDevice.Viewport = Viewport; //throws the exception here
            GraphicsDevice.Clear(ClearColor);

            if (scene != null)
            {
                scene.Render();
                scene.AfterRender();
            }
        }

//only other mention of ViewPort
//called on window resize, graphics creation and graphics reset
private void UpdateView()
        {
            float screenWidth = GraphicsDevice.PresentationParameters.BackBufferWidth;
            float screenHeight = GraphicsDevice.PresentationParameters.BackBufferHeight;

            // get View Size
            if (screenWidth / Width > screenHeight / Height)
            {
                ViewWidth = (int)(screenHeight / Height * Width);
                ViewHeight = (int)screenHeight;
            }
            else
            {
                ViewWidth = (int)screenWidth;
                ViewHeight = (int)(screenWidth / Width * Height);
            }

            // apply View Padding
            var aspect = ViewHeight / (float)ViewWidth;
            ViewWidth -= ViewPadding * 2;
            ViewHeight -= (int)(aspect * ViewPadding * 2);

            // update screen matrix
            ScreenMatrix = Matrix.CreateScale(ViewWidth / (float)Width);

            // update viewport
            Viewport = new Viewport
            {
                X = (int)(screenWidth / 2 - ViewWidth / 2),
                Y = (int)(screenHeight / 2 - ViewHeight / 2),
                Width = ViewWidth,
                Height = ViewHeight,
                MinDepth = 0,
                MaxDepth = 1
            };

При отладке появляется пустое окно, но код генерирует исключение Runtime System.ArgumentException.

полная ошибка:

System.ArgumentException: 'The viewport is invalid. The viewport cannot be larger than or outside of the current render target bounds. The MinDepth and MaxDepth must be between 0 and 1.
Parameter name: value'

Спасибо, что прочитали мой вопрос!

...