Unhandled exception on using Button::Ptr
« on: 10 October 2015, 06:21:12 »
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.

Code: [Select]
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;
}

*

texus

  • *****
  • 1161
    • View Profile
    • Texus's Blog
Re: Unhandled exception on using Button::Ptr
« Reply #1 on: 10 October 2015, 12:00:22 »

Re: Unhandled exception on using Button::Ptr
« Reply #2 on: 10 October 2015, 15:49:25 »
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

  • *****
  • 1161
    • View Profile
    • Texus's Blog
Re: Unhandled exception on using Button::Ptr
« Reply #3 on: 10 October 2015, 15:54:19 »
Most errors like these are caused by wrong settings so I honestly didn't even look at your code earlier.

Quote
tgui::Button::Ptr new_game_button;
new_game_button will be a nullptr here. It should be
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.

Re: Unhandled exception on using Button::Ptr
« Reply #4 on: 10 October 2015, 16:20:17 »
Derp. Such a silly mistake. Well, sorry for that, and thanks for your time and attention.