[已解]运行中修改控件前景色,程序不定时终止问题
时间:2010-08-13
来源:互联网
本帖最后由 凌彬严 于 2010-08-14 19:18 编辑
gpointer
timer_thread(gpointer data)
{
gint i;
while(1)
{
for(i=13;i>=0;i--)
{
label_put(i);//将计时值输出label
if(i==13)
{
Run=TRUE;
g_cond_broadcast(Cond_animation[0]);
}
else if(i==3)
{
Run=FALSE;
//gtk_widget_modify_fg(Label_timer,GTK_STATE_NORMAL,&color1); 倒计时三秒,改变label文本显示顔色
}
sleep(1);
}
//gtk_widget_modify_fg(Label_timer,GTK_STATE_NORMAL,&color2); 重新计时恢复label文本显示顔色
}
}
问题:如果启用以上两个运行过程中修改LABEL前景色的两行代码,程序在正常运行一段后,不定时的出错终止程序,而且错误提示还不固定,如下:
错误一:
(client:3530): Gdk-CRITICAL **: gdk_gc_set_clip_rectangle: assertion `GDK_IS_GC (gc)' failed
(client:3530): Gdk-CRITICAL **: gdk_draw_layout: assertion `PANGO_IS_LAYOUT (layout)' failed
Gdk-ERROR **: The program 'client' received an X Window System error.
This probably reflects a bug in the program.
The error was 'BadLength (poly request too large or internal Xlib length erro'.
(Details: serial 158882 error_code 16 request_code 60 minor_code 0)
(Note to programmers: normally, X errors are reported asynchronously;
that is, you will receive the error a while after causing it.
To debug your program, run it with the --sync command line
option to change this behavior. You can then get a meaningful
backtrace from your debugger if you break on the gdk_x_error() function.)
aborting...
已放弃 (core dumped)
错误二:
(client:3575): GLib-GObject-CRITICAL **: g_object_ref: assertion `object->ref_count > 0' failed
(client:3575): Pango-WARNING **: shaping failure, expect ugly output. shape-engine='BasicEngineFc', font='DejaVu Sans 9.9990234375', text=''
(client:3575): Pango-CRITICAL **: pango_layout_get_text: assertion `PANGO_IS_LAYOUT (layout)' failed
(client:3575): GLib-GObject-CRITICAL **: g_object_unref: assertion `G_IS_OBJECT (object)' failed
请高手指点问题所在!谢谢!
gpointer
timer_thread(gpointer data)
{
gint i;
while(1)
{
for(i=13;i>=0;i--)
{
label_put(i);//将计时值输出label
if(i==13)
{
Run=TRUE;
g_cond_broadcast(Cond_animation[0]);
}
else if(i==3)
{
Run=FALSE;
//gtk_widget_modify_fg(Label_timer,GTK_STATE_NORMAL,&color1); 倒计时三秒,改变label文本显示顔色
}
sleep(1);
}
//gtk_widget_modify_fg(Label_timer,GTK_STATE_NORMAL,&color2); 重新计时恢复label文本显示顔色
}
}
问题:如果启用以上两个运行过程中修改LABEL前景色的两行代码,程序在正常运行一段后,不定时的出错终止程序,而且错误提示还不固定,如下:
错误一:
(client:3530): Gdk-CRITICAL **: gdk_gc_set_clip_rectangle: assertion `GDK_IS_GC (gc)' failed
(client:3530): Gdk-CRITICAL **: gdk_draw_layout: assertion `PANGO_IS_LAYOUT (layout)' failed
Gdk-ERROR **: The program 'client' received an X Window System error.
This probably reflects a bug in the program.
The error was 'BadLength (poly request too large or internal Xlib length erro'.
(Details: serial 158882 error_code 16 request_code 60 minor_code 0)
(Note to programmers: normally, X errors are reported asynchronously;
that is, you will receive the error a while after causing it.
To debug your program, run it with the --sync command line
option to change this behavior. You can then get a meaningful
backtrace from your debugger if you break on the gdk_x_error() function.)
aborting...
已放弃 (core dumped)
错误二:
(client:3575): GLib-GObject-CRITICAL **: g_object_ref: assertion `object->ref_count > 0' failed
(client:3575): Pango-WARNING **: shaping failure, expect ugly output. shape-engine='BasicEngineFc', font='DejaVu Sans 9.9990234375', text=''
(client:3575): Pango-CRITICAL **: pango_layout_get_text: assertion `PANGO_IS_LAYOUT (layout)' failed
(client:3575): GLib-GObject-CRITICAL **: g_object_unref: assertion `G_IS_OBJECT (object)' failed
请高手指点问题所在!谢谢!
作者: 凌彬严 发布时间: 2010-08-13
找到问题所在了,因为是多线程,在使用GTK对象时忘了使用GDK_THREADS_ENTER和GDK_THREADS_LEAVE.这样就正常了:
...
gdk_threads_enter();
gtk_widget_modify_fg(Label_timer,GTK_STATE_NORMAL,&color1);
gdk_threads_leave();
...
...
gdk_threads_enter();
gtk_widget_modify_fg(Label_timer,GTK_STATE_NORMAL,&color1);
gdk_threads_leave();
...
作者: 凌彬严 发布时间: 2010-08-14
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28