Hey,
I need another pair of eyes to look over my code to find out what the hell is going on
I get no compiler or link errors but I segfault every time, upon closer inspection with Valgrind, I am given an error message:
Access not within mapped region at address 0x10
==21451== at 0x52A31B6: sf::RenderTarget::draw(sf::Drawable const&, sf::RenderStates const&) (in /usr/local/lib/libsfml-graphics.so.2.4.1)
It crashes during this function:
void
render_system_draw(Engine *engine, EntityPool &pool) {
std::shared_ptr<TransformComponent> transform;
std::shared_ptr<RenderComponent> render;
for (Entity *ent : pool.entities) {
if (entity_has_component<TransformComponent>(ent) && entity_has_component<RenderComponent>(ent)) {
transform = entity_get_component<TransformComponent>(ent);
render = entity_get_component<RenderComponent>(ent);
render->sprite.setPosition(sf::Vector2f(transform->x, transform->y));
engine->window.draw(render->sprite); /* CRASHES HERE */
}
}
}
render->sprite is an sf::Sprite, the texture is maintained since I do all my allocations in a big pool and give out sub-allocations so it only gets freed at the end. I've got into the debugger and poked around, double-triple checking that render->sprite is not null, nor is engine or the entity pool.
If I move the draw code out into game.cpp, and use a separate texture and position, it works fine. But as soon as I call it in render_system_draw, it segfaults. render and texture are not null, nor is any of their members.
Help please
If you need to see any more code then just say and I'll post whatever you need.