Corregits 8.000.000 de segmentation faults en intro.cpp

This commit is contained in:
2024-10-07 18:37:08 +02:00
parent 0330fe6b74
commit bf945ef14b
5 changed files with 48 additions and 53 deletions

View File

@@ -19,18 +19,15 @@
struct JA_Music_t;
// Constructor
Intro::Intro(JA_Music_t *music):music(music)
Intro::Intro(JA_Music_t *music) : music(music)
{
// Copia los punteros
input = Input::get();
asset = Asset::get();
screen = Screen::get();
SDL_Renderer *renderer = screen->getRenderer();
SDL_Renderer *renderer = Screen::get()->getRenderer();
// Reserva memoria para los objetos
eventHandler = std::make_unique<SDL_Event>();
texture = std::make_unique<Texture>(renderer, asset->get("intro.png"));
text = std::make_unique<Text>(asset->get("nokia.png"), asset->get("nokia.txt"), renderer);
texture = std::make_unique<Texture>(renderer, Asset::get()->get("intro.png"));
text = std::make_unique<Text>(Asset::get()->get("nokia.png"), Asset::get()->get("nokia.txt"), renderer);
// Inicializa variables
section::name = section::NAME_INTRO;
@@ -49,7 +46,7 @@ Intro::Intro(JA_Music_t *music):music(music)
ss->setEnabledCounter(20);
ss->setDestX(param.game.gameArea.centerX - 64);
ss->setDestY(param.game.gameArea.firstQuarterY - 24);
bitmaps.push_back(ss.get());
bitmaps.push_back(std::move(ss));
}
bitmaps[0]->setPosX(-128);
@@ -111,7 +108,7 @@ Intro::Intro(JA_Music_t *music):music(music)
w->setKerning(-1);
w->setEnabled(false);
w->setEnabledCounter(180);
texts.push_back(w.get());
texts.push_back(std::move(w));
}
// Un dia qualsevol de l'any 2000
@@ -150,7 +147,7 @@ Intro::Intro(JA_Music_t *music):music(music)
texts[8]->setCaption(lang::getText(35));
texts[8]->setSpeed(16);
for (auto text : texts)
for (auto &text : texts)
{
text->center(param.game.gameArea.centerX);
}
@@ -191,7 +188,7 @@ void Intro::checkEvents()
void Intro::checkInput()
{
// Comprueba si se ha pulsado cualquier botón (de los usados para jugar)
if (input->checkAnyButtonPressed())
if (Input::get()->checkAnyButtonPressed())
{
JA_StopMusic();
section::name = section::NAME_TITLE;
@@ -200,7 +197,7 @@ void Intro::checkInput()
}
// Comprueba el input para el resto de objetos
screen->checkInput();
Screen::get()->checkInput();
// Comprueba los inputs que se pueden introducir en cualquier sección del juego
globalInputs::check();
@@ -371,15 +368,15 @@ void Intro::update()
ticks = SDL_GetTicks();
// Actualiza el objeto screen
screen->update();
Screen::get()->update();
// Actualiza los objetos
for (auto bitmap : bitmaps)
for (auto &bitmap : bitmaps)
{
bitmap->update();
}
for (auto text : texts)
for (auto &text : texts)
{
text->update();
}
@@ -393,24 +390,24 @@ void Intro::update()
void Intro::render()
{
// Prepara para empezar a dibujar en la textura de juego
screen->start();
Screen::get()->start();
// Limpia la pantalla
screen->clean(bgColor);
Screen::get()->clean(bgColor);
// Dibuja los objetos
for (auto bitmap : bitmaps)
for (auto &bitmap : bitmaps)
{
bitmap->render();
}
for (auto text : texts)
for (auto &text : texts)
{
text->render();
}
// Vuelca el contenido del renderizador en pantalla
screen->blit();
Screen::get()->blit();
}
// Bucle principal