0

I am using CodeLite to create a Fltk project.Everthing seems fine but when I press F5 to debug it,it always crashed with a "Program Received signal SIGSEGV" tips. Here is the call stack:

0 0x00401c66 Fl_Widget::Fl_Widget(int, int, int, int, char const*)
1 0x0040a6b1 Fl_Group::Fl_Group(int, int, int, int, char const*)
2 0x004097bf Fl_Window::Fl_Window(int, int, char const*) 3 0x00401415 main

I am sure the code have no problems because i had made it successfully by using CodeBlocks;

#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Button.H>
using namespace std;

//--------------------------------------------
void but_cb( Fl_Widget* o, void*  ) {
Fl_Button* b=(Fl_Button*)o;
b->label("Good job"); //redraw not necessary

b->resize(10,150,140,30); //redraw needed
b->redraw();
}

//--------------------------------------------  
int main() {
Fl_Window win( 300,200,"Testing" );
win.begin();
   Fl_Button but( 10, 150, 70, 30, "Click me" );
win.end();
but.callback( but_cb );
win.show();
return Fl::run();
}

the build log,maybe useful:

C:\windows\system32\cmd.exe /c "mingw32-make.exe -j 4 -e -f "CL_TESL_wsp.mk"" ----------Building project:[ HelloFltk - Debug ]----------" mingw32-make.exe[1]: Entering directoryG:/CPP/CL_TESL/HelloFltk' g++ -o ./Debug/HelloFltk @"HelloFltk.txt" -L. -LG:/MinGW-4.7.1/lib/ -LG:/FLTK/fltk- 1.3.2/lib/ -LG:/FLTK/fltk-1.3.2/ -LG:/MinGW-4.7.1/lib/ -lgdi32 -lfltk -lfltk_forms -lfltk_gl -lfltk_images -lfltk_z -lgdi32 -lole32 -luuid -luser32 -lcomctl32 mingw32-make.exe[1]: Leaving directoryG:/CPP/CL_TESL/HelloFltk' 0 errors, 0 warnings

A new situation!! Today I update my CodeBlocks to the newest version,and it occurs the same problem.I think it is relavent to the version of MinGW...I remake the FLTK by using new version of MinGW,doesn't work either... So I have to change the CodeLite's MinGW path to the old one,and it works...Why couldnt I use the newest version?

1 Answers1

0

I suspect that you tried to follow this tutorial:

http://www3.telus.net/public/robark/#labels

At the bottom of that link it explains why the example you tried is not good:

This program has a BIG problem. Click on the button. Then try forcing a redraw by moving the window or minimize/restore. Notice the garbage the label displays! FLTK is trying to deference a pointer which no longer exists. NOT GOOD

I did not try it myself, by the same tutorial offers a fix:

If we change the line in the callback function from o->label(newcap);

to

o->copy_label(newcap);

Good luck, Eran

Eran
  • 2,310
  • 1
  • 13
  • 13
  • now I copy code from the fltk.org,but the problem is still remain unsolved. "int main(int argc, char **argv) { Fl_Window *window = new Fl_Window(340,180); Fl_Box *box = new Fl_Box(20,40,300,100,"Hello, World!"); box->box(FL_UP_BOX); box->labelfont(FL_BOLD+FL_ITALIC); box->labelsize(36); box->labeltype(FL_SHADOW_LABEL); window->end(); window->show(argc, argv); return Fl::run(); } " It always crashed in the construction of the Fl_Widget – user2002732 May 01 '13 at 02:26