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

Author Topic: program crashes when trying to use new font  (Read 4536 times)

0 Members and 2 Guests are viewing this topic.

BillH

  • Newbie
  • *
  • Posts: 12
    • View Profile
program crashes when trying to use new font
« on: April 23, 2013, 09:43:24 pm »
Newbie again

I have recently started learning SFML and have managed quite well so far. I have a program which displays a number of circles and a rectangle in a graphics window (I know it's not very exciting). This works perfectly but, when I tried to add a font I get an error: "example.exe has stopped working". If I comment out the references to the new font it runs OK again. I am using VS 2010 with sfml 2.0 rc.

I have included the code I wrote complete with the references to the new font, commented out.

Sorry if this is just another stupid problem but I really am a complete beginner to SFML and I have looked at the documentation and googled the problem with no luck, so any advice is welcome.

Thanks

-----------------------------------------------------------------Code follows-----------------------------------

 
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>



int main()
{
       

        sf::RenderWindow window(sf::VideoMode(1000, 600),"SFML works!");
        window.setPosition(sf::Vector2i(550,100));



/*
         sf::Font fnew;
         if(!fnew.loadFromFile("c:/windows/fonts/comic.ttf"))  
                {
                return 1;
                }
*/





       
       
       

       

 
    sf::CircleShape shape(10.f);//-----------------------------------diameter
    shape.setFillColor(sf::Color::Yellow);
        shape.setPosition(250,350);//-------------------position x,y

        sf::CircleShape shape1(20.f);//-----------------------------------diameter
    shape1.setFillColor(sf::Color::Red);
        shape1.setPosition(350,350);//-------------------position x,y

   sf::CircleShape shape2(30.f);//-----------------------------------diameter
    shape2.setFillColor(sf::Color::Green);
        shape2.setPosition(450,350);//-------------------position x,y

   sf::CircleShape shape3(40.f);//-----------------------------------diameter
    shape3.setFillColor(sf::Color::Yellow);
        shape3.setPosition(550,350);//-------------------position x,y

        sf::RectangleShape rec;

         rec.setSize(sf::Vector2f(800, 150));
         rec.setOutlineColor(sf::Color(255,0,0,150));
         rec.setFillColor(sf::Color(255,255,255,100));
         rec.setOutlineThickness(5);
         rec.setPosition(100, 20);

                sf::Text text("Test of text for graphics window");

                text.setCharacterSize(30);
                text.setColor(sf::Color::Green);
                text.setPosition(150,20);
                text.setRotation(0.f);//rotates text
                text.setScale(1.f,1.f);//changes size

//              text.setFont(fnew);                            


 while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
                       
            if (event.type == sf::Event::Closed)
                window.close();
        }
               
                window.clear(sf::Color::Blue);
                window.draw(shape);
                window.draw(text);
                window.draw(shape1);
                window.draw(shape2);
                window.draw(shape3);
                window.draw(rec);
       

        window.display();
    }

    return 0;
}
 
« Last Edit: April 24, 2013, 02:32:58 pm by BillH »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: program crashes when trying to use new font
« Reply #1 on: April 23, 2013, 10:00:31 pm »
Use your debugger to know where and why it crashes.

And please use the [ code = cpp ] tag to format code blocks on the forum ;)
Laurent Gomila - SFML developer

BillH

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: program crashes when trying to use new font
« Reply #2 on: April 24, 2013, 08:14:58 am »
Hi Laurent. Thanks for your reply. Apologies for not formatting code block correctly.

When I ran the debugger it gave the following output, I don't know if this will help but here goes:

output screen from Debug:

'example2.exe': Loaded 'C:\Users\Bill\Documents\Visual Studio 2010\Projects\example2\Debug\example2.exe', Symbols loaded.
'example2.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll', Cannot find or open the PDB file
'example2.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', Cannot find or open the PDB file
'example2.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll', Cannot find or open the PDB file
'example2.exe': Loaded 'C:\Users\Bill\Documents\Visual Studio 2010\Projects\example2\Debug\sfml-graphics-2.dll', Binary was not built with debug

information.
'example2.exe': Loaded 'C:\Users\Bill\Documents\Visual Studio 2010\Projects\example2\Debug\sfml-window-2.dll', Binary was not built with debug

information.
'example2.exe': Loaded 'C:\Users\Bill\Documents\Visual Studio 2010\Projects\example2\Debug\sfml-system-2.dll', Binary was not built with debug

