I'm working on a C++ project that uses SFML and lua The thing is when I tried to push the texture pointer that I loaded it crashes.
Here's my code
sf::Texture* tex = new sf::Texture;
if(!tex->loadFromFile(lua_tostring(L, -1))) std::cout << "Failed to load texture!" << std::endl;
std::cout << "Got here!" << std::endl;
try{
p.tex_auras.push_back(tex);
}catch(std::invalid_argument& e){
std::cout << "Error: " << e.what() << std::endl;
}
If I comment out the push_back thingy, everything was fine. Also, the code spits out Got here! once and if tried checking the tex->loadFromFile() to see if it fails, it didn't. When I debug the code it seems to happen in the std::vector::push_back
void push_back(const value_type &__x) {
if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage) { <<== HERE ==
_Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish,
__x);
++this->_M_impl._M_finish;
} else
_M_realloc_insert(end(), __x);
}
typedef std::vector<sf::Texture*> Textures;
// The textures was initialized in a class as such
class Player {
public:
// Just like that
Textures tex_auras;
}
I don't know what's going on
Apparently the player is NULL in the first place after I loaded the userdata from lua. I'm on the wrong stack index