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

1
.gitignore vendored
View File

@@ -9,3 +9,4 @@ thumbs.db
*.zip *.zip
*.app *.app
*_debug* *_debug*
jail_engine*

15
Makefile Normal file
View File

@@ -0,0 +1,15 @@
executable = jail_engine_demo
source = *.cpp units/*.cpp
windows:
@echo off
g++ $(source) -std=c++11 -Wall -Os -lmingw32 -lws2_32 -lSDL2main -lSDL2 -ffunction-sections -fdata-sections -Wl,--gc-sections -static-libstdc++ -Wl,-subsystem,windows -o "$(executable).exe"
strip -s -R .comment -R .gnu.version "$(executable).exe" --strip-unneeded
macos:
clang++ $(source) -std=c++11 -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -o "$(executable)"
linux:
g++ $(source) -std=c++11 -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -Wl,--gc-sections -o "$(executable)"
strip -s -R .comment -R .gnu.version "$(executable)" --strip-unneeded

View File

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

View File

@@ -148,6 +148,7 @@ animatedSprite_t loadAnimationFromFile(Texture *texture, std::string filePath, b
// Constructor // Constructor
AnimatedSprite::AnimatedSprite(Texture *texture, SDL_Renderer *renderer, std::string file, std::vector<std::string> *buffer) AnimatedSprite::AnimatedSprite(Texture *texture, SDL_Renderer *renderer, std::string file, std::vector<std::string> *buffer)
{ {
//std::cout << "Creado AnimatedSprite" << std::endl;
// Copia los punteros // Copia los punteros
setTexture(texture); setTexture(texture);
setRenderer(renderer); setRenderer(renderer);
@@ -176,6 +177,7 @@ AnimatedSprite::AnimatedSprite(Texture *texture, SDL_Renderer *renderer, std::st
// Constructor // Constructor
AnimatedSprite::AnimatedSprite(SDL_Renderer *renderer, animatedSprite_t *animation) AnimatedSprite::AnimatedSprite(SDL_Renderer *renderer, animatedSprite_t *animation)
{ {
//std::cout << "Creado AnimatedSprite" << std::endl;
// Copia los punteros // Copia los punteros
setTexture(animation->texture); setTexture(animation->texture);
setRenderer(renderer); setRenderer(renderer);
@@ -193,6 +195,7 @@ AnimatedSprite::AnimatedSprite(SDL_Renderer *renderer, animatedSprite_t *animati
// Destructor // Destructor
AnimatedSprite::~AnimatedSprite() AnimatedSprite::~AnimatedSprite()
{ {
//std::cout << "Destruido AnimatedSprite" << std::endl;
for (auto &a : animation) for (auto &a : animation)
{ {
a.frames.clear(); a.frames.clear();
@@ -510,21 +513,6 @@ void AnimatedSprite::update()
MovingSprite::update(); MovingSprite::update();
} }
// Establece el rectangulo para un frame de una animación
void AnimatedSprite::setAnimationFrames(Uint8 index_animation, Uint8 index_frame, int x, int y, int w, int h)
{
animation[index_animation].frames.push_back({x, y, w, h});
}
// OLD - Establece el contador para todas las animaciones
void AnimatedSprite::setAnimationCounter(int value)
{
for (auto &a : animation)
{
a.counter = value;
}
}
// Reinicia la animación // Reinicia la animación
void AnimatedSprite::resetAnimation() void AnimatedSprite::resetAnimation()
{ {

View File

@@ -90,12 +90,6 @@ public:
// Actualiza las variables del objeto // Actualiza las variables del objeto
void update(); void update();
// OLD - Establece el rectangulo para un frame de una animación
void setAnimationFrames(Uint8 index_animation, Uint8 index_frame, int x, int y, int w, int h);
// OLD - Establece el contador para todas las animaciones
void setAnimationCounter(int value);
// Reinicia la animación // Reinicia la animación
void resetAnimation(); void resetAnimation();
}; };

View File

@@ -4,11 +4,18 @@
// Constructor // Constructor
Asset::Asset(std::string executablePath) Asset::Asset(std::string executablePath)
{ {
//std::cout << "Construido Asset" << std::endl;
this->executablePath = executablePath.substr(0, executablePath.find_last_of("\\/")); this->executablePath = executablePath.substr(0, executablePath.find_last_of("\\/"));
longestName = 0; longestName = 0;
verbose = true; verbose = true;
} }
// Destructot
Asset::~Asset()
{
//std::cout << "Destruido Asset" << std::endl;
}
// Añade un elemento a la lista // Añade un elemento a la lista
void Asset::add(std::string file, enum assetType type, bool required, bool absolute) void Asset::add(std::string file, enum assetType type, bool required, bool absolute)
{ {

View File

@@ -50,6 +50,9 @@ public:
// Constructor // Constructor
Asset(std::string path); Asset(std::string path);
// Destructor
~Asset();
// Añade un elemento a la lista // Añade un elemento a la lista
void add(std::string file, enum assetType type, bool required = true, bool absolute = false); void add(std::string file, enum assetType type, bool required = true, bool absolute = false);

View File

@@ -4,7 +4,6 @@
#include "asset.h" #include "asset.h"
#include "input.h" #include "input.h"
#include "jail_audio.h" #include "jail_audio.h"
//#include "resource.h"
#include "sprite.h" #include "sprite.h"
#include "text.h" #include "text.h"
#include "utils.h" #include "utils.h"

View File

@@ -1,9 +1,11 @@
#include "movingsprite.h" #include "movingsprite.h"
#include <iostream>
// Constructor // Constructor
MovingSprite::MovingSprite(float x, float y, int w, int h, float velx, float vely, float accelx, float accely, Texture *texture, SDL_Renderer *renderer) MovingSprite::MovingSprite(float x, float y, int w, int h, float velx, float vely, float accelx, float accely, Texture *texture, SDL_Renderer *renderer)
{ {
//std::cout << "Construido MovingSprite" << std::endl;
// Copia los punteros // Copia los punteros
this->texture = texture; this->texture = texture;
this->renderer = renderer; this->renderer = renderer;
@@ -53,6 +55,12 @@ MovingSprite::MovingSprite(float x, float y, int w, int h, float velx, float vel
currentFlipV = false; currentFlipV = false;
}; };
// Destructor
MovingSprite::~MovingSprite()
{
//std::cout << "Destruido MovingSprite" << std::endl;
}
// Reinicia todas las variables // Reinicia todas las variables
void MovingSprite::clear() void MovingSprite::clear()
{ {

View File

@@ -42,6 +42,9 @@ public:
// Constructor // Constructor
MovingSprite(float x = 0, float y = 0, int w = 0, int h = 0, float velx = 0, float vely = 0, float accelx = 0, float accely = 0, Texture *texture = nullptr, SDL_Renderer *renderer = nullptr); MovingSprite(float x = 0, float y = 0, int w = 0, int h = 0, float velx = 0, float vely = 0, float accelx = 0, float accely = 0, Texture *texture = nullptr, SDL_Renderer *renderer = nullptr);
// Destructor
~MovingSprite();
// Mueve el sprite // Mueve el sprite
void move(); void move();

View File

@@ -6,6 +6,8 @@
// Constructor // Constructor
Notify::Notify(SDL_Renderer *renderer, string iconFile, string bitmapFile, string textFile, string soundFile, options_t *options) Notify::Notify(SDL_Renderer *renderer, string iconFile, string bitmapFile, string textFile, string soundFile, options_t *options)
{ {
//std::cout << "Construido Notify" << std::endl;
// Inicializa variables // Inicializa variables
this->renderer = renderer; this->renderer = renderer;
this->options = options; this->options = options;
@@ -21,15 +23,29 @@ Notify::Notify(SDL_Renderer *renderer, string iconFile, string bitmapFile, strin
// Destructor // Destructor
Notify::~Notify() Notify::~Notify()
{ {
//std::cout << "Destruido Notify" << std::endl;
// Libera la memoria de los objetos // Libera la memoria de los objetos
delete iconTexture; if (iconTexture != nullptr)
delete text; {
delete iconTexture;
}
if (text != nullptr)
{
delete text;
}
JA_DeleteSound(sound); JA_DeleteSound(sound);
for (auto notification : notifications) for (auto notification : notifications)
{ {
delete notification.sprite; if (notification.sprite != nullptr)
delete notification.texture; {
delete notification.sprite;
}
if (notification.texture != nullptr)
{
delete notification.texture;
}
} }
} }
@@ -116,8 +132,14 @@ void Notify::clearFinishedNotifications()
{ {
if (notifications[i].state == ns_finished) if (notifications[i].state == ns_finished)
{ {
delete notifications[i].sprite; if (notifications[i].sprite != nullptr)
delete notifications[i].texture; {
delete notifications[i].sprite;
}
if (notifications[i].texture != nullptr)
{
delete notifications[i].texture;
}
notifications.erase(notifications.begin() + i); notifications.erase(notifications.begin() + i);
} }
} }

View File

@@ -5,13 +5,12 @@
// Constructor // Constructor
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options) Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options)
{ {
//std::cout << "Construido Screen" << std::endl;
// Inicializa variables // Inicializa variables
this->window = window; this->window = window;
this->renderer = renderer; this->renderer = renderer;
this->options = options; this->options = options;
gameCanvasWidth = options->screen.nativeWidth;
gameCanvasHeight = options->screen.nativeHeight;
borderWidth = options->screen.borderWidth * 2; borderWidth = options->screen.borderWidth * 2;
borderHeight = options->screen.borderHeight * 2; borderHeight = options->screen.borderHeight * 2;
@@ -22,7 +21,7 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options)
borderColor = {0x00, 0x00, 0x00}; borderColor = {0x00, 0x00, 0x00};
// Crea la textura donde se dibujan los graficos del juego // Crea la textura donde se dibujan los graficos del juego
gameCanvas = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, gameCanvasWidth, gameCanvasHeight); gameCanvas = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, options->screen.nativeWidth, options->screen.nativeHeight);
if (gameCanvas == nullptr) if (gameCanvas == nullptr)
{ {
if (options->console) if (options->console)
@@ -38,6 +37,7 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options)
// Destructor // Destructor
Screen::~Screen() Screen::~Screen()
{ {
//std::cout << "Destruido Screen" << std::endl;
if (notify != nullptr) if (notify != nullptr)
{ {
delete notify; delete notify;
@@ -92,23 +92,25 @@ void Screen::setVideoMode(int videoMode)
if (options->screen.borderEnabled) if (options->screen.borderEnabled)
{ {
windowWidth = gameCanvasWidth + borderWidth; windowWidth = options->screen.nativeWidth + borderWidth;
windowHeight = gameCanvasHeight + borderHeight; windowHeight = options->screen.nativeHeight + borderHeight;
dest = {0 + (borderWidth / 2), 0 + (borderHeight / 2), gameCanvasWidth, gameCanvasHeight}; dest = {0 + (borderWidth / 2), 0 + (borderHeight / 2), options->screen.nativeWidth, options->screen.nativeHeight};
} }
else else
{ {
//windowWidth = gameCanvasWidth; // windowWidth = options->screen.nativeWidth;
windowWidth = gameCanvasWidth * options->screen.nativeZoom * options->screen.windowZoom; windowWidth = options->screen.nativeWidth * options->screen.nativeZoom * options->screen.windowZoom;
//windowHeight = gameCanvasHeight; // windowHeight = options->screen.nativeHeight;
windowHeight = gameCanvasHeight * options->screen.nativeZoom * options->screen.windowZoom; windowHeight = options->screen.nativeHeight * options->screen.nativeZoom * options->screen.windowZoom;
//dest = {0, 0, gameCanvasWidth, gameCanvasHeight}; // dest = {0, 0, options->screen.nativeWidth, options->screen.nativeHeight};
dest = {0, 0, windowWidth, windowHeight}; gameWidth = options->screen.nativeWidth * options->screen.nativeZoom;
gameHeight = options->screen.nativeHeight * options->screen.nativeZoom;
dest = {0, 0, gameWidth, gameHeight};
} }
// Modifica el tamaño de la ventana // Modifica el tamaño de la ventana
//SDL_SetWindowSize(window, windowWidth * options->screen.windowZoom, windowHeight * options->screen.windowZoom); // SDL_SetWindowSize(window, windowWidth * options->screen.windowZoom, windowHeight * options->screen.windowZoom);
SDL_SetWindowSize(window, windowWidth, windowHeight); SDL_SetWindowSize(window, windowWidth, windowHeight);
SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED); SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
} }
@@ -127,20 +129,20 @@ void Screen::setVideoMode(int videoMode)
{ {
// Calcula el tamaño de la escala máxima // Calcula el tamaño de la escala máxima
int scale = 0; int scale = 0;
while (((gameCanvasWidth * (scale + 1)) <= windowWidth) && ((gameCanvasHeight * (scale + 1)) <= windowHeight)) while (((options->screen.nativeWidth * (scale + 1)) <= windowWidth) && ((options->screen.nativeHeight * (scale + 1)) <= windowHeight))
{ {
scale++; scale++;
} }
dest.w = gameCanvasWidth * scale; dest.w = options->screen.nativeWidth * scale;
dest.h = gameCanvasHeight * scale; dest.h = options->screen.nativeHeight * scale;
dest.x = (windowWidth - dest.w) / 2; dest.x = (windowWidth - dest.w) / 2;
dest.y = (windowHeight - dest.h) / 2; dest.y = (windowHeight - dest.h) / 2;
} }
else if (options->screen.keepAspect) else if (options->screen.keepAspect)
{ {
float ratio = (float)gameCanvasWidth / (float)gameCanvasHeight; float ratio = (float)options->screen.nativeWidth / (float)options->screen.nativeHeight;
if ((windowWidth - gameCanvasWidth) >= (windowHeight - gameCanvasHeight)) if ((windowWidth - options->screen.nativeWidth) >= (windowHeight - options->screen.nativeHeight))
{ {
dest.h = windowHeight; dest.h = windowHeight;
dest.w = (int)((windowHeight * ratio) + 0.5f); dest.w = (int)((windowHeight * ratio) + 0.5f);
@@ -164,7 +166,8 @@ void Screen::setVideoMode(int videoMode)
} }
// Modifica el tamaño del renderizador // Modifica el tamaño del renderizador
SDL_RenderSetLogicalSize(renderer, windowWidth, windowHeight); // SDL_RenderSetLogicalSize(renderer, windowWidth, windowHeight);
SDL_RenderSetLogicalSize(renderer, gameWidth, gameHeight);
// Actualiza las opciones // Actualiza las opciones
options->screen.mode = videoMode; options->screen.mode = videoMode;
@@ -302,7 +305,7 @@ void Screen::renderFade()
return; return;
} }
const SDL_Rect rect = {0, 0, gameCanvasWidth, gameCanvasHeight}; const SDL_Rect rect = {0, 0, options->screen.nativeWidth, options->screen.nativeHeight};
color_t color = {0, 0, 0}; color_t color = {0, 0, 0};
const float step = (float)fadeCounter / (float)fadeLenght; const float step = (float)fadeCounter / (float)fadeLenght;
const int alpha = 0 + (255 - 0) * step; const int alpha = 0 + (255 - 0) * step;

View File

@@ -22,14 +22,14 @@ private:
Notify *notify; // Dibuja notificaciones por pantalla Notify *notify; // Dibuja notificaciones por pantalla
// Variables // Variables
int windowWidth; // Ancho de la pantalla o ventana int borderWidth; // Anchura del borde que se añade a la resolución nativa del juego
int windowHeight; // Alto de la pantalla o ventana int borderHeight; // Anltura del borde que se añade a la resolución nativa del juego
int gameCanvasWidth; // Resolución interna del juego. Es el ancho de la textura donde se dibuja el juego int gameWidth; // Resultado de multiplicar la resolución nativa (mas el borde) por el zoom nativo
int gameCanvasHeight; // Resolución interna del juego. Es el alto de la textura donde se dibuja el juego int gameHeight; // Resultado de multiplicar la resolución nativa (mas el borde) por el zoom nativo
int borderWidth; // Anchura del borde int windowWidth; // Resultado de multiplicar gameWidth por el zoom de la ventana
int borderHeight; // Anltura del borde int windowHeight; // Resultado de multiplicar gameWidth por el zoom de la ventana
SDL_Rect dest; // Coordenadas donde se va a dibujar la textura del juego sobre la pantalla o ventana SDL_Rect dest; // Coordenadas donde se va a dibujar la textura del juego sobre la pantalla o ventana
color_t borderColor; // Color del borde añadido a la textura de juego para rellenar la pantalla color_t borderColor; // Color del borde añadido a la textura de juego para rellenar la pantalla
// Variables - Efectos // Variables - Efectos
bool fade; // Indica si esta activo el efecto de fade bool fade; // Indica si esta activo el efecto de fade

View File

@@ -1,8 +1,10 @@
#include "sprite.h" #include "sprite.h"
#include <iostream>
// Constructor // Constructor
Sprite::Sprite(int x, int y, int w, int h, Texture *texture, SDL_Renderer *renderer) Sprite::Sprite(int x, int y, int w, int h, Texture *texture, SDL_Renderer *renderer)
{ {
//std::cout << "Construido Sprite" << std::endl;
// Establece la posición X,Y del sprite // Establece la posición X,Y del sprite
this->x = x; this->x = x;
this->y = y; this->y = y;
@@ -28,6 +30,7 @@ Sprite::Sprite(int x, int y, int w, int h, Texture *texture, SDL_Renderer *rende
Sprite::Sprite(SDL_Rect rect, Texture *texture, SDL_Renderer *renderer) Sprite::Sprite(SDL_Rect rect, Texture *texture, SDL_Renderer *renderer)
{ {
//std::cout << "Construido Sprite" << std::endl;
// Establece la posición X,Y del sprite // Establece la posición X,Y del sprite
this->x = rect.x; this->x = rect.x;
this->y = rect.y; this->y = rect.y;
@@ -51,6 +54,12 @@ Sprite::Sprite(SDL_Rect rect, Texture *texture, SDL_Renderer *renderer)
zoomH = 1.0f; zoomH = 1.0f;
} }
// Destructor
Sprite::~Sprite()
{
//std::cout << "Destruido Sprite" << std::endl;
}
// Muestra el sprite por pantalla // Muestra el sprite por pantalla
void Sprite::render() void Sprite::render()
{ {

View File

@@ -29,6 +29,9 @@ public:
Sprite(int x = 0, int y = 0, int w = 0, int h = 0, Texture *texture = nullptr, SDL_Renderer *renderer = nullptr); Sprite(int x = 0, int y = 0, int w = 0, int h = 0, Texture *texture = nullptr, SDL_Renderer *renderer = nullptr);
Sprite(SDL_Rect rect, Texture *texture, SDL_Renderer *renderer); Sprite(SDL_Rect rect, Texture *texture, SDL_Renderer *renderer);
// Destructor
~Sprite();
// Muestra el sprite por pantalla // Muestra el sprite por pantalla
void render(); void render();

View File

@@ -79,6 +79,7 @@ textFile_t LoadTextFile(string file, bool verbose)
// Constructor // Constructor
Text::Text(string textFile, string bitmapFile, SDL_Renderer *renderer) Text::Text(string textFile, string bitmapFile, SDL_Renderer *renderer)
{ {
//std::cout << "Construido Text" << std::endl;
// Carga los offsets desde el fichero // Carga los offsets desde el fichero
textFile_t tf = LoadTextFile(textFile); textFile_t tf = LoadTextFile(textFile);
@@ -104,6 +105,7 @@ Text::Text(string textFile, string bitmapFile, SDL_Renderer *renderer)
// Constructor // Constructor
Text::Text(string textFile, Texture *texture, SDL_Renderer *renderer) Text::Text(string textFile, Texture *texture, SDL_Renderer *renderer)
{ {
//std::cout << "Construido Text" << std::endl;
// Carga los offsets desde el fichero // Carga los offsets desde el fichero
textFile_t tf = LoadTextFile(textFile); textFile_t tf = LoadTextFile(textFile);
@@ -128,6 +130,7 @@ Text::Text(string textFile, Texture *texture, SDL_Renderer *renderer)
// Constructor // Constructor
Text::Text(textFile_t *textFile, Texture *texture, SDL_Renderer *renderer) Text::Text(textFile_t *textFile, Texture *texture, SDL_Renderer *renderer)
{ {
//std::cout << "Construido Text" << std::endl;
// Inicializa variables desde la estructura // Inicializa variables desde la estructura
boxHeight = textFile->boxHeight; boxHeight = textFile->boxHeight;
boxWidth = textFile->boxWidth; boxWidth = textFile->boxWidth;
@@ -149,8 +152,13 @@ Text::Text(textFile_t *textFile, Texture *texture, SDL_Renderer *renderer)
// Destructor // Destructor
Text::~Text() Text::~Text()
{ {
delete sprite; //std::cout << "Destruido Text" << std::endl;
if (texture) if (sprite != nullptr)
{
delete sprite;
}
if (texture != nullptr)
{ {
delete texture; delete texture;
} }

View File

@@ -7,6 +7,7 @@
// Constructor // Constructor
Texture::Texture(SDL_Renderer *renderer, std::string path, bool verbose) Texture::Texture(SDL_Renderer *renderer, std::string path, bool verbose)
{ {
//std::cout << "Construido Texture" << std::endl;
// Copia punteros // Copia punteros
this->renderer = renderer; this->renderer = renderer;
this->path = path; this->path = path;
@@ -26,6 +27,8 @@ Texture::Texture(SDL_Renderer *renderer, std::string path, bool verbose)
// Destructor // Destructor
Texture::~Texture() Texture::~Texture()
{ {
//std::cout << "Destruido Texture" << std::endl;
// Libera memoria // Libera memoria
unload(); unload();
} }