wxwidgets和线程 [英] wxwidgets and threads

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

问题描述

在我的应用程序中,我从onThread函数运行wglGetCurrentDC()wglGetCurrentContext() (此函数应按此处声明的方式调用-EVT_THREAD(wxID_ANY,MyCanvas::onThread)) 在这两种情况下我都得到NULL.当我不是从onThread运行它时,就可以了…… 解决该问题的方法是什么-(从线程获取事件时,我必须运行它们!)

In my application I run wglGetCurrentDC() and wglGetCurrentContext() from onThread function (this function should be called as declared here - EVT_THREAD(wxID_ANY,MyCanvas::onThread)) and I get NULL in both cases. When I run it not from onThread it is ok… What is work around in order to solve the problem – (I have to run them when getting event from the thread!)

根据Alex的建议,我更改为wxPostEvent以将事件重定向到主线程,该主线程在其onThread函数中捕获该事件.在此onThread函数中,我具有wglGetCurrentDC()wglGetCurrentContext()调用...它们仍然返回null.请向我解释我做错了.以及如何解决他的问题.

As Alex suggested I changed to wxPostEvent to redirect the event to main thread, which catches the event in its onThread function.In this onThread function I have wglGetCurrentDC() and wglGetCurrentContext() calls ...They still return null.Please explain me what I am doing wrong. And how to solve he problem.

推荐答案

也许我误会了,但是您不应该使用wxGLCanvas和wxGLContext而不是Windows特定的代码吗?至少它可能与其他wxWidget代码更兼容.

Maybe I'm misunderstanding, but should you not be using wxGLCanvas and wxGLContext rather than the windows-specific code? At the very least it's probably more compatible with other wxWidget code.

无论如何,请参见 wglGetCurrentDC文档,如果当前窗口的DC不存在,则该函数返回NULL.这表明上下文要么以某种方式被破坏,要么不是从您认为正在从中调用它的窗口中调用它(也许是因为线程?).我要重申亚历克斯所说的话;不要从主线程之外的任何线程调用UI代码.

Anyway, from the wglGetCurrentDC documentation, the function returns NULL if a DC for the current window doesn't exist. This suggests that either the context was destroyed somehow or you're not calling it from the window you think you're calling it from (perhaps because of your threading?). I would reiterate what Alex said; don't call UI code from any thread besides the main one.

如果您可以发布一些代码来显示您如何从线程中返回,则可能有助于发现问题.似乎您正在从线程中执行UI任务,而只是没有意识到. (不过,很难说没有看到任何代码.)

If you could post some code showing how you're returning from the thread it might help identify the problem. It seems likely that you're doing UI stuff from the thread and just not realizing it. (Hard to tell without seeing any code, though.)

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

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