5
« on: October 12, 2017, 02:45:58 am »
My game crashes after my objects vector's size gets higher than 127.
This is my code
--- Main loop function
// Set the FPS limit of the window
m_window.setFramerateLimit(60);
// Activate the window
m_window.setActive(true);
// Disable lighting
glDisable(GL_LIGHTING);
// Configure the viewport (the same size as the window)
glViewport(0, 0, m_window.getSize().x, m_window.getSize().y);
// Enable OpenGL
glEnable(GL_TEXTURE_2D);
// Load all scenes
SceneTest sc_0;
scenes.push_back(&sc_0);
sf::Texture sortOfATex;
sortOfATex.loadFromFile("data/uglie.gif");
// Main game loop
while (m_window.isOpen())
{
// Event
sf::Event event;
while (m_window.pollEvent(event))
{
// Close the game when the [X] button is clicked
if (event.type == sf::Event::Closed)
m_window.close();
}
// Clear the buffers
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Run the scene
scenes[currentScene]->run(m_window);
if (sf::Keyboard::isKeyPressed(sf::Keyboard::B))
{
GameObject obj(sortOfATex);
objects.push_back(obj);
}
int8_t i;
for (const auto& x : objects)
{
objects[i].update();
objects[i].draw(m_window);
i++;
}
i = 0;
// Display the things on the window
m_window.display();
}
--- GameObject
Source file
#include "GameObject.hpp"
GameObject::GameObject(sf::Texture& text)
: spr(text)
{}
GameObject::~GameObject() {}
void GameObject::update()
{
spr.move(1, 0);
}
void GameObject::draw(sf::RenderWindow& w)
{
w.draw(this->spr);
}
Header
#ifndef GAMEOBJECT_HPP
#define GAMEOBJECT_HPP
#include <SFML/Graphics.hpp>
class GameObject
{
public:
GameObject(sf::Texture& text);
virtual ~GameObject();
virtual void update();
virtual void draw(sf::RenderWindow& w);
private:
sf::Sprite spr;
};
#endif // GAMEOBJECT_HPP
Thanks for reading.