Firstly i trying to initiate SFML and TGUI:
Then i send a reference of TGUI context (gui) to another function where i trying to create main game menu:
But when i push SettingsButton and application trying to render Settings Page i get a Nullptr error. Where my code gone wrong?
Btw, guifactory::checkbox and button methods:
There is the same problem with comboboxes (i'm getting access violation error when trying to add any item), buttons work fine with it. If i add checkboxes and comboboxes as usual, then it works fine.
Compiler VS2015, Dynamically Linked, Prebuild Downloaded Libraries.
Code Select
int main()
{
//Tons of code
Window window;
window.startUp();
window.createWindow();
}
Code Select
void Window::createWindow()
{
sf::RenderWindow window{ { 800, 600 }, "Window" };
window.setFramerateLimit(60);
tgui::Gui gui{ window };
MainMenu menu;
menu.create(gui);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
gui.handleEvent(event);
}
window.clear(sf::Color::White);
gui.draw();
window.display();
}
// Tons of code
}
Then i send a reference of TGUI context (gui) to another function where i trying to create main game menu:
Code Select
void MainMenu::create(tgui::Gui & context)
{
context.removeAllWidgets();
GuiFactory guifactory;
Settings settings;
guifactory.button(context, 20, 4.5, 2.5, 10, "guisettings", "Settings");
tgui::Button::Ptr settingsbutton = context.get<tgui::Button>("Settings");
settingsbutton->connect("pressed", [&]() {
settings.create(context);
});
//Tons of unnecessary code
}
Code Select
void Settings::create(tgui::Gui & context)
{
context.removeAllWidgets();
GuiFactory guifactory;
//Tons of unnecessary code
guifactory.checkbox(context, 20, 1.45, 28.0, 28.0, "settingsvsynccheckbox", "settingsvsynccheckbox", 0, 28);
tgui::CheckBox::Ptr settingsvsynccheckbox = context.get<tgui::CheckBox>("settingsvsynccheckbox");
if (getSettingBool("Fullscreen") == true) {
settingsvsynccheckbox->check();
}
else {
settingsvsynccheckbox->uncheck();
}
//Tons of unnecessary code
}
But when i push SettingsButton and application trying to render Settings Page i get a Nullptr error. Where my code gone wrong?
Btw, guifactory::checkbox and button methods:
Quotevoid GuiFactory::checkbox(tgui::Gui & context, double xpos, double ypos, double xsize, double ysize, std::string text, std::string indentifier, int type, int size)
{
auto windowWidth = tgui::bindWidth(context);
auto windowHeight = tgui::bindHeight(context);
Localization localization;
auto checkbox = std::make_shared<tgui::CheckBox>();
checkbox->setSize(xsize, ysize);
checkbox->setText(localization.wtext(text));
checkbox->setTextSize(size);
if (type == 1) {
checkbox->setPosition(xpos, ypos);
}
else {
checkbox->setPosition(windowWidth / xpos, windowHeight / ypos);
}
context.add(checkbox);
}
Code Select
void GuiFactory::button(tgui::Gui& context, double xpos, double ypos, double xsize, double ysize, std::string text, std::string indentifier)
{
Localization localization;
auto windowWidth = tgui::bindWidth(context);
auto windowHeight = tgui::bindHeight(context);
auto Button = std::make_shared<tgui::Button>();
Button->setPosition(windowWidth / xpos, windowHeight / ypos);
Button->setSize(windowWidth / xsize, windowHeight / ysize);
Button->setText(localization.wtext(text));
Button->setTextSize(34);
context.add(Button, indentifier);
}
There is the same problem with comboboxes (i'm getting access violation error when trying to add any item), buttons work fine with it. If i add checkboxes and comboboxes as usual, then it works fine.
Compiler VS2015, Dynamically Linked, Prebuild Downloaded Libraries.