2010-01-11 73 views
2

我們有一個在wxWidgets上運行的相當大的跨平臺C++程序。最近,一大塊代碼從windows移植到linux,從那以後,程序在顯示彈出對話框時崩潰。打印到控制檯的錯誤信息是:BadAlloc在wxWidgets程序中崩潰。如何找到錯誤?

The program 'program name' received an X Window System error. 
This probably reflects a bug in the program. 
The error was 'BadAlloc (insufficient resources for operation)'. 
    (Details: serial 12425 error_code 11 request_code 53 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.) 
libxcb: WARNING! Program tries to lock an already locked connection, 
     which indicates a programming error. 
     There will be no further warnings about this issue. 

步進通過與調試器的代碼,違規線似乎是:

wxBitmap* maskBmp = new wxBitmap(iconPath, wxBITMAP_TYPE_BMP); 
wxMask* mask = new wxMask(*maskBmp, wxColour(255, 0, 255)); 

在崩潰的第二行之後。位圖顯示爲正確加載,因爲在工具欄的其他位置使用相同的圖標沒有任何問題。我試圖用「--sync」進行調試,因爲錯誤消息提示,但這似乎沒有多大幫助,因爲gdb似乎無法在gdk_x_error()函數上放置斷點。

有關錯誤可能來自哪裏或至少如何跟蹤它的任何想法?

感謝

更新:請注意,我得到一個日誌Xwindows下的斷言錯誤的,如:

(main:5322): GLib-GObject-CRITICAL **: g_object_unref: assertion `G_IS_OBJECT (object)' failed 

(main:5322): Gdk-CRITICAL **: gdk_drawable_get_image: assertion `GDK_IS_DRAWABLE (drawable)' failed 

(main:5322): Gdk-CRITICAL **: gdk_image_get_colormap: assertion `GDK_IS_IMAGE (image)'failed 

(main:5322): GLib-GObject-CRITICAL **: g_object_unref: assertion `G_IS_OBJECT (object)' failed 

但這似乎發生的時間,即使在程序運作良好!

回答

0

那麼我最終通過使用「--sync」並逐步完成程序來找到它。問題只是提供給wxMask構造函數的路徑。如果給wxBitmap指定了相同的錯誤路徑,它只會彈出一條錯誤消息,但wxMask並不友好。

1

嚴重的GTK警告絕對不是一件好事,並且經常表明存在問題,因此不要以爲您的程序在您看到它們時運行良好。您可以通過在gdb中的g_log函數中放置一個斷點並在到達時查看回溯來調試它們。

而且,如果你能重現崩潰,在一個簡單的例子使用與wxMask一個錯誤的文件,請考慮提交錯誤報告http://trac.wxwidgets.org/