NogginBops / ImGui.NET_OpenTK_Sample

A sample project showing an ImGui (using ImGui.NET) renderer for OpenTK in C#
106 stars 27 forks source link

AccessViolationException with latest OpenTK package (4.0.0-pre9.4) #9

Closed dfkeenan closed 3 years ago

dfkeenan commented 3 years ago

Hi,

I was trying to use this sample with the latest NuGet packages. After updating OpenTK to 4.0.0-pre9.4 and ImGuiNet to 1.78.0. I started getting System.AccessViolationException in the ImGuiController.RenderImDrawData method. I thought I might have broken something when I copied the code. So I downloaded the opentk4.0 branch. I updated the NuGet packages and changed the OpenToolkit namespaces to OpenTK and got the same error.

The error happens with the call to GL.DrawElementsBaseVertex.

https://github.com/NogginBops/ImGui.NET_OpenTK_Sample/blob/3e45958946c8f1ad8c4b1c6e543662a563769c55/Dear%20ImGui%20Sample/ImGuiController.cs#L372

NogginBops commented 3 years ago

Thank you for the bug report 🤗

I have updated the opentk4.0 branch to use the latest pre-released of OpenTK.

The issue was that OpenTK 4-pre9.4 doesn't automatically make a opengl context "current" on the main thread, this doesn't happen in the later pre-releases so I needed to add a call to MakeCurrent() in the OnLoad method. Because there was no context current all of the opengl calls where invalid operations and the buffers null, so the call do draw had no data, hence the AccessViolation.

Try it out and see if that fixed the issue you where having 🙂

dfkeenan commented 3 years ago

It works. \o/ Thank You!!

This is my first time playing with OpenGL and ImGui. I had no idea what to even look for. :D