Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

Image Loading problems


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 Crusable   Members   -  Reputation: 348

Like
0Likes
Like

Posted 02 March 2013 - 11:53 PM

Hello, I am having some weird problems with my Image handling class. The code here I copied from my previous project and it worked there so I am unsure of the problem. 

 

Imagehandler.h 

 

 
//This class handlers loading, optimizing, colour keying, and blitting images
 
#ifndef IMAGE_HANDLER_H
#define IMAGE_HANDLER_H
 
#include "SDL.h"
#include "SDL_image.h"
#include <string>
 
class ImageHandler{
 
public:
    SDL_Surface* LoadImage(std::string Filename);
    void BlitImage(int x, int y, SDL_Surface* Image, SDL_Surface* Destination, SDL_Rect* SpriteClip);
 
private:
    SDL_Rect mOffset;
    Uint32 mColourKey;
    SDL_Surface* mLoadedImage;
    SDL_Surface* mOpdImage;
};
 
#endif //IMAGE_HANDLER_H

 

Imagehandler.cpp

 

 

 
 
#include "ImageHandler.h"
 
SDL_Surface* ImageHandler::LoadImage(std::string Filename){
    
    mLoadedImage = IMG_Load(Filename.c_str());
    mOpdImage = NULL;
    
    if(mLoadedImage != NULL){
 
        mOpdImage = SDL_DisplayFormat(mLoadedImage);
        SDL_FreeSurface(mLoadedImage);
 
    } else return NULL;
 
    if(mOpdImage != NULL){
 
        mColourKey = SDL_MapRGB(mOpdImage->format, 255, 0, 255);
        SDL_SetColorKey(mOpdImage, SDL_SRCCOLORKEY, mColourKey);
    }
    
    return mOpdImage;
}
 

The program throws an excpetion here

mOpdImage = SDL_DisplayFormat(mLoadedImage);

 

Thank you for any help.


Edited by Mathew Bergen, 02 March 2013 - 11:56 PM.

"C spilled his beer all over C++'s shirt. Outraged, C++ shouted, "Good god, man! Have you no class?"

"Your mother is so fat that the recursive function that was used to calculate her mass created a stack overflow"

 

 


Sponsor:

#2 Crusable   Members   -  Reputation: 348

Like
0Likes
Like

Posted 02 March 2013 - 11:56 PM

Sorry for posting three posts I had internet issues.


"C spilled his beer all over C++'s shirt. Outraged, C++ shouted, "Good god, man! Have you no class?"

"Your mother is so fat that the recursive function that was used to calculate her mass created a stack overflow"

 

 


#3 blueshogun96   Crossbones+   -  Reputation: 448

Like
0Likes
Like

Posted 03 March 2013 - 12:20 AM

The server was acting strange a while ago, that might have caused the double post...

 

Is IMG_Load part of SDL?  If not, can you share the source for that function?  Also, what's the exception message you're getting (assuming you're using visual studio)?

 

Shogun.


Shogun3D Development Blog (Last Update: April 11, 2013)

Latest Update: Mac-Metro Anyone?

 

Shogun3D on Tumblr! happy.png


#4 Dennisvb   Members   -  Reputation: 160

Like
0Likes
Like

Posted 03 March 2013 - 12:20 AM

What exception for you get?

#5 ultramailman   Members   -  Reputation: 820

Like
0Likes
Like

Posted 03 March 2013 - 12:42 AM

Are you linking with the SDL_image library? IMG_Load is from there so you need to link with it.



#6 Crusable   Members   -  Reputation: 348

Like
0Likes
Like

Posted 03 March 2013 - 01:41 AM

Is IMG_Load part of SDL?

 

 

 IMG_Load is from SDL_Image;

 

Are you linking with the SDL_image library?

 

Yes it is all linked properly

 

What exception for you get?

 

Unhandled exception at 0x6812591F (SDL.dll) in Space Invaders Clone.exe: 0xC0000005: Access violation reading location 0x0000013C.

That is the exact message.


Edited by Mathew Bergen, 03 March 2013 - 01:43 AM.

"C spilled his beer all over C++'s shirt. Outraged, C++ shouted, "Good god, man! Have you no class?"

"Your mother is so fat that the recursive function that was used to calculate her mass created a stack overflow"

 

 


#7 ultramailman   Members   -  Reputation: 820

Like
0Likes
Like

Posted 03 March 2013 - 02:10 AM

Please read the section titled "Newbie Hint" of this page: http://sdl.beuc.net/sdl.wiki/SDL_DisplayFormat, maybe it explains the cause to your problem.


Edited by ultramailman, 03 March 2013 - 02:12 AM.


#8 Crusable   Members   -  Reputation: 348

Like
0Likes
Like

Posted 03 March 2013 - 02:20 AM

Ah thanks. I have a repository with all the files loaded load before that thanks :)


"C spilled his beer all over C++'s shirt. Outraged, C++ shouted, "Good god, man! Have you no class?"

"Your mother is so fat that the recursive function that was used to calculate her mass created a stack overflow"

 

 





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS