New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mac OS: NSView, OpenTK and NullReferenceException #330

Open
bchavez opened this Issue Jan 4, 2016 · 2 comments

Comments

4 participants
@bchavez

bchavez commented Jan 4, 2016

Hello,

I'm having a hard time getting an NSView (from MonoMac) working with OpenTK working on mac.

I'm working on a Map Editor for a game. My map editor has two GL surfaces as shown below:

Map Editor

Left surface shows loaded terrain textures (via GL) and right side is the 3D rendered map (via GL). On windows and linux everything works perfectly. Both GL surfaces share texture graphic contexts.

Mac, however, has been somewhat of a pain. On the mac platform, both left and right panels are NSViews. I cannot get shared contexts between both surfaces using OpenTK.

Attempt 1

Originally, I tried manually creating an NSOpenGLContext (from MonoMac) and passing it to OpenTK as an externally created context, but didn't get very far. I get a somewhat related issue: #52 where CreateDummyContext that kept throwing a "key not found" exception.

Attempt 2

My current attempt is to try and use CreateMacOSWindowInfo and hopefully have OpenTK manage both graphics contexts automatically. However, my current attempt runs into a NullReferenceException when I use any of the GL methods like GL.ClearColor. My current code is here: https://github.com/bchavez/SharpFlame/blob/eto/source/Eto.Gl.Mac/MacGLView8.cs#L115

public void InitGL()
{
  OpenTK.Graphics.GraphicsContext.ShareContexts = true;

  var gpxMode = GraphicsMode.Default;

    this.windowInfo = OpenTK.Platform.Utilities.CreateMacOSWindowInfo(this.Window.Handle, this.Handle);

  this.openTK = new OpenTK.Graphics.GraphicsContext(gpxMode, this.windowInfo, 1, 0, GraphicsContextFlags.ForwardCompatible);

  this.openTK.MakeCurrent(this.windowInfo);

  //Null Reference Exception Here
  GL.ClearColor(OpenTK.Graphics.Color4.CornflowerBlue);

  this.IsInitialized = true;

screen542

My guess is, OpenTK didn't setup the GraphicsContext I received correctly, somewhere.

My open source project can be found here: https://github.com/bchavez/SharpFlame/

I'd appreciate it if anyone could help me solve this issue.

Thanks,
Brian

@varon

This comment has been minimized.

Show comment
Hide comment
@varon

varon Jun 11, 2017

Member

@UnknownShadow200 - here's a mac issue that would be worth looking at.

Member

varon commented Jun 11, 2017

@UnknownShadow200 - here's a mac issue that would be worth looking at.

@UnknownShadow200

This comment has been minimized.

Show comment
Hide comment
@UnknownShadow200

UnknownShadow200 Jun 12, 2017

Contributor
Contributor

UnknownShadow200 commented Jun 12, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment