Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [Solved] Pointer to sf::Text crashes when drawing to window  (Read 4507 times)

0 Members and 1 Guest are viewing this topic.

deviouskoopa

  • Newbie
  • *
  • Posts: 6
    • View Profile
I'm having a strange issue with my SFML project. When I create a pointer for a sf::Text then draw it to the window in the same function scope, it works. However, when I create the sf::Text and store in a class in one function then draw from that member variable, it breaks in Debug mode with the message: "Unhandled exception at 0x77cc15de in TestSfmlApp.exe: 0xC0000005: Access violation reading location 0xccccccd0." Below is my project info and a condensed test program that fails for me.

System Info:
SFML 2.0 for "Visual C++ 10 (2010) - 32 bits"
Windows 7 64-bit, VS 2010

VS 2010 settings:
dynamic libs according to http://sfml-dev.org/tutorials/2.0/start-vc.php

Test program that crashes at line 42:
http://pastebin.com/L2XQeCdU
(but works when I remove lines 29-31 and 65)

Not sure if I copied the right stuff, but here's the call stack:
    ntdll.dll!77cc15de()    
    [Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll]   
    ntdll.dll!77cc15de()    
    ntdll.dll!77cb014e()    
    sfml-graphics-d-2.dll!5b80ad77()    
    sfml-graphics-d-2.dll!5b80cd56()    
    sfml-graphics-d-2.dll!5b80abae()    
    sfml-graphics-d-2.dll!5b80869a()    
    sfml-graphics-d-2.dll!5b805b2d()    
    sfml-graphics-d-2.dll!5b852986()    
    sfml-graphics-d-2.dll!5b8346e3()    
>   TestSfmlApp.exe!Game::Loop()  Line 42 + 0x1a bytes   C++
    TestSfmlApp.exe!main(int argc, char * * argv)  Line 66   C++
    TestSfmlApp.exe!__tmainCRTStartup()  Line 555 + 0x19 bytes   C
    TestSfmlApp.exe!mainCRTStartup()  Line 371   C
    kernel32.dll!770333aa()    
    ntdll.dll!77cd9ef2()    
    ntdll.dll!77cd9ec5()    


I've been stuck on this for 3-4 days now, but haven't found anything on forums or tutorials. Everything I read suggests the VS 2010 settings are wrong for linking the libraries, but I followed that link above exactly. Any suggestions?
« Last Edit: June 29, 2013, 06:15:07 pm by deviouskoopa »

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Pointer to sf::Text crashes when drawing to window
« Reply #1 on: June 29, 2013, 12:16:42 am »
sf::Font at line 19 is local to start so it dies after quitting that function's scope.
Back to C++ gamedev with SFML in May 2023

deviouskoopa

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Pointer to sf::Text crashes when drawing to window
« Reply #2 on: June 29, 2013, 06:14:36 pm »
Wow that was definitely it, thank you! Can't believe it was that easy...

deviouskoopa

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: [Solved] Pointer to sf::Text crashes when drawing to window
« Reply #3 on: June 29, 2013, 09:53:44 pm »
Just curious:
Is there a good reason that the sf::Text class stores a reference to the sf::Font instead of a sf::Font itself? Then you could copy from the reference in the setFont() function and wouldn't have to manage the lifecycle of the sf::Font separately... but maybe that's the intended use.

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: [Solved] Pointer to sf::Text crashes when drawing to window
« Reply #4 on: June 29, 2013, 10:05:20 pm »
Font instances are very heavy to copy and store.
Back to C++ gamedev with SFML in May 2023

 

anything