Drawing using skia, with a glfw window managed from python. Crashes using Mac

Hi, I cant work out if this is a glfw or skia related issue, but perhaps someone here might be able to help.
I am making a python app that uses glfw (the python package glfw · PyPI) to manage a window and am trying to use skia (c++ library) to draw to this window. The application is compiled using python setuptools/pip. However I cannot seem to get this to work using macOS (v11.6.8), although everything seems to work fine on ubuntu. Also everything works fine if the glfw window is managed from the c++ layer and not python.

On the python side the window is created using:

(lib versions are: glfw ‘3.3.7 Cocoa NSGL EGL OSMesa dynamic’ and opengl version 2.1 ATI-4.6.21)

glfw.init()
glfw.window_hint(glfw.STENCIL_BITS, 8)
window = glfw.create_window(width, height, ‘’, None, None)
glfw.make_context_current(window)

I then have a c++ class that manages the skia surface. I try and initialize the context like this:

#include <OpenGL/gl.h> // note glfw is not included here


// glGetString(GL_VERSION) returns 2.1 ATI-4.6.21

auto interface = GrGLMakeNativeInterface();
sContext = GrDirectContext::MakeGL(interface).release();
if (!sContext) { return -1; }

GrGLFramebufferInfo framebufferInfo;
framebufferInfo.fFBOID = 0;
framebufferInfo.fFormat = GL_SRGB8_ALPHA8;

SkColorType colorType = kRGBA_8888_SkColorType;

// this crashes? →
GrBackendRenderTarget backendRenderTarget(width, height, 0, 8, framebufferInfo);

sSurface = SkSurface::MakeFromBackendRenderTarget(sContext, backendRenderTarget,
kBottomLeft_GrSurfaceOrigin, colorType,
SkColorSpace::MakeSRGB(), nullptr).release();

if (!sSurface) { return -1; }

canvas = sSurface->getCanvas();

This crashes on mac with an abort trap 6 (out of bounds error?). However, if I create the glfw window in the c++ layer, then the window seems to work again. As a separate test I tried drawing into the python-glfw window, using opengl functions from the c++ layer, and this also seems to work. I am really confused, it seems like the the c++ skia functions cant use the right glfw-opengl context? Any pointers would be greatly appreciated, thanks!

*** I also tried adding this before using skia functions, but did not work:

GLFWwindow * window = glfwGetCurrentContext();
glfwMakeContextCurrent(window);

Is there a reason why you’re using Python for GLFW but C++ for Skia? There are Python bindings for Skia: skia-python — skia-python 87.5 documentation

Is the Python GLFW library setting the window hints for the OpenGL version appropriately for macOS? Check the FAQ for macOS: FAQ | GLFW