【问题标题】:FLTK draw pixmap gives segfaultFLTK 绘制像素图给出了段错误
【发布时间】:2012-06-15 02:50:42
【问题描述】:

我正在尝试使用 FLTK 在 C++ 程序中绘制 xpm 文件。

这是代码

#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include "image.xpm"
#include <FL/Fl_Pixmap.H>
#include <FL/fl_draw.H>
#include <FL/Fl_Image.H>
int main(int argc, char ** argv)
{
  Fl_Window *window = new Fl_Window(800,650);
  Fl_Pixmap pix(XFACE);
  pix.draw(200,200);
  window->end();
  window->show(argc,argv);
  return Fl::run();
}

XFACE 是“image.xpm”中的有效 xpm 对象

但我在 pix.draw() 行遇到分段错误。
这是什么原因造成的?

【问题讨论】:

  • 一切?没有?老实说,目前还无法回答你的问题。至少编辑您的问题以包含XPM,或至少包含XPM 的开头和结尾。
  • 请写一个 SSCCE (sscce.org) 或者至少在某个包含完整错误输出的地方进行网络粘贴...我的第一个猜测是 - 你要么没有有效的 FLTK 上下文,所以Fl_Pixmap 不知道自己渲染到哪里,或者 XPM 无效...

标签: c++ linux fltk


【解决方案1】:
/* Try this - this works for me, and I guess is what you meant! */

#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Pixmap.H>

#include "image.xpm"

int main(int argc, char ** argv)
{
    Fl_Window *window = new Fl_Window(800,650);
    Fl_Box *image_box = new Fl_Box(5, 5, 790, 640);
    Fl_Pixmap pix(XFACE);
    window->end();
    image_box->image(pix);
    window->show(argc,argv);
    return Fl::run();
}

/* end of file */

【讨论】:

    【解决方案2】:

    说实话,这甚至不像是有效的 fltk 代码;您正在直接调用 draw() 方法,而 AFAIK 在 fltk 中很少有效。

    您可能想在他们的邮件列表中询问 - 他们的响应速度非常快。

    另外,您是否查看了 tarball 的“测试”文件夹中的像素图演示 - 看看它做了什么,然后复制它!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多