1
DotNet / Re: OpenTK AccessViolationException on any OpenGL call
« on: October 15, 2016, 02:09:22 am »
Sorry for ressurrecting this, but I had the exactly same problem and managed to solve, so I thought it could be a good idea to let the solution here for someone who, just as me, needs it.
I was trying to reproduce this example but failing by getting AccessViolaton exception. Based on Ztormi's link I managed to make it work by the following:
I was trying to reproduce this example but failing by getting AccessViolaton exception. Based on Ztormi's link I managed to make it work by the following:
using System;
using System.Runtime.InteropServices;
using SFML.Window;
using SFML.System;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;
using OpenTKUtilities = OpenTK.Platform.Utilities;
namespace SharpGL.Examples.Window
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main()
{
var contextSettings = new ContextSettings {
DepthBits = 24,
};
var window = new Window(new VideoMode(640, 480), "SFML window with OpenGL", Styles.Default, contextSettings);
window.SetActive();
Toolkit.Init();
// Solution: creating a windowInfo and associating it with the GraphicsContext
var windowInfo = new OpenTKUtilities.CreateWindowInfo(window.SystemHandle);
var context = new GraphicsContext(new ContextHandle(IntPtr.Zero), windowInfo); // windowInfo instead of null
context.MakeCurrent(windowInfo);
context.LoadAll();
// Everything else from now on is the same from the example (starting from Events setup)
}
}
}
using System.Runtime.InteropServices;
using SFML.Window;
using SFML.System;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;
using OpenTKUtilities = OpenTK.Platform.Utilities;
namespace SharpGL.Examples.Window
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main()
{
var contextSettings = new ContextSettings {
DepthBits = 24,
};
var window = new Window(new VideoMode(640, 480), "SFML window with OpenGL", Styles.Default, contextSettings);
window.SetActive();
Toolkit.Init();
// Solution: creating a windowInfo and associating it with the GraphicsContext
var windowInfo = new OpenTKUtilities.CreateWindowInfo(window.SystemHandle);
var context = new GraphicsContext(new ContextHandle(IntPtr.Zero), windowInfo); // windowInfo instead of null
context.MakeCurrent(windowInfo);
context.LoadAll();
// Everything else from now on is the same from the example (starting from Events setup)
}
}
}