Main Menu
Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - EpicMan2

#1
Help requests / Re: How to get ptr properly?
22 August 2017, 19:00:35
Quote from: texus on 22 August 2017, 18:47:05
You are passing the settings to the lambda by reference (because of the "&"), but settings is a local object. After the "menu.create(gui);" call, the settings object has been destroyed. When the button is pressed, you will be accessing an object that no longer exists.

But why it doesn't crash when i use only buttons? (For test i have deleted all the checkboxes and comboboxes from Settings::create). For example, one of buttons:
guifactory.button(context, 20, 1.2, 2.5, 10, "guiexit", "Exit");
tgui::Button::Ptr exitbutton = context.get<tgui::Button>("Exit");
exitbutton->connect("pressed", [&]() {
mainmenu.create(context);
});


And can you give me advice how to properly pass TGUI context to other functions?
#2
Help requests / How to get ptr properly?
22 August 2017, 18:37:54
Firstly i trying to initiate SFML and TGUI:
int main()
{
//Tons of code
Window window;
window.startUp();
window.createWindow();
}


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:

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
}


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);
}
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.
#3
Help requests / How to get ptr properly?
22 August 2017, 18:11:44
Firstly i trying to initiate SFML and TGUI:
int main()
{
//Tons of code
Window window;
window.startUp();
window.createWindow();
}


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:

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
}


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);
}
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 (not using guifactory class), then it works fine.

Compiler VS2015, Dynamically Linked, Prebuild Downloaded Libraries.
#4
Help requests / How to get ptr properly
22 August 2017, 18:09:07
Firstly i trying to initiate SFML and TGUI:
int main()
{
//Tons of code
Window window;
window.startUp();
window.createWindow();
}


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:

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
}


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);
}
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 (not using guifactory class), then it works fine.

Compiler VS2015, Dynamically Linked, Prebuild Downloaded Libraries.
#5
Help requests / How to get ptr properly
22 August 2017, 18:08:26
Firstly i trying to initiate SFML and TGUI:
int main()
{
//Tons of code
Window window;
window.startUp();
window.createWindow();
}


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:

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
}


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);
}
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 (not using guifactory class), then it works fine.

Compiler VS2015, Dynamically Linked, Prebuild Downloaded Libraries.
#6
Help requests / How to get ptr
22 August 2017, 17:59:24
Firstly i trying to initiate SFML and TGUI:
int main()
{
//Tons of code
Window window;
window.startUp();
window.createWindow();
}


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:

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
}


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 method:
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);
}
There is the same problem with comboboxes, buttons work fine with it.
#7
Help requests / How to get ptr properly?
22 August 2017, 17:56:46
Firstly i trying to initiate SFML and TGUI:
int main()
{
//Tons of code
Window window;
window.startUp();
window.createWindow();
}


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:

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
}


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 method:
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);
}
There is the same problem with comboboxes, buttons work fine with it.
#8
Help requests / How to get ptr properly?
22 August 2017, 17:56:23
Firstly i trying to initiate SFML and TGUI:
int main()
{
//Tons of code
Window window;
window.startUp();
window.createWindow();
}


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:

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
}


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 method:
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);
}
There is the same problem with comboboxes, buttons work fine with it.