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

Author Topic: Vector of text but access violation  (Read 1120 times)

0 Members and 1 Guest are viewing this topic.

Canvas

  • Full Member
  • ***
  • Posts: 107
    • View Profile
Vector of text but access violation
« on: July 18, 2012, 03:16:39 pm »
Hey guys, just a little problem.
I have a vector of a class called gText,
I know for a fact that gText works as i use it for something else, but i cant seem to get it to work in a different state...
this is my code for the working piece i already have

gText tempText;
tempText.setUpInt(monsters.at(i).pos,monsters.at(i).rtnDam(),font);
texts.push_back(tempText);
 

and in my draw method it draws it fine,

also pos is just a simple rect class i made, the rtnDam is just a int and font is a variable that holds a sf::Font

so i then put this code to draw some text on screen

                        gText tmpText;
                        rect pos;
                        pos.x = 200;
                        pos.y = 100;
                        pos.h = 1;
                        pos.w = 1;
                        tmpText.setUpText(pos,"text",font);
                        texts.push_back(tmpText);
 

now if i run any method from my gText class, i can return the text, i can also return its pos. but with this code

for(int i=0;i<texts.size();i++){if(texts.at(i).rtnAlive() == true){screen.draw(texts.at(i).rtnText());}}
 

i get a huge access violation error which im really confused about. can anyone tell me whats wrong?

Cheers.

Its ok, i found out it was going out of scope, and as i could access the string and pos, i still couldnt access the sf::text cause of how sfml is coded :), but i fixed it. cheers
« Last Edit: July 18, 2012, 03:31:01 pm by Canvas »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Vector of text but access violation
« Reply #1 on: July 18, 2012, 03:37:50 pm »
Quote
Its ok, i found out it was going out of scope, and as i could access the string and pos, i still couldnt access the sf::text cause of how sfml is coded , but i fixed it. cheers
You should put it at the beginning of your post, so that people can see it before reading the full message... ;)
Laurent Gomila - SFML developer