information.
'example2.exe': Loaded 'C:\Windows\SysWOW64\msvcr100.dll', Symbols loaded.
'example2.exe': Loaded 'C:\Windows\SysWOW64\msvcp100.dll', Symbols loaded.
'example2.exe': Loaded 'C:\Windows\SysWOW64\opengl32.dll', Cannot find or open the PDB file
'example2.exe': Loaded 'C:\Windows\SysWOW64\msvcrt.dll', Cannot find or open the PDB file
'example2.exe': Loaded 'C:\Windows\SysWOW64\advapi32.dll', Cannot find or open the PDB file
'example2.exe': Loaded 'C:\Windows\SysWOW64\sechost.dll', Cannot find or open the PDB file
'example2.exe': Loaded 'C:\Windows\SysWOW64\rpcrt4.dll', Cannot find or open the PDB file
'example2.exe': Loaded 'C:\Windows\SysWOW64\sspicli.dll', Cannot find or open the PDB file
'example2.exe': Loaded 'C:\Windows\SysWOW64\cryptbase.dll', Cannot find or open the PDB file
'example2.exe': Loaded 'C:\Windows\SysWOW64\gdi32.dll', Cannot find or open the PDB file
'example2.exe': Loaded 'C:\Windows\SysWOW64\user32.dll', Cannot find or open the PDB file
'example2.exe': Loaded 'C:\Windows\SysWOW64\lpk.dll', Cannot find or open the PDB file
'example2.exe': Loaded 'C:\Windows\SysWOW64\usp10.dll', Cannot find or open the PDB file
'example2.exe': Loaded 'C:\Windows\SysWOW64\glu32.dll', Cannot find or open the PDB file
'example2.exe': Loaded 'C:\Windows\SysWOW64\ddraw.dll', Cannot find or open the PDB file
'example2.exe': Loaded 'C:\Windows\SysWOW64\dciman32.dll', Cannot find or open the PDB file
'example2.exe': Loaded 'C:\Windows\SysWOW64\setupapi.dll', Cannot find or open the PDB file
'example2.exe': Loaded 'C:\Windows\SysWOW64\cfgmgr32.dll', Cannot find or open the PDB file
'example2.exe': Loaded 'C:\Windows\SysWOW64\oleaut32.dll', Cannot find or open the PDB file
'example2.exe': Loaded 'C:\Windows\SysWOW64\ole32.dll', Cannot find or open the PDB file
'example2.exe': Loaded 'C:\Windows\SysWOW64\devobj.dll', Cannot find or open the PDB file
'example2.exe': Loaded 'C:\Windows\SysWOW64\dwmapi.dll', Cannot find or open the PDB file
'example2.exe': Loaded 'C:\Windows\SysWOW64\winmm.dll', Cannot find or open the PDB file
'example2.exe': Loaded 'C:\Windows\SysWOW64\msvcp100d.dll', Symbols loaded.
'example2.exe': Loaded 'C:\Windows\SysWOW64\msvcr100d.dll', Symbols loaded.
'example2.exe': Loaded 'C:\Windows\SysWOW64\imm32.dll', Cannot find or open the PDB file
'example2.exe': Loaded 'C:\Windows\SysWOW64\msctf.dll', Cannot find or open the PDB file
'example2.exe': Loaded 'C:\Windows\SysWOW64\uxtheme.dll', Cannot find or open the PDB file
'example2.exe': Loaded 'C:\Windows\SysWOW64\ig4icd32.dll', Cannot find or open the PDB file
'example2.exe': Loaded 'C:\Windows\SysWOW64\version.dll', Cannot find or open the PDB file
'example2.exe': Unloaded 'C:\Windows\SysWOW64\version.dll'
'example2.exe': Loaded 'C:\Windows\SysWOW64\dinput.dll', Cannot find or open the PDB file
'example2.exe': Loaded 'C:\Windows\SysWOW64\hid.dll', Cannot find or open the PDB file
'example2.exe': Loaded 'C:\Windows\SysWOW64\wintrust.dll', Cannot find or open the PDB file
'example2.exe': Loaded 'C:\Windows\SysWOW64\crypt32.dll', Cannot find or open the PDB file
'example2.exe': Loaded 'C:\Windows\SysWOW64\msasn1.dll', Cannot find or open the PDB file
'example2.exe': Loaded 'C:\Windows\SysWOW64\clbcatq.dll', Cannot find or open the PDB file
First-chance exception at 0x72621f34 (msvcr100.dll) in example2.exe: 0xC0000005: Access violation reading location 0x023c5000.
Unhandled exception at 0x72621f34 (msvcr100.dll) in example2.exe: 0xC0000005: Access violation reading location 0x023c5000.



Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: program crashes when trying to use new font
« Reply #3 on: April 24, 2013, 08:25:48 am »
Quote
Apologies for not formatting code block correctly.
I would have preferred if you just edited your first post to fix it ;)

Quote
When I ran the debugger it gave the following output, I don't know if this will help
This doesn't help, since this is not a relevant output to watch. You must look at the line in your source code where the debugger points to. You can also display the call stack, in case the crash occurs deeply in system calls.
You should really learn to use the debugger properly. Just with the basics, which are really straight-forward to understand, you'll be able to have much more information when your app crashes. The debugger is not an optional tool that some experts use sometimes, it's really a core element of the programming environment.
Laurent Gomila - SFML developer

BillH

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: program crashes when trying to use new font
« Reply #4 on: April 24, 2013, 01:31:13 pm »
Thanks Laurent,your comments are really appreciated.  I will take note of what you said about using the debugger.

Meanwhile an update: I decided to try linking to the static libraries instead of the dynamic ones and the program compiles and runs with no problems

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: program crashes when trying to use new font
« Reply #5 on: April 24, 2013, 01:54:41 pm »
You still haven't edited your first post to fix the code = cpp tag.
Laurent Gomila - SFML developer

BillH

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: program crashes when trying to use new font
« Reply #6 on: April 27, 2013, 05:10:18 pm »
Just to confirm: when linking to static libraries the problem does NOT occur and it runs perfectly. I have tried it with a number of different fonts. I don't know whether this means there is a problem with sfml dynamic library or something else. by the way Laurent I took your advice and am studying how to use the debugger properly! ;)

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: program crashes when trying to use new font
« Reply #7 on: April 27, 2013, 05:15:26 pm »
Quote
'example2.exe': Loaded 'C:\Users\Bill\Documents\Visual Studio 2010\Projects\example2\Debug\sfml-graphics-2.dll', Binary was not built with debug

information.
'example2.exe': Loaded 'C:\Users\Bill\Documents\Visual Studio 2010\Projects\example2\Debug\sfml-window-2.dll', Binary was not built with debug

information.
'example2.exe': Loaded 'C:\Users\Bill\Documents\Visual Studio 2010\Projects\example2\Debug\sfml-system-2.dll', Binary was not built with debug

information.
In debug you must put -d before .lib in your additional dependencies. So it's
sfml-system-d.lib
sfml-window-d.lib
sfml-graphics-d.lib
Back to C++ gamedev with SFML in May 2023