C++ Sfml text class Unhandled exception at 0x0F58155F (sfml-graphics-d-2.dll)

て烟熏妆下的殇ゞ 提交于 2019-12-12 06:19:18

问题


Hello I add Text Class to my project , where text is fallowing the moving ball i build is successful, but when i trying debuging i receive

Unhandled exception at 0x0F58155F (sfml-graphics-d-2.dll) in Lotto.exe: 0xC0000005: Access violation reading location 0xCCCCCD24.

My main.cpp

#include <iostream>
#include <SFML/Graphics.hpp>
#include  "Ball.h"
#include  "Line.h"
#include  "TextBall.h"
using namespace std;
using namespace sf;

int main()
{
    RenderWindow win(VideoMode(800, 600), L"Rozdział 1");
    Clock stoper;
    Font font;
    font.loadFromFile("arial.ttf");
    float ySpeed = -100;
    float xSpeed = -100;
    Ball CircleOne(win);
    Line linia1(win);
    linia1.sie(500, 500);
    linia1.position(20, 20);
    linia1.thiness(2);
    TextBall text(win);
    text.dFont(font);
    text.dString("Hello");
    text.dCharacterSize(40);
    text.dColor(sf::Color::Black);
    text.dPosition(CircleOne.GetPosition().x + 5, CircleOne.GetPosition().y);




    CircleOne.SetPozition(100, 100);
//  CircleOne.SetOutlineColor(Color::Red);  
    CircleOne.Fil(Color::Yellow);
    CircleOne.Promien(15);
//  CircleOne.thinesS();

    while (win.isOpen())
    {
        win.clear(Color::White);
        Event e;
        while (win.pollEvent(e))
        {
            if (e.type == Event::Closed)
                win.close();

        }
        auto dt = stoper.restart().asSeconds();

        CircleOne.Move(xSpeed *dt , ySpeed * dt);
        //text.Move(xSpeed *dt, ySpeed * dt);
        linia1.draw();
        CircleOne.Draw();
        text.Draw();


        int positionY = CircleOne.GetPosition().y;
        if (positionY <= 0){ ySpeed = -ySpeed; }
        if (positionY >= 600.0-2*CircleOne.radius()){ ySpeed = -ySpeed; }
        int positionX = CircleOne.GetPosition().x;
        if (positionX <= 0){ xSpeed = -xSpeed; }
        if (positionX >= 800.0-2*CircleOne.radius()){xSpeed = -xSpeed; }

        win.display();
    }
}

and TextBall class

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

using namespace std;
using namespace sf;

class TextBall{
public:
    TextBall(RenderWindow&);
    void dString(String);
    void dCharacterSize(int);
    void dColor(Color);
    void dPosition(float, float);
    void Move(float, float);
    void Draw();
    void dFont(Font);


private:
    Text text;
    RenderWindow& Render;

};
TextBall::TextBall(sf::RenderWindow& app) : Render(app)
{

}

void TextBall::dString(String liczba)
{
    text.setString(liczba);
}
void TextBall::dCharacterSize(int size)
{
    text.setCharacterSize(size);
}
void TextBall::dColor(Color kolor)
{
    text.setColor(kolor);
}
void TextBall::dPosition(float x, float y)
{
    text.setPosition(x, y);
}
void TextBall::Move(float a, float b)
{
    text.move(a, b);
}
void TextBall::Draw()
{
    Render.draw(text);
}
void TextBall::dFont(Font fon)
{
    text.setFont(fon);
}

When i add text without a additional class its working fine, i afraid it object sending in TextBall is faulty. Plaese how can i solve this project

来源:https://stackoverflow.com/questions/32034947/c-sfml-text-class-unhandled-exception-at-0x0f58155f-sfml-graphics-d-2-dll

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!