Skip to content

GLFW backend fails on macOS: missing glfwMakeContextCurrent() before GLEW initialization #4

@ShugoSUWAZONO

Description

@ShugoSUWAZONO

I tried installing PDL::Graphics::TriD and failed to see demo. Claude.ai helped me to workaround as follows, I hope helps communitiy:

Environment

  • macOS Sequoia (Intel Mac mini)
  • Perl 5.42.1 (Homebrew)
  • PDL::Graphics::TriD 2.102
  • OpenGL::Modern 0.0404
  • freeglut 3.8.0 (Homebrew)

Problem

Running demo 3d in pdl2 crashes with:

Error: Missing GL version at .../PDL/Graphics/TriD/GL.pm line 499

The error string "Missing GL version" originates from
OpenGL::Modern's GLEW initialization code (glew.c).

Root Cause

In lib/PDL/Graphics/TriD/GL/GLFW.pm, after glfwCreateWindow() is
called, there is no call to glfwMakeContextCurrent() before GLEW
attempts to retrieve the GL version. GLEW requires an active OpenGL
context to initialize correctly. On macOS, unlike some Linux
configurations, OpenGL contexts are never implicitly made current, so
glewInit() fails immediately.

The fix should be to add:

glfwMakeContextCurrent($glfwin);

immediately after the glfwCreateWindow() call (around line 21 of
GLFW.pm).

Workaround

Setting the environment variable before launching pdl2 works around
the issue by switching to the GLUT backend:

export POGL_WINDOW_TYPE=glut

Notes

The GLUT backend works correctly on this system.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions