neokabuto / OpenTKTutorialContent

Project files from OpenTK tutorials from my blog
MIT License
97 stars 22 forks source link

Access violation on call of GL.DrawElements in Tutorial 6 #11

Open uzername opened 5 years ago

uzername commented 5 years ago

https://github.com/neokabuto/OpenTKTutorialContent/blob/60e9668c2f283a3d9600d62fd67a30e619e7d9c9/OpenTKTutorial6/OpenTKTutorial6/Game.cs#L104

I am using OpenTK 3.0.1 from official Nuget, and I get access violation (writing attempt to protected memory) error on this line. In tutorial 5 you use GL.DrawArrays and it's fine there

neokabuto commented 5 years ago

This is sort of an embarrassingly long standing issue. It seems to be something non-deterministic that loves to "fix" itself. I've spent hours trying to figure it out, but it's really inconsistent on when it happens.

Can you try the change I added in the OpenTK 3 PR, https://github.com/neokabuto/OpenTKTutorialContent/pull/13/files#diff-816f14b5ba6b1b047326f50ca21fe968R167 (thanks again for inspiring me to finally upgrade these)? I'm pretty sure I finally (not sure why it took me so long) figured out it's a race condition where the first render code was running before the first update code occasionally (which I thought I had tested for previously with no success, but it seems to work). This if statement just prevents it from trying to render until we know we have some vertices to draw.