在c ++中使用sfml库时出错

时间:2015-07-17 07:11:32

标签: c++ visual-studio memory sfml

Deputy Engineer

这是我得到错误的代码的过度简化版本,它本身源自上面的“void reproduce()”函数。我为上下文添加了“picture”类,试着忽略它对代码长度的影响;我不是要你调试我的程序。尽管进行了广泛的研究,但我无法找到错误的原因。我正在使用SFML 2.2版并在visual studio 13中运行代码。

这是我得到的错误:

   #include <SFML/Graphics.hpp>
   #include <SFML/Window.hpp>
   #include <SFML/System.hpp>
   #include <iostream>
   #include <vector>
   #include <stack>
   using namespace sf;
   using namespace std;

class picture;
vector<picture*> picStack;

class picture
{
public:
    Image *mainImage;
    unsigned long long fitness = 0;
    picture(Vector2u size){
        mainImage = new Image;
        mainImage->create(size.x, size.y);
    }

    void test(Image objective){
        for (int i = 0; i < mainImage->getSize().x; i++)
        {
            for (int o = 0; o < mainImage->getSize().y; o++)
            {
                fitness += abs(mainImage->getPixel(i, o).r - objective.getPixel(i, o).r);
                fitness += abs(mainImage->getPixel(i, o).g - objective.getPixel(i, o).g);
                fitness += abs(mainImage->getPixel(i, o).b - objective.getPixel(i, o).b);
            }
        }
    }

    void generate(){
        for (int i = 0; i < mainImage->getSize().x; i++)
        {
            for (int o = 0; o < mainImage->getSize().y; o++)
            {
                mainImage->setPixel(i, o, Color(rand() % 255, rand() % 255, rand() % 255));
            }
        }
    }

    void draw(Vector2f position, RenderWindow *window){
        Texture texture;
        Sprite sprite;
        sprite.setPosition(position);
        texture.loadFromImage(*mainImage);
        sprite.setTexture(texture);
        window->draw(sprite);
    }

    ~picture(){
        delete mainImage;
    }
};

void reproduce(picture *male, picture *female){
    picStack.push_back(new picture(female->mainImage->getSize()));
}

0 个答案:

没有答案