Chinaunix

标题: [已解]运行中修改控件前景色,程序不定时终止问题 [打印本页]

作者: 凌彬严    时间: 2010-08-13 20:12
标题: [已解]运行中修改控件前景色,程序不定时终止问题
本帖最后由 凌彬严 于 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

请高手指点问题所在!谢谢!
作者: 凌彬严    时间: 2010-08-14 19:17
找到问题所在了,因为是多线程,在使用GTK对象时忘了使用GDK_THREADS_ENTER和GDK_THREADS_LEAVE.这样就正常了:

...
gdk_threads_enter();
gtk_widget_modify_fg(Label_timer,GTK_STATE_NORMAL,&color1);  
gdk_threads_leave();
...




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2