NSView* from wxPython

对着背影说爱祢 提交于 2019-12-11 04:57:34

问题


I'm developing a Python module that needs to get a pointer to a NSView in order to attach OpenGL to a window.

I'm using wxPython as GUI library that has a method GetHandle() that, as the documentation says, 'Returns the platform-specific handle (as a long integer) of the physical window'.

Because my module has to be compatible with both Windows and Mac, I've made a wrapper function that takes a unsigned long and cast it to a void* in order to pass it to the actual method that handles the OpenGL creation.

void wrap_CreateContext(unsigned long windowId)
{
    return CreateContext((void*)&(windowId));
}

On Windows everything works, but on Mac, when I try to cast the void* to a NSView* and then use that NSView*, the debugger gives me a EXC_BAD_ACCESS error.

This is how I cast the void* to a NSView*:

void CreateContext(void* windowId)
{
    NSView* view = (NSView*)windowId;

    // for example I try to get the view size
    NSSize size = view.frame.size; // <--- EXC_BAD_ACCESS error
}

I really don't know if the problem is in my casting at first from unsigned long to void* and then from void* to NSView*, or if the problem is somewhere else.

The version of wxPython I'm using is build upon Cocoa so I should get a pointer to a NSView from GetHandle().


回答1:


Found the solution. The problem was in my casting from long to void* and back to NSView*.

Casting directly from long to NSView* works fine.



来源:https://stackoverflow.com/questions/31014804/nsview-from-wxpython

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!