C、GTK:窗口停止更新

发布于 2024-12-28 20:44:23 字数 670 浏览 6 评论 0原文

我正在开发一个应用程序,它定期在窗口内的 GTK 绘图区域上绘制图像。

渲染首先工作正常,如果我将另一个窗口拖到绘图窗口上,窗口内容会被重新绘制,但经过一段随机时间(几秒钟)后,窗口会停止自行更新。

新图像不会显示,如果我然后将另一个窗口拖动到渲染窗口上,我会得到以下结果:

Window content not update more

当我单击绘图区域下方的复选框之一时,窗口会刷新,问题又消失了几秒钟。

知道什么可以使 GTK 线程停止更新窗口内容吗?

我不知道我的代码的哪一部分有兴趣回答这个问题,所以我粘贴了大部分完整的版本 此处

我的 GTK-main() 是这样调用的:

void window_main()
{
    pthread_create(&drawing_thread, NULL, img_draw, NULL);

    gtk_main();

    gdk_threads_leave();
}

感谢您的任何提示! :)

I'm developing an application that periodically draws images on a GTK Drawing Area inside a window.

The rendering first works well and the window content gets repainted if I drag another window over the drawing one, but after some random amount of time (some seconds), the window stops updating itself.

New images dont get displayed, and if I then drag another window over the rendering one I get this:

Window content not updated anymore

When I click one of the checkboxes below my drawing area, the window gets refreshed and the problem is gone for another few seconds.

Any idea what could make the GTK threads stop updating the window content?

I dont know which part of my code is of interest to answer that question, so I pasted the mostly full version here.

My GTK-main() is called like this:

void window_main()
{
    pthread_create(&drawing_thread, NULL, img_draw, NULL);

    gtk_main();

    gdk_threads_leave();
}

Thanks for any hints! :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

挽袖吟 2025-01-04 20:44:23

找到了解决方案:在我使用的原始示例代码中(此处),他们使用 < code>g_timeout_add() 来注册它们的周期性绘图函数。

g_timeout_add() 注册的函数由 gtk_main() 运行,这意味着它在内部受到 gdk_threads_enter()gdk_threads_leave 的保护()。这就是我没有意识到的一点。

用这两个函数包围我对 gtk_widget_queue_draw_area() 的调用,错误就消失了 8)

Found the solution: in the original example code I used (here) they use a g_timeout_add() to register their periodic drawing function.

The g_timeout_add()-registered function is run by gtk_main(), which means it is protected internally by gdk_threads_enter() and gdk_threads_leave(). That's the point I was not aware of.

Surrounded my call to gtk_widget_queue_draw_area() with these two functions and the bug is gone 8)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文