BadAlloc和wxWidgets程序崩溃。如何找到错误?

时间:2010-01-11 11:12:11

标签: linux debugging wxwidgets x11

我们在wxWidgets上运行了一个相当大的跨平台C ++程序。最近有大量的代码从windows移植到linux,从那时起,程序在弹出对话框的显示时崩溃。打印到控制台的错误消息是:

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

但这似乎总是发生,即使程序运作良好!

2 个答案:

答案 0 :(得分:1)

严重的GTK警告绝对不是一件好事,并且通常表明存在问题所以不要认为你的程序在看到它们时运行良好。您可以通过在gdb中的g_log函数上放置一个断点并在到达那里时查看回溯来调试它们。

此外,如果您可以在一个简单的示例中使用wxMask使用错误的文件重现崩溃,请考虑向http://trac.wxwidgets.org/提交错误报告

答案 1 :(得分:0)

好吧,我最终通过使用“--sync”并逐步完成程序来找到它。问题只是给wxMask构造函数的路径。如果为wxBitmap提供了相同的错误路径,它只会弹出一条错误消息,但是wxMask并不友好。