Sign in to follow this  
SLy2097

Cannot load bitmaps in VC++ 2005

Recommended Posts

Hope some one can help me with this. I have a game running OK in VC98 and want to use VC2005 instead. I have got the program just about running now but have hit a snag with loading bitmaps. I get this error message: - ------------------------- Debug Assertion Failed! Program: ... File: lseek.c Line: 66 Expression: (fh >= 0 && (unsigned)fh < (unsigned)_nhandle) For information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts. (Press Retry to debug the application) ------------------------- this happens directly after this call: - _lseek(file_handle,-(int)(bitmap->bitmapinfoheader.biSizeImage),SEEK_END); When debugging, I can see that the file loads OK as the header info is read (there is also code to stop the app upon failure). Not sure if this could be a linker problem? whereby I am just not using the correct libraries? These are the libraries in my proj: - user32.lib gdi32.lib ole32.lib ddraw.lib dxguid.lib dinput.lib dinput8.lib winmm.lib dsound.lib fmodvc.lib Also, I am using the latest DX9 SDK, April 2006. Any help is much appreciated. Thanks Ryan

Share this post


Link to post
Share on other sites
I think this line might say it all:
Expression: (fh >= 0 && (unsigned)fh < (unsigned)_nhandle)

It looks like your file handle is invalid. Debug your program and add a watch for the file_handle variable, although I'm not sure how the file would load with an invalid handle.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Im not too sure about what the actual problem is there, but it seems that microsoft are intent on phasing-out the use of c-style file handling in later versions of vc++ so you might be better off just switching to fstreams to handle bitmap loading.

Share this post


Link to post
Share on other sites
thanks for the suggestion of using fstream. A combination of the existing code, plus the tutorial: -

How to load a bitmap
http://www.gamedev.net/reference/articles/article608.asp

did the trick. For the benefit of anyone else, here are the changes made to the code: -

//NOTE: This is all in the function
int Load_Bitmap_File(BITMAP_FILE_PTR bitmap, char *filename)

// DECLARE FILE POINTER --------------------------------------
int file_handle
*** Replaced with ***
FILE *bmp_in

// GET FILE HANDLE -------------------------------------------
file_handle = OpenFile(filename,&file_data,OF_READ);
*** Replaced with ***
bmp_in = fopen( filename, "rb");

// READ FILE HEADER ------------------------------------------
_lread(file_handle, &bitmap->bitmapfileheader,sizeof(BITMAPFILEHEADER
*** Replaced with ***
fread(&bitmap->bitmapfileheader, sizeof(BITMAPFILEHEADER), 1, bmp_in);

// READ INFO HEADER ------------------------------------------
_lread(file_handle, &bitmap->bitmapinfoheader,sizeof(BITMAPINFOHEADER))
*** Replaced with ***
fread(&bitmap->bitmapinfoheader,sizeof(BITMAPINFOHEADER),1,bmp_in);

// READ PALETTE ----------------------------------------------
_lread(file_handle, &bitmap->palette,MAX_COLORS_PALETTE*sizeof(PALETTEENTRY));
*** Replaced with ***
fread(&bitmap->palette, MAX_COLORS_PALETTE*sizeof(PALETTEENTRY),1,bmp_in);

// SEEK END OF FILE (WHAT STARTED ALL THIS!) -----------------
_lseek(file_handle,-(int)(bitmap->bitmapinfoheader.biSizeImage),SEEK_END);
*** Replaced with ***
fseek( bmp_in, -(int)(bitmap->bitmapinfoheader.biSizeImage),SEEK_END);

// READ IN BITMAP IMAGE --------------------------------------
lread(file_handle,bitmap->buffer,bitmap->bitmapinfoheader.biSizeImage)
*** Replaced with ***
fread(bitmap->buffer, bitmap->bitmapinfoheader.biSizeImage, 1, bmp_in);

// FILE CLOSURE (Any reference to) ---------------------------
_lclose(file_handle)
*** Replaced with ***
fread(bitmap->buffer, bitmap->bitmapinfoheader.biSizeImage, 1, bmp_in);

------------------------------------------------------------------

And there you have it. I really hope this helps someone out, as it took me a while to get to this (as I am still a rookie coder) and was painful.

Cheers
Ryan

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