2013-05-16 83 views
2

對不起,我的英語不好。
*的Mac OS X 10.8.3
* XQuartz 2.7.4
* GTK + 3.4.4
gtk +在調用任何開羅繪圖功能時崩潰

我對這篇文章https://developer.gnome.org/gtk3/stable/gtk-getting-started.html

我的環境下學習的GTK + 3作爲的 「HelloWorld」 *的i686-蘋果darwin11-LLVM-GCC-4.2

一切正常之前,我試圖調用此函數作爲繪製的信號處理程序:

 
static gboolean configure_event_cb(GtkWidget* widget,GdkEventConfigure* event,gpointer data) 
{ 

    if(surface) cairo_surface_destroy(surface); 

    surface = gdk_window_create_similar_surface(gtk_widget_get_window(widget), 
               CAIRO_CONTENT_COLOR, 
               gtk_widget_get_allocated_width(widget), 
               gtk_widget_get_allocated_height(widget)); 

    //非對象類型.看做普通的struct. cairo看做類似Graphics的靜態類. 
    cairo_t* cr = cairo_create(surface); 

    cairo_set_source_rgb(cr, 1.0, 1.0, 1.0); 

    cairo_paint(cr); 

    cairo_destroy(cr); 

    return TRUE; 
} 

程序在其他函數中始終在「cairo_paint(cr)」或「cairo_fill」行上崩潰。這裏是調用堆棧:

 
libcairo.2.dylib`_cairo_default_context_in_clip: 
0x100a71ff5: pushq %rbp 
0x100a71ff6: movq %rsp, %rbp 
0x100a71ff9: pushq %rbx 
0x100a71ffa: pushq %rax 
0x100a71ffb: movq %rsi, %rbx 
0x100a71ffe: movq 40(%rdi), %rdi 
0x100a72002: callq 0x100a761c1    ; _cairo_gstate_in_clip 
0x100a72007: movl %eax, (%rbx) 
0x100a72009: xorl %eax, %eax 
0x100a7200b: addq $8, %rsp 
0x100a7200f: popq %rbx 
0x100a72010: popq %rbp 
0x100a72011: ret  

有人能幫助我嗎?

回答

0

我找到了答案。

實際的問題是,開羅庫在運行時並未加載。線索是,Xcode中向我展示了以下味精當我試圖得出一些與開羅:
錯誤:地址不包含一個指向部分在目標文件

所以我改變了我的gcc節命令通過添加-L在/ usr/local/lib目錄-lcairo

/usr/bin/gcc -Wall ./*.c -L/usr/local/lib -lcairo pkg-config --cflags --libs gtk+-3.0

這樣做了以後,它不會再崩潰。 Howerver,我不知道哪種類型的庫實際鏈接到可執行文件,共享庫或靜態庫?爲什麼它沒有在運行時加載該庫?

1

我懷疑由於致電cairo_surface_destroy而導致內存損壞。你在哪裏申報surface?你打電話給cairo_surface_destroy之前在哪裏設置它?你確定它指向一個引用計數> 0的有效表面對象嗎?

我想嘗試評論,看看你是否仍然崩潰。你可能會有一些內存泄漏來修復,但至少你會知道這是否是問題所在。

+0

謝謝@gcbenison。我將表面變量聲明爲靜態全局,就像教程所做的一樣。即使我在教程中編寫了所有原始代碼以進行測試,它也崩潰了。破壞函數似乎不成問題:-(。 – Nozama