I'm trying to create a GUI for my program. Im using Edit Boxes to input RGB values to change the colour of a button as a rudimentary colour picker, however when trying to access any methods from the IGUIEditBox, I get a segfault. Im not sure why this is the case as it should be accessible (it is in the same class).
The header of the class contains a struct in which all the elements are kept:
Code: Select all
#pragma once
#include <irrlicht.h>
#include "Structs.h"
#include <vector>
#include <string>
class GuiHandler
{
public:
GuiHandler(Structs::SAppContext *contIN);
bool GuiEvent(const irr::SEvent& eventType);
~GuiHandler();
struct RGBPicker
{
IGUIButton* sample;
IGUIStaticText* RGB[3];
IGUIEditBox* RGBValues[3];
int Colour[3];
};
RGBPicker bottomColour;
RGBPicker topColour;
protected:
void setSkinTransparency(s32 alpha, irr::gui::IGUISkin * skin);
Structs::SAppContext *context;
std::vector<IGUIButton*> buttons;
std::vector<IGUIListBox*> listboxes;
std::vector<IGUIComboBox*> comboBoxes;
std::vector<IGUIStaticText*> labels;
std::vector<IGUIEditBox*> RGBControls;
int selectedChannel = 0;
private:
bool isNumeric(std::string str);
};
Code: Select all
bool GuiHandler::GuiEvent(const irr::SEvent& event)
{
s32 id = event.GUIEvent.Caller->getID();
if (event.GUIEvent.EventType == EGET_EDITBOX_CHANGED)
{
switch (id)
{
case 113:
irr::core::stringc text = event.GUIEvent.Caller->getText();
if (text == L"")
{
text = L"0";
event.GUIEvent.Caller->setText(L"0");
}
std::string ctxt = text.c_str(); //cast irrlicht string into a c++ string for easier analysis
if (isNumeric(ctxt))
{
int val = atoi(ctxt.c_str());
if (val > 255) //limit to RGB values
{
val = 255;
event.GUIEvent.Caller->setText(L"255");
}
//update colourpicker
for (int i = 0;i<3;i++)
{
irr::core::stringc bottomText = bottomColour.RGBValues[i]->getText();
std::string bottomTextC = bottomText.c_str();
bottomColour.Colour[i] = atoi(bottomTextC.data());
std::cout<< bottomColour.Colour[i]<<std::endl;
}
}
else
{
event.GUIEvent.Caller->setText(L"0");
}
break;
}
}
}
Thanks for the Help,
Dom