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

Author Topic: SFML throws exception "Access violation reading location"  (Read 1864 times)

0 Members and 1 Guest are viewing this topic.

waxta

  • Newbie
  • *
  • Posts: 1
    • View Profile
SFML throws exception "Access violation reading location"
« on: March 28, 2016, 08:53:23 pm »
I got strange problem I mentioned in subject. Debbuger shows that exception throws in file button.cpp:
#include "Button.h"

Button::Button(std::string ButtonTittle)
{
        sf::FloatRect textBox;

        this->buttonFont.loadFromFile("media/fonts/arial.ttf");

        this->buttonTittle.setFont(this->buttonFont);
        this->buttonTittle.setString(ButtonTittle);
        textBox = this->buttonTittle.getLocalBounds();
        this->buttonTittle.setOrigin((textBox.width / 2.0f), (textBox.height / 2.0f));
        this->buttonTittle.setPosition(512.0f, 384.0f);

        this->buttonShape.setSize(sf::Vector2f( (textBox.width + 4.0f), (textBox.height + 15.0f) ));
        this->buttonShape.setOrigin((this->buttonShape.getSize()) / 2.0f);
        this->buttonShape.setPosition(this->buttonTittle.getPosition());
        this->buttonShape.setFillColor(sf::Color::Green);
}

Button::~Button()
{
}

void Button::Draw(sf::RenderWindow &gameWindow)
{
        gameWindow.draw(this->buttonShape);
        gameWindow.draw(this->buttonTittle);
}

void Button::MouseOverAction()
{

}
in line gameWindow.draw(this->buttonTittle);
Debbuger throws me this exception whenever I use vector<Button> in MainMenu class:
#pragma once
#include <vector>
#include <string>
#include "VVisibleObject.h"
#include "Button.h"

class MainMenu : public VVisibleObject
{
public:
        MainMenu(std::string ButtonTittle);
        ~MainMenu();
       
        void ShowMenu();
        static void AddButton(std::string ButtonTittle);
        void operator+=(std::string ButtonTittle);
        void Draw(sf::RenderWindow & gameWindow) override;

private:
        std::vector<Button> Buttons;
        //sf::Text GameTittle;
        //Button button;
};

 
when using single object Button rather than vector of buttons game runs correctly, showing me button. I'm linking debug files (sfml-xxx-d.lib) correcty .. I suppose :D

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: SFML throws exception "Access violation reading location"
« Reply #1 on: March 29, 2016, 02:02:03 am »
The vector of buttons is empty when it's first created. Are you trying to draw a button that doesn't exist?
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*