Unhandled exception on using Button::Ptr

Started by desocupado, 10 October 2015, 06:21:12

desocupado

Hi. I'm trying to put some buttons on screen. I'm getting an unhandled exception:

"Unhandled exception at 0x72EE2B2B (sfml-system-d-2.dll) in blue.exe: 0xC0000005: Access violation reading location 0x00000238."

Bellow is my code. The offending line is "new_game_button->setText("New Game");" But if I delete this line, the next line that uses the new_game_button pointer gives me the same exception. If I just create the button and don't modify it, just call gui.add(new_game_button), it crashes during runtime.

int main()
{
sf::RenderWindow window(sf::VideoMode(1280, 720), "SFML works!");

tgui::Gui gui(window);
gui.setFont("DejaVuSans.ttf");

tgui::Button::Ptr new_game_button;
new_game_button->setText("New Game");
new_game_button->setPosition(1000, 200);
new_game_button->setSize(50, 50);
gui.add(new_game_button);

while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}

window.clear();
gui.draw();
window.display();
}
return 0;
}


desocupado

I did. Everything is set up correctly. tgui-d.lib for the debug mode and tgui.lib for the release mode. Same for the sfml files. I'm linking dynamically, I'm using VS2015, and I downloaded the precompiled libraries for VS2015 32-bit.

texus

Most errors like these are caused by wrong settings so I honestly didn't even look at your code earlier.

Quote
Code (cpp) Select
tgui::Button::Ptr new_game_button;
new_game_button will be a nullptr here. It should be
Code (cpp) Select
tgui::Button::Ptr new_game_button = std::make_shared<tgui::Button>();

But an "Unhandled exception" coming from inside sfml is a strange error for this scenario. A nullptr is not really the first thing that you would think about.

desocupado

Derp. Such a silly mistake. Well, sorry for that, and thanks for your time and attention.