How to get ptr properly?

  • 11 Replies
  • 64 Views
How to get ptr properly?
« on: 22 August 2017, 17:56:23 »
Firstly i trying to initiate SFML and TGUI:
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 method:
Quote
void 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.

How to get ptr properly?
« Reply #1 on: 22 August 2017, 17:56:46 »
Firstly i trying to initiate SFML and TGUI:
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 method:
Quote
void 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.

How to get ptr
« Reply #2 on: 22 August 2017, 17:59:24 »
Firstly i trying to initiate SFML and TGUI:
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 method:
Quote
void 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.

How to get ptr properly
« Reply #3 on: 22 August 2017, 18:08:26 »
Firstly i trying to initiate SFML and TGUI:
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:
Quote
void 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 (not using guifactory class), then it works fine.

Compiler VS2015, Dynamically Linked, Prebuild Downloaded Libraries.

How to get ptr properly
« Reply #4 on: 22 August 2017, 18:09:07 »
Firstly i trying to initiate SFML and TGUI:
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:
Quote
void 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 (not using guifactory class), then it works fine.

Compiler VS2015, Dynamically Linked, Prebuild Downloaded Libraries.

How to get ptr properly?
« Reply #5 on: 22 August 2017, 18:11:44 »
Firstly i trying to initiate SFML and TGUI:
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:
Quote
void 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 (not using guifactory class), then it works fine.

Compiler VS2015, Dynamically Linked, Prebuild Downloaded Libraries.

*

texus

  • *****
  • 1411
    • View Profile
    • Texus's Blog
test
« Reply #6 on: 22 August 2017, 18:16:42 »
test

*

texus

  • *****
  • 1411
    • View Profile
    • Texus's Blog
test
« Reply #7 on: 22 August 2017, 18:22:13 »
x

*

texus

  • *****
  • 1411
    • View Profile
    • Texus's Blog
test
« Reply #8 on: 22 August 2017, 18:24:53 »
x

*

texus

  • *****
  • 1411
    • View Profile
    • Texus's Blog
test
« Reply #9 on: 22 August 2017, 18:25:44 »
x

*

texus

  • *****
  • 1411
    • View Profile
    • Texus's Blog
x
« Reply #10 on: 22 August 2017, 18:26:26 »
t

*

texus

  • *****
  • 1411
    • View Profile
    • Texus's Blog
x
« Reply #11 on: 22 August 2017, 18:28:51 »
y