C++ Help

Stormrider^

EGO Addict
Joined
Aug 2, 2008
Messages
1,315
Hello,
I need a help of someone who is comfortable around C++ and preferably SDL.

I'm trying to learn my way around C++ using Windows (sigh, would've used Kubuntu but it has some sort of grudge against my DVD-drive) and Visual C++ 2008 Express Edition.

The problem? The program gives no error regarding the code, none what so ever, but it does not load the image. It draws the screen black but displays no image and yes the image is in the right folder. When I execute it from the command line, it works perfectly. I think the debug-mode messes up the filepaths, any way to fix it?

Code:
Code:
#include "SDL.h"

int main( int argc, char* args[] )
{
    //The images
    SDL_Surface* hello = NULL;
    SDL_Surface* screen = NULL;

    //Start SDL
    SDL_Init( SDL_INIT_EVERYTHING );

    //Set up screen
    screen = SDL_SetVideoMode( 640, 480, 32, SDL_SWSURFACE );

    //Load image
    hello = SDL_LoadBMP( "hello.bmp" );

    //Apply image to screen
    SDL_BlitSurface( hello, NULL, screen, NULL );

    //Update Screen
    SDL_Flip( screen );

    //Pause
    SDL_Delay( 2000 );

    //Free the loaded image
    SDL_FreeSurface( hello );

    //Quit SDL
    SDL_Quit();

    return 0;
}



May or may not count as a tech-issue but still, no better place to put it in.
 
Last edited:
For starters, you need to check the return value on each call..That will help track down what's failing.

SDL_Init Returns -1 on an error or 0 on success

SDL_SetVideoMode returns the framebuffer (screen as you call it), OR NULL if it fails.

SDL_BlitSurface Returns -1 on an error or 0 on success

The other SDL functions return values also. It's always good programming to capture and check all calls..even something as simple as a file I/O.
 
Hmmm, code looks right. Let me do some thinking, man this is gonna hurt, havn't done this in a long time. Executes from the command line.......hmmm
 
For starters, you need to check the return value on each call..That will help track down what's failing. /SNIP

The Ten Commandments for C Programmers (by Henry Spencer)

...
2. Thou shalt not follow the NULL pointer, for chaos and madness await thee at its end.
...
6. If a function be advertised to return an error code in the event of difficulties, thou shalt check for that code, yea, even though the checks triple the size of thy code and produce aches in thy typing fingers, for if thou thinkest "it cannot happen to me", the gods shall surely punish thee for thy arrogance.
...

Back to your specific problem, I'm not quite sure:
What do you mean by
... execute it from the command line, it works perfectly...

What commandline? How is that code run? Does it load the img?
 

Latest posts

Back
Top