SDLPP: Save texture before rendering
In some cases texture might be changed after render() has been called but before renderer presented the render, causing errors.
This commit is contained in:
parent
b65b0bf034
commit
1f7a80d7d2
@ -104,10 +104,10 @@ std::shared_ptr< Renderer > RenderObject::getRenderer() const {
|
||||
void RenderObject::setSceneID( int id ) {
|
||||
scene_id = id;
|
||||
}
|
||||
void RenderObject::copyTo(std::shared_ptr<RenderObject> other) {
|
||||
void RenderObject::copyTo( std::shared_ptr< RenderObject > other ) {
|
||||
other->collisions.clear();
|
||||
for ( auto &colider : collisions ) {
|
||||
other->collisions.push_back(colider->copySelf());
|
||||
other->collisions.push_back( colider->copySelf() );
|
||||
}
|
||||
other->texture.reset();
|
||||
if ( texture ) {
|
||||
@ -119,4 +119,7 @@ void RenderObject::copyTo(std::shared_ptr<RenderObject> other) {
|
||||
}
|
||||
other->colidedWith.clear();
|
||||
}
|
||||
void RenderObject::saveCurTexture() {
|
||||
cur_texture = texture;
|
||||
}
|
||||
} // namespace SDLPP
|
||||
|
@ -78,11 +78,13 @@ public:
|
||||
bool isStatic();
|
||||
void setStatic( bool stat = true );
|
||||
std::shared_ptr< Renderer > getRenderer() const;
|
||||
void saveCurTexture();
|
||||
|
||||
protected:
|
||||
virtual void copyTo(std::shared_ptr<RenderObject> other);
|
||||
virtual void copyTo( std::shared_ptr< RenderObject > other );
|
||||
std::vector< std::shared_ptr< CollisionPolygon > > collisions;
|
||||
std::shared_ptr< Texture > texture;
|
||||
std::shared_ptr< Texture > cur_texture;
|
||||
std::shared_ptr< Renderer > renderer;
|
||||
std::shared_ptr< CollisionPolygon > polygon;
|
||||
double movementSpeed = 0;
|
||||
|
@ -121,6 +121,7 @@ void Scene::renderScene( bool clear_renderer ) {
|
||||
SDL_RenderCopy( renderer->getRendererPtr(), background->getTexturePtr(),
|
||||
NULL, NULL );
|
||||
for ( const auto &x : render_objects ) {
|
||||
x->saveCurTexture();
|
||||
x->render();
|
||||
}
|
||||
}
|
||||
|
@ -55,6 +55,7 @@ Texture::Texture( std::shared_ptr< Renderer > &renderer, Font &font,
|
||||
setTextureFromSurface( renderer, surface );
|
||||
}
|
||||
Texture::~Texture() {
|
||||
if ( texture != nullptr )
|
||||
SDL_DestroyTexture( texture );
|
||||
}
|
||||
SDL_Texture *Texture::getTexturePtr() {
|
||||
|
Loading…
Reference in New Issue
Block a user