FLTK library and segmentation faults
Hiya, I am making a very simple app using the FLTK library, a dice
roller, thing is when I try to put text into the text output box I get
a segmentation fault, and I have never even heard of these, whats up
with my code? Any help is muchly appreciated. Heres my code:
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <Fl/Fl_Value_Input.H>
#include <Fl/Fl_Button.H>
#include <Fl/Fl_Text_Display.H>
#include <Fl/fl_ask.H>
using namespace std;
//=====Start Window Class=====
class Window: public Fl_Window
{
public:
Window(int w, int h, const char* title);
~Window();
//widget pointers
Fl_Value_Input* Number;
Fl_Value_Input* Sides;
Fl_Value_Input* Coins;
Fl_Button* Roll;
Fl_Button* Flip;
Fl_Text_Display* Output;
private:
//callback functions
static void cb_roll(Fl_Button*, void*);
void cb_roll_i(Fl_Button*, void*);
};
Window::Window(int w, int h, const char* title): Fl_Window(w, h, title)
{
//Interface
Fl_Value_Input* Number =
new Fl_Value_Input(120, 20, 100, 20, "Number of die");
Fl_Value_Input* Sides =
new Fl_Value_Input(120, 60, 100, 20, "Number of sides");
Fl_Value_Input* Coins =
new Fl_Value_Input(120, 100, 100, 20, "Number Of Coins");
Fl_Button* Roll =
new Fl_Button(240, 40, 100, 20, "Roll Dice");
Fl_Button* Flip =
new Fl_Button(240, 100, 100, 20, "Flip Coins");
Fl_Text_Display* Output =
new Fl_Text_Display(10, 140, 330, 250, "");
//Callbacks
Roll->callback((Fl_Callback*) cb_roll, this);
}
Window::~Window()
{
//do nothing deconstructor
}
void Window::cb_roll(Fl_Button* o, void* v)
{
Window* T=(Window*)v;
T->cb_roll_i(o,v);
}
void Window::cb_roll_i(Fl_Button*, void*)
{
Output->insert("Test");
}
//=====End Window Class=====
int main(int argc, char* argv[])
{
Window main(350, 400, "Dice Roller");
main.show();
return Fl::run();
}
roller, thing is when I try to put text into the text output box I get
a segmentation fault, and I have never even heard of these, whats up
with my code? Any help is muchly appreciated. Heres my code:
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <Fl/Fl_Value_Input.H>
#include <Fl/Fl_Button.H>
#include <Fl/Fl_Text_Display.H>
#include <Fl/fl_ask.H>
using namespace std;
//=====Start Window Class=====
class Window: public Fl_Window
{
public:
Window(int w, int h, const char* title);
~Window();
//widget pointers
Fl_Value_Input* Number;
Fl_Value_Input* Sides;
Fl_Value_Input* Coins;
Fl_Button* Roll;
Fl_Button* Flip;
Fl_Text_Display* Output;
private:
//callback functions
static void cb_roll(Fl_Button*, void*);
void cb_roll_i(Fl_Button*, void*);
};
Window::Window(int w, int h, const char* title): Fl_Window(w, h, title)
{
//Interface
Fl_Value_Input* Number =
new Fl_Value_Input(120, 20, 100, 20, "Number of die");
Fl_Value_Input* Sides =
new Fl_Value_Input(120, 60, 100, 20, "Number of sides");
Fl_Value_Input* Coins =
new Fl_Value_Input(120, 100, 100, 20, "Number Of Coins");
Fl_Button* Roll =
new Fl_Button(240, 40, 100, 20, "Roll Dice");
Fl_Button* Flip =
new Fl_Button(240, 100, 100, 20, "Flip Coins");
Fl_Text_Display* Output =
new Fl_Text_Display(10, 140, 330, 250, "");
//Callbacks
Roll->callback((Fl_Callback*) cb_roll, this);
}
Window::~Window()
{
//do nothing deconstructor
}
void Window::cb_roll(Fl_Button* o, void* v)
{
Window* T=(Window*)v;
T->cb_roll_i(o,v);
}
void Window::cb_roll_i(Fl_Button*, void*)
{
Output->insert("Test");
}
//=====End Window Class=====
int main(int argc, char* argv[])
{
Window main(350, 400, "Dice Roller");
main.show();
return Fl::run();
}
