Segmentation fault

This commit is contained in:
2023-05-07 18:08:36 +02:00
parent 90ebea4807
commit c1f8e16963
17 changed files with 163 additions and 73 deletions

View File

@@ -18,8 +18,8 @@ Código fuente creado por JailDesigner
SDL_Event *event;
SDL_Window *window;
SDL_Renderer *renderer;
int ticks = 0;
int ticksSpeed = 15;
Uint32 ticks = 0;
Uint32 ticksSpeed = 15;
int counter = 0;
int gradColorMin = 64; // Minimo color más alto del degradado
int gradColorMax = 192; // Minimo color más alto del degradado
@@ -28,7 +28,6 @@ int gradBreathDirection = 0; // Indica si gradCurrentColor crece o decrece
int main(int argc, char *argv[])
{
// Inicializa las opciones
struct options_t *options = new options_t;
initOptions(options);
@@ -36,7 +35,7 @@ int main(int argc, char *argv[])
options->screen.nativeHeight = 240;
options->screen.nativeZoom = 1;
options->screen.windowZoom = 2;
options->console = true;
options->console = false;
// Inicializa la lista de recursos
Asset *asset = new Asset(argv[0]);
@@ -56,6 +55,7 @@ int main(int argc, char *argv[])
// Inicializa SDL y la ventana
SDL_Init(SDL_INIT_EVERYTHING);
window = SDL_CreateWindow("jail_engine_demo", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, options->screen.nativeWidth * options->screen.nativeZoom * options->screen.windowZoom, options->screen.nativeHeight * options->screen.nativeZoom * options->screen.windowZoom, SDL_WINDOW_SHOWN);
// window = SDL_CreateWindow("jail_engine_demo", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 320, 240, SDL_WINDOW_SHOWN);
if (window != nullptr)
{
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
@@ -72,13 +72,10 @@ int main(int argc, char *argv[])
// Inicializa jail_audio
JA_Init(48000, AUDIO_S16, 2);
JA_Music_t *music;
JA_Sound_t *sound;
music = JA_LoadMusic(asset->get("music.ogg").c_str());
sound = JA_LoadSound(asset->get("sound.wav").c_str());
int volume = 128;
// Inicializa el objeto screen
Screen *screen = new Screen(window, renderer, options);
@@ -101,7 +98,7 @@ int main(int argc, char *argv[])
sprite->setVelY(2);
// Bucle principal
// JA_PlayMusic(music, true);
JA_PlayMusic(music, true);
bool should_exit = false;
while (!should_exit)
{
@@ -206,6 +203,8 @@ int main(int argc, char *argv[])
// Dibuja en pantalla
screen->start();
screen->clean();
// SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0xFF);
// SDL_RenderClear(renderer);
// Dibuja un degradado de fondo
const int gradFirstLine = options->screen.nativeHeight / 3;
@@ -233,29 +232,54 @@ int main(int argc, char *argv[])
// Vuelca el buffer en pantalla
screen->blit();
// SDL_RenderPresent(renderer);
}
// Finaliza el sprite
delete sprite;
delete texture;
if (sprite != nullptr)
{
delete sprite;
}
if (texture != nullptr)
{
delete texture;
}
// Finaliza el texto
delete text;
if (text != nullptr)
{
delete text;
}
// Finaliza el objeto screen
delete screen;
if (screen != nullptr)
{
delete screen;
}
// Finaliza jail_audio
JA_DeleteSound(sound);
JA_DeleteMusic(music);
// Finaliza el objeto con la lista de recuros
delete asset;
if (asset != nullptr)
{
delete asset;
}
// Finaliza las opciones
if (options != nullptr)
{
delete options;
}
// Finaliza SDL y la ventana
if (event != nullptr)
{
delete event;
}
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
delete event;
SDL_Quit();
return 0;