LolDragonFire's picture

Exit error

Hey,
I program a little game but if I want to close it with this code:

if (Keyboard[Key.Escape])
                Exit();

which is in OnUpdateFrame, the GameWindow closes but the Console won't disappear and a window appears: "vshost32.exe has stopped working"
My question is how can exit the game without an this error?


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

Exit() will close the GameWindow and return from GameWindow.Run(). Make sure you are not calling any OpenGL functions after the GameWindow.Closed event is fired.

Without more information, it is impossible to tell why you are getting this error.

  • Which version of OpenTK are you using?
  • Which platform backend? (native windows or SDL?)
  • Try running your application with a debug version of OpenTK.dll. The output window (ctrl-w, ctrl-o in Visual Studio) will then contain additional debugging information - please post that here.
LolDragonFire's picture

The version is 2013-11-25
and the code is:

using System;
using System.Drawing;
using OpenTK;
using OpenTK.Graphics.OpenGL;
using System.Windows.Forms;
using OpenTK.Input;
using OpenTK.Audio;
 
namespace DrawLines
{
    class Program : GameWindow
    {
 
        double time;
        int frames;
        bool fullscreen = true;
        public Program()
        {
            GL.LineWidth(4f);
            this.WindowState = WindowState.Fullscreen;
            this.WindowBorder = WindowBorder.Hidden;
        }
 
        protected override void OnResize(EventArgs e)
        {
            // Set orthographic rendering (useful when you want 2D)
            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadIdentity();
            GL.Ortho(this.ClientRectangle.Left, this.ClientRectangle.Right,
                this.ClientRectangle.Bottom, this.ClientRectangle.Top, -1.0, 1.0);
            GL.Viewport(this.ClientRectangle.Size);
        }
 
        protected override void OnUpdateFrame(FrameEventArgs e)
        {
            if (Keyboard[Key.Escape])
            {
                Exit();
            }
            if (Keyboard[Key.F])
            {
                if (fullscreen)
                {
                    this.WindowBorder = WindowBorder.Resizable;
                    this.WindowState = WindowState.Normal;
                    fullscreen = false;
                }
                else
                {
                    this.WindowState = WindowState.Fullscreen;
                    this.WindowBorder = WindowBorder.Hidden;
                    fullscreen = true;
                }
            }
 
            if ((time += e.Time) >= 1.0)
            {
                time = 0;
                this.Title = "Game - " + Convert.ToString(frames) + " FPS";
                frames = 0;
            }            
        }
 
        protected override void OnUnload(EventArgs e)
        {
            Console.WriteLine("EXIT");
        }
 
        protected override void OnRenderFrame(FrameEventArgs e)
        {
            frames++;
            //if (time == 0f)
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
 
            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadIdentity();
 
            GL.Begin(BeginMode.Lines);
 
            GL.Vertex2(0, 0);
            GL.Vertex2(Width, Height);
 
            GL.Vertex2(Width, 0);
            GL.Vertex2(0, Height);
 
 
            GL.End();
 
 
            SwapBuffers();  
        }
 
        public static void Main(string[] args)
        {
            using (Program p = new Program())
            {
                p.Run();
            }            
        }
    }
}
the Fiddler's picture

This code looks fine and indeed, I'm not getting any errors when I run it. I tested with Visual Studio 2013 on Windows 8.1.

We need a way to diagnose what is causing this error. Below is a debug version of OpenTK.dll:

https://www.dropbox.com/s/4gzrymfk4hviode/opentk-2013-12-6-debug.zip

Unzip it somewhere on your disk, remove the existing reference to OpenTK.dll from your project and add a reference to this debug version. If you execute your application now, you should get a stack trace for the crash. Please post that here so we can diagnose the problem.