Fix possible segfault

This commit is contained in:
zvon 2020-09-12 09:36:08 +02:00
parent 0a06e1d841
commit 74e53a0d67
3 changed files with 28 additions and 18 deletions

View File

@ -113,6 +113,12 @@ public:
bool getRenderColiders() {
return render_coliders;
}
void clearRenderer() {
SDL_RenderClear( getRendererPtr() );
}
void presentRenderer() {
SDL_RenderPresent( getRendererPtr() );
}
private:
SDL_Renderer *renderer = NULL;
@ -562,10 +568,10 @@ public:
}
return ret;
}
void renderScene( bool clear_scene = true ) {
void renderScene( bool clear_renderer = true ) {
checkKilled();
render_mutex.lock();
if ( clear_scene )
if ( clear_renderer )
SDL_RenderClear( renderer->getRendererPtr() );
if ( background && background->getTexturePtr() )
SDL_RenderCopy( renderer->getRendererPtr(),

View File

@ -316,6 +316,11 @@ void handleKeyDownMain( SDL_Keycode key, SDLPP::Scene &scene ) {
g_cur_shadow->rotate();
updateShadow(scene);
break;
case SDLK_SPACE:
if(!g_cur_object)
break;
g_cur_object->setPos(g_cur_shadow->getPos());
break;
case SDLK_r:
scene.getRenderer().setRenderColiders(
!scene.getRenderer().getRenderColiders() );
@ -565,6 +570,16 @@ void gameOverSceneInput( std::shared_ptr< SDLPP::Scene > /*UNUSED*/, int /*UNUSE
pollEventsGameOver();
}
void saveOptions() {
g_update_colors = true;
if(g_cur_shadow)
g_cur_shadow->setHidden(!g_show_shadow);
g_pause = 0;
g_main_scene->setPrevTicks( SDL_GetTicks() );
g_active_scenes.pop_back();
g_input_functions.pop_back();
}
void handleKeyDownOptions( SDL_Keycode key ) {
switch ( key ) {
case SDLK_r:
@ -626,24 +641,14 @@ void handleKeyDownOptions( SDL_Keycode key ) {
case SDLK_RETURN:
switch ( g_options_select ) {
case 2:
g_update_colors = true;
g_cur_shadow->setHidden(!g_show_shadow);
g_pause = 0;
g_main_scene->setPrevTicks( SDL_GetTicks() );
g_active_scenes.pop_back();
g_input_functions.pop_back();
saveOptions();
break;
default:
break;
}
break;
case SDLK_ESCAPE:
g_update_colors = true;
g_cur_shadow->setHidden(!g_show_shadow);
g_pause = 0;
g_main_scene->setPrevTicks( SDL_GetTicks() );
g_active_scenes.pop_back();
g_input_functions.pop_back();
saveOptions();
default:
break;
}

View File

@ -107,12 +107,11 @@ int main() {
g_update_colors = false;
}
g_main_scene->renderScene();
renderer->clearRenderer();
for(auto &x : g_active_scenes) {
if(x != g_main_scene)
x->renderScene(false);
x->renderScene(false);
}
g_main_scene->presentScene();
renderer->presentRenderer();
g_wait_for_anim = false;
frames++;
if ( SDL_GetTicks() - base >= 1000 ) {