Sign in to follow this  
Mr_lloyd_the_skater

DirectX 9 LoadSurface() function call returning NULL

Recommended Posts

Hey everyone. I'm tearing what little hair I have out over this problem I've been having loading some bitmaps using a simple exercise from a "Beginning Game Programming" textbook. It seems the function I have is returning a NULL value, and as such return a 0 and thusly triggering an error handler in my winMain function to display a messagebox onscreen to say its failed and then quit. The relevent sourcecode from the exercise is below for you to peruse in all its (in)glory: int Game_Init(HWND hwnd) { char s[20]; int n; srand(time(NULL)); //load sprite animation for (n=0; n<6; n++) { sprintf(s, "cat%d.bmp", n+1); kitty_image[n] = LoadSurface(s, D3DCOLOR_XRGB(255,0,255)); if (kitty_image[n] == NULL) return 0; } //some rubbish not important, skipping to end of func for you lot return 1; } and in Winmain this causes the following code to be actioned: //init game if (!Game_Init(hWnd)) { MessageBox(hWnd, "Error init game ","Error", MB_OK); return 0; } I have the cat%d.bmp files in the appropriate directory, and have tried moving them into different folders from being in the same one as where the .exe file is generated and then tried the debug folder, rebuilding the project but still no luck. It's driving me mad! I'm using MS Visual C++ Express Edition2008, vers 3.5 running on Vista. DirectX9 is fully installed I have no problems compiling or building my project. If anyone has a clue to what I'm doing completely wrong I'd be eternally grateful. Peace

Share this post


Link to post
Share on other sites
Did you try putting the bmp files in the project directory? (The one containing the debug folder, etc.)

Share this post


Link to post
Share on other sites
I had. I just tried putting them into another folder just now, rebuilt the project and its working, although I swore I had them in that same directory earlier and it refused to work! I'm ever so *slightly* embarassed to have used up GD's bandwidth and you guys and your time for musing over this.

Computers are so inconsistant and awkward to work with sometimes!

Thanks anyway
Peace
Lloyd

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this