NSView * from wxPython [英] NSView* from wxPython

查看:212
本文介绍了NSView * from wxPython的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个Python模块,需要获得一个NSView的指针,以便将OpenGL附加到一个窗口。

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

我使用wxPython作为GUI库中有一个方法GetHandle(),如文档所述,'返回物理窗口的平台特定句柄(作为一个长整数)。

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'.

因为我的模块必须兼容Windows和Mac,我做了一个包装函数,它接受一个无符号长,并将其转换为void *,以便将其传递给处理OpenGL创建的实际方法。

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));
}

在Windows上一切正常,但在Mac上, * / NSView *,然后使用NSView *,调试器给我一个EXC_BAD_ACCESS错误。

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.

这是我把一个NSView * p>

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
}

我真的不知道if问题是在我首先从unsigned long到void *然后从void *到NSView *,或者如果问题是在其他地方。

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.

wxPython的版本我使用的是基于Cocoa的,所以我应该从GetHandle()得到一个NSView的指针。

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

推荐答案

找到解决方案。问题是在我的转换从长到void *并回到NSView *。

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

直接从long投射到NSView *工作正常。

Casting directly from long to NSView* works fine.

这篇关于NSView * from wxPython的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