GPWiki.org
GPWiki.org
It is currently Wed Jun 19, 2013 1:53 pm

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Fri Feb 15, 2013 3:48 am 
Rookie

Joined: Fri Feb 15, 2013 3:40 am
Posts: 1
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


Top
 Profile  
 
PostPosted: Sun Feb 17, 2013 3:02 pm 
Gamer Geek
User avatar

Joined: Wed Jun 20, 2012 4:03 am
Posts: 29
Have you tried to write the bmp after reading it and then watch it with a graphics program, should look the same as the original, if not, then something with the bmp is wrong (e.g. picture mode rgb/index/grey)

Code:
int Imagem::carregar_imagem(std::string imagem)
{
    SDL_Surface* temp = SDL_LoadBMP(imagem.c_str());
    SDL_SaveBMP(temp, "thisshouldexactlythesameastheorig.bmp");
...

_________________
My projects: Gamvas Web - html5 canvas game framework| sge2d - C/C++ 2D SDL game framework


Top
 Profile  
 
PostPosted: Sun Feb 17, 2013 10:53 pm 
Octogenarian
User avatar

Joined: Sun Aug 05, 2012 9:32 pm
Posts: 96
God, i hate SIGSEGV errors. but regarding the image topic, i get that error when I make an image in photoshop and leave the default background White layer there. As soon as i make it invisible or delete it it loads just fine, so it might be just an image problem.

_________________
Did you ever wonder, how time works?


Top
 Profile  
 
PostPosted: Mon Apr 22, 2013 6:29 am 
Rookie

Joined: Mon Apr 22, 2013 6:24 am
Posts: 1
Sorry, a little confused on your sample code, you can check this image loading sdk in c# and sample code to see what happened to your code, also vb .net image loading info is offered too.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group