Hello, i'm trying to load an image but whenever I get a SIGSEGV error, do not know why, since I have other projects that work with that class picture but that it is giving this error'll put here the class that loads the image:
the code is in Portuguese, if you have problems with the translation, let me know that I translate
imagem.h
Code:
#pragma once
#ifndef IMAGEM_H_
#define IMAGEM_H_
#include "erro.h"
#include <SDL.h>
//Classe usada para carregar uma imagem em uma superficie
class Imagem
{
//Superficie onde a imagem será desenhada
SDL_Surface* surface;
//A imagem
SDL_Surface* imagem;
//Area da imagem
SDL_Rect area;
//Parte da imagem que será desenhada
//SDL_Rect parte;
int carregar_imagem(std::string);
public:
Imagem(SDL_Surface*, int, int, std::string);
void MudarImagem(std::string);
void Desenhar();
void Posicionar(int x, int y);
SDL_Rect ImagemArea();
SDL_Surface* ImagemSurface();
};
#endif
imagem.cpp
Code:
#include "imagem.h"
int Imagem::carregar_imagem(std::string imagem)
{
SDL_Surface* temp = SDL_LoadBMP(imagem.c_str());
if(temp == NULL)
return -1;
this->imagem = SDL_DisplayFormat(temp);
SDL_FreeSurface(temp);
return 0;
return 0;
}
Imagem::Imagem(SDL_Surface* surface, int x, int y,std::string imagem)
{
if(carregar_imagem(imagem) == -1)
throw(Erro("Não foi possivel carregar a imagem " +imagem+ "."));
this->surface = surface;
area.x = x;
area.y = y;
}
void Imagem::MudarImagem(std::string imagem)
{
if(carregar_imagem(imagem) == -1)
throw(Erro("Não foi possivel carregar a imagem " +imagem+ "."));
}
void Imagem::Desenhar()
{
SDL_BlitSurface(imagem, NULL, surface, &area);
}
void Imagem::Posicionar(int x, int y)
{
area.x = x;
area.y = y;
}
SDL_Rect Imagem::ImagemArea()
{
return area;
}
SDL_Surface* Imagem::ImagemSurface()
{
return imagem;
}
I debug the code and call the function SDL_DisplayFormat whenever it's wrong
I thank anyone who can help