|
Load Bitmap in VC++ |
Skax459
Member #8,290
February 2007
|
OK if you saw my other topic, I remade it because I forgot to title the other own. Sorry, sorry. Anyway, I'm trying to make a game and I'm trying to load some bitmaps. I'm using Visual C++ 8.0. I added the file as a reference, but it won't run. When I take out the little piece of bitmap loading code, it works fine. When its in, it returns this error: (The game is Zylin) Unhandled exception at 0x10042eaa in Zylin.exe: 0xC0000005: Access violation reading location 0x00000000. after that, it says: No symbols are loaded for any call stack frame. The source code cannot be displayed. The code is:
Anyone know why? |
Kitty Cat
Member #2,815
October 2002
|
Quote: allegro_message("Error loading %s", h_sprite);
h_sprite is the BITMAP* (which has evaluated to NULL/0x00000000 to get there), not the filename. -- |
Skax459
Member #8,290
February 2007
|
Yay! Thanks! Well, it doesn't crash, but I still don't know if it works...::) EDIT: I change my previous opinion. I altered the code to this:
And now it returns this: Unhandled exception at 0x10004d4d in Zylin.exe: 0xC0000005: Access violation reading location 0x00000000. Its the addition of the line with blit that causes the problem- without that it runs fine. Its similar to the first time, and I've never done bitmaps and stuff yet...mainly graphics primitives. |
Kitty Cat
Member #2,815
October 2002
|
Quote: I think you goofed a bit there. And you should probably the filename variable to a const char*, since that's what a string literal is. -- |
Skax459
Member #8,290
February 2007
|
Um...what did I goof? |
Kitty Cat
Member #2,815
October 2002
|
hsprite_name is the pointer to the filename, which since you explicitly set it to a string literal, will never be NULL. You want to check load_bitmap's return value, h_sprite. -- |
Skax459
Member #8,290
February 2007
|
Sonova...now it runs, but it says "Error loading h_sprite.bmp" |
bamccaig
Member #7,536
July 2006
|
You are dereferencing NULL (referencing the data pointed to by a pointer that is set to NULL). I just had a long thread about it and got very good explanations of what is going on and why. It might help you out since you seem to be having the same problem: http://allegro.cc/forums/thread/590183 Pretty much if you see an "access violation" it means your program is trying to access memory that is not allocated to it. If the address is 0x00000000 then that is 0 or NULL and you can assume you are trying to access data pointed to by a pointer somewhere that is set to NULL.
It appears that the BITMAP you are trying to blit() is NULL, which means the load failed and likely the path/filename you supplied load_bitmap() is wrong (or something else is wrong - i.e. read permissions). EDIT In VC++ 7.1 I have to start relative paths to files from the same directory as my project files. Make sure that h_sprite.bmp is in the same directory as your project files (.sln, .vcproj, etc.). -- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
Kitty Cat
Member #2,815
October 2002
|
Quote: Sonova...now it runs, but it says "Error loading h_sprite.bmp" Make sure you're looking in the right directory. IDEs really like to run programs from odd directories, so something to do is to chdir to where your exe is (using get_executable_name), then do everything relative to there. -- |
Skax459
Member #8,290
February 2007
|
Should I put the pictures in the same folder as the executable? Because that isn't working. |
bamccaig
Member #7,536
July 2006
|
Quote: In VC++ 7.1 I have to start relative paths to files from the same directory as my project files. Make sure that h_sprite.bmp is in the same directory as your project files (.sln, .vcproj, etc.). The image needs to be in the pwd, or present working directory. When running from within VC++ I think the pwd is the project directory (folder). So if you had a project named MyProject in C:\Documents and Settings\%USERNAME%\My Documents\Visual Studio Projects\, you would want the image file located in C:\Documents and Settings\%USERNAME%\My Documents\Visual Studio Projects\MyProject\ when running from VC++ and in whatever directory the executable is located when executing it from Windows. i.e. "C:\Documents and Settings\%USERNAME%\My Documents\Visual Studio Projects\MyProject\h_sprite.bmp" -- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
Skax459
Member #8,290
February 2007
|
Yay! Thanks to all who helped! Now all I need is to take this little bit of information and make it into a game. ...:P EDIT: I actually drew the game map and I'm really excited...it runs. Whooo. |
|