访问违规写入位置

时间:2014-11-27 23:19:38

标签: c++ access-violation

我正在尝试将对象存储在列表>中,并从列表中存储的每个对象中调用一个方法。目前,该对象调用该方法,但最终崩溃与_locktable中的mlock.c中的Access违规写入位置(方法void __cdecl _unlock)。以下是相关文件:

#include "TextWindow.hpp"
#include "TextElement.hpp"

#include <iostream>

TextWindow::TextWindow(const TextureHolder& textures, const FontHolder& fonts, sf::Window& windows, Fonts::ID fontID, sf::String text)
: mSprite(textures.get(Textures::WindowDefault))
, mHitpoints(10)
, mWindow(windows)
{
    sf::FloatRect bounds = mSprite.getLocalBounds();
    mSprite.setOrigin(bounds.width / 2.f, bounds.height / 2.f);
    addElements(text, fonts.get(fontID));
}

void TextWindow::addElements(sf::String text, sf::Font font)
{
    std::unique_ptr<TextElement> e(new TextElement(text, font, 10, xPos, yPos, 10, 10));
    mElements.push_back(std::move(e));
}

void TextWindow::drawCurrent(sf::RenderTarget& target, sf::RenderStates states) const
{
    target.draw(mSprite, states);
    for(std::list<std::unique_ptr<Element>>::const_iterator iterator = mElements.begin(); iterator != mElements.end(); ++iterator)
    {
        //std::cout << "IN TEXTWINDOW PRINT ITERATOR" << std::endl;
        (*iterator).get()->drawCurrent(target, states);
    }

}

void TextWindow::updateCurrent(sf::Time dt)
{
}

#include "TextElement.hpp"
#include <iostream>

TextElement::TextElement(sf::String text, sf::Font font, int textSize, int xOrig, int yOrig, int xPos, int yPos)
: mText(text, font, textSize)
, xpos(xPos)
, ypos(yPos)
{
    mText.setOrigin(xOrig, yOrig);
    mText.setColor(sf::Color::Green);
}

void TextElement::drawCurrent(sf::RenderTarget& target, sf::RenderStates states) const
{
    std::cout << "TEXTELEMENT" << std::endl;
    target.draw(mText, states);
}
void TextElement::updateCurrent(sf::Time dt)
{
    //Do nothing, text doesn't need to update!
}

建议?

0 个答案:

没有答案