SFML程序有线程错误

时间:2013-10-03 16:03:54

标签: c++ multithreading text fonts sfml

我最近开始使用Library SFML和visual studio 2012 c ++。

一切正常,直到我开始使用自定义字体,然后弹出这些消息并且没有任何效果:

'Graphics test.exe' (Win32): Loaded 'C:\Users\Oliver Bolt\Documents\Visual Studio 2012\Projects\Graphics test\Debug\Graphics test.exe'. Symbols loaded.
'Graphics test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ntdll.dll'. Symbols loaded.
'Graphics test.exe' (Win32): Loaded 'C:\Program Files\AVAST Software\Avast\snxhk.dll'. Cannot find or open the PDB file.
'Graphics test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel32.dll'. Symbols loaded.
'Graphics test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\KernelBase.dll'. Symbols loaded.
'Graphics test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\opengl32.dll'. Symbols loaded.
'Graphics test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcrt.dll'. Symbols loaded.
'Graphics test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\advapi32.dll'. Symbols loaded.
'Graphics test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sechost.dll'. Symbols loaded.
'Graphics test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\rpcrt4.dll'. Symbols loaded.
'Graphics test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sspicli.dll'. Symbols loaded.
'Graphics test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\cryptbase.dll'. Symbols loaded.
'Graphics test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\gdi32.dll'. Symbols loaded.
'Graphics test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\user32.dll'. Symbols loaded.
'Graphics test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\lpk.dll'. Symbols loaded.
'Graphics test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\usp10.dll'. Symbols loaded.
'Graphics test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\glu32.dll'. Symbols loaded.
'Graphics test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ddraw.dll'. Symbols loaded.
'Graphics test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\dciman32.dll'. Symbols loaded.
'Graphics test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\setupapi.dll'. Symbols loaded.
'Graphics test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\cfgmgr32.dll'. Symbols loaded.
'Graphics test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\oleaut32.dll'. Symbols loaded.
'Graphics test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ole32.dll'. Symbols loaded.
'Graphics test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\devobj.dll'. Symbols loaded.
'Graphics test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\dwmapi.dll'. Symbols loaded.
'Graphics test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\winmm.dll'. Symbols loaded.
'Graphics test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcp110d.dll'. Symbols loaded.
'Graphics test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcr110d.dll'. Symbols loaded.
'Graphics test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\imm32.dll'. Symbols loaded.
'Graphics test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msctf.dll'. Symbols loaded.
'Graphics test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\nvinit.dll'. Cannot find or open the PDB file.
'Graphics test.exe' (Win32): Loaded 'C:\Program Files (x86)\NVIDIA Corporation\coprocmanager\_etoured.dll'. Cannot find or open the PDB file.
'Graphics test.exe' (Win32): Loaded 'C:\Program Files (x86)\NVIDIA Corporation\coprocmanager\Nvd3d9wrap.dll'. Cannot find or open the PDB file.
'Graphics test.exe' (Win32): Loaded 'C:\Program Files (x86)\NVIDIA Corporation\coprocmanager\nvdxgiwrap.dll'. Cannot find or open the PDB file.
'Graphics test.exe' (Win32): Loaded 'C:\PROGRA~2\OPTIMI~1\OPTPRO~1.DLL'. Module was built without symbols.
'Graphics test.exe' (Win32): Unloaded 'C:\PROGRA~2\OPTIMI~1\OPTPRO~1.DLL'
'Graphics test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\uxtheme.dll'. Symbols loaded.
'Graphics test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ig7icd32.dll'. Cannot find or open the PDB file.
'Graphics test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\igdusc32.dll'. Cannot find or open the PDB file.
'Graphics test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\version.dll'. Symbols loaded.
'Graphics test.exe' (Win32): Unloaded 'C:\Windows\SysWOW64\version.dll'
'Graphics test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\dinput.dll'. Symbols loaded.
'Graphics test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\hid.dll'. Symbols loaded.
'Graphics test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\wintrust.dll'. Symbols loaded.
'Graphics test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\crypt32.dll'. Symbols loaded.
'Graphics test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msasn1.dll'. Symbols loaded.
'Graphics test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ole32.dll'. Symbols loaded.
'Graphics test.exe' (Win32): Unloaded 'C:\Windows\SysWOW64\ole32.dll'
The thread 0xed8 has exited with code 0 (0x0).
The thread 0x131c has exited with code 0 (0x0).
The thread 0x105c has exited with code 0 (0x0).
The thread 0x19e8 has exited with code 0 (0x0).
The thread 0xeb4 has exited with code 0 (0x0).
The thread 0x187c has exited with code 0 (0x0).
The thread 0x1c78 has exited with code 0 (0x0).
The thread 0x480 has exited with code 0 (0x0).
The thread 0x1244 has exited with code 0 (0x0).
The program '[4124] Graphics test.exe' has exited with code 0 (0x0).

导致这些错误的程序:

#include <SFML\System.hpp>
#include <SFML\Graphics.hpp>
#include <ctime>
#include <sstream>

using namespace sf;
using namespace std;

int main()
{
    VideoMode videoMode(320, 240);
    RenderWindow window(videoMode, "Plus or minus");

    Font font;
    if (!font.loadFromFile("TOMB.TTF"))
    {
        return EXIT_FAILURE;
    }

    Text title("Plus Or Minus", font, 20);
    title.setPosition(10, 10);
    title.setColor(Color::White);

    Text question("What is your guess ?",font,20);
    question.setPosition(5,30);
    question.setColor(Color::White);

    Text enter("", font, 20);
    enter.setPosition(5, 50);
    enter.setColor(Color::Green);
    String textEntered;
    int numEntered = 0;

    Text status("", font, 16);
    status.setPosition(100, 50);
    status.setColor(Color::Yellow);
    stringstream out("");

    Text won("You have discovered\n the secret number\n in less than 10 tries,\n well played !", font, 20);
    won.setPosition(5, 70);
    won.setColor(Color::Green);

    Text lost("You have failed to\n discover the secret\n number in less than\n 10 tries, better \nluck next time!", font, 20);
    lost.setPosition(5, 70);
    lost.setColor(Color::Red);

    srand(static_cast<unsigned int> (time(NULL)));

    int secretNumber = rand() % 100;

    bool isGameOn = true;
    bool playerWon = false;
    int tryNumber = 0;

    while (window.isOpen())
    {
        window.clear();
        window.draw(title);
        if (isGameOn)
        {
            window.draw(question);
            window.draw(enter);
            window.draw(status);
        }
        else
        {
            if (playerWon)
            {
                window.draw(won);
            }
            else
            {
                window.draw(lost);
            }
        }

        window.display();

        Event event;
        while (window.pollEvent(event))
        {
            if ((event.type == Event::Closed) || ((event.type == Event::KeyPressed) && (event.key.code == Keyboard::Escape)))
            {
                window.close();
            }

            if (event.type == Event::TextEntered)
            {
                char c = static_cast<char> (event.text.unicode);
                if (c >= '0' && c <= '9')
                {
                    textEntered += event.text.unicode;
                    enter.setString(textEntered);
                }
                else if (c == '\r')
                {
                    tryNumber++;

                    stringstream in(enter.getString());
                    in >> numEntered;

                    if (numEntered > secretNumber)
                    {
                        out << tryNumber;
                        out << ". ";
                        out << numEntered;
                        out << ": Minus" << endl;
                        status.setString(out.str());
                    }
                    if (numEntered < secretNumber)
                    {
                        out << tryNumber;
                        out << ". ";
                        out << numEntered;
                        out << ": Plus" << endl;
                        status.setString(out.str());
                    }
                    if (numEntered == secretNumber)
                    {
                        playerWon = true;
                        status.setString("");
                        isGameOn = false;
                    }
                    if (tryNumber > 10)
                    {
                        playerWon = false;
                        status.setString("");
                        isGameOn = false;
                    }
                    textEntered = "";
                }
            }
        }
        return EXIT_SUCCESS;
    }
}

我已经四处寻找,但我没有真正找到这个问题的答案,如果有人能帮助我解决这个问题,我将非常感激! :)

最好的问候

FreeSirenety

1 个答案:

答案 0 :(得分:1)

return循环结束时,您有一个while (window.isOpen()) { ... }语句。 所以循环只运行一次。