Skip to main content
GameDev.net gamedev.net
🔒 Locked

Game menu system, null reference error

Started by siferion Oct 29, 2005 at 5:00 PM 2 replies 900+ views
Original Post
siferion
siferion
I am new to GDI+ api and decided to do a small game menu system. After a couple hours of reading and coding, I got all the bugs I could figure out fixed, but now i'm stumped at this one, but think I have an idea of what is going wrong. Here is the code i'm using, the part in question at least: { hDC = BeginPaint(hwnd, &Ps); WCHAR wcTxt[] = L"Test"; Graphics *gs = new Graphics(hDC); // menu images Image background(L"Menu/background.jpg"); Image top(L"Menu/top.jpg"); Image bottom(L"Menu/top.jpg"); Image csheet(L"Menu/charsheet.jpg"); // font settings Font font(L"Arial", 36, FontstyleRegular); PointF pointF(30.0f, 30.0f); SolidBrush solidBrush(Color(0, 0, 255, 255)); gs->DrawString(wcTxt, lstrlenW(wcTxt), &font, pointF, &solidBrush); gs->DrawImage(&background, 0, 0); gs->DrawImage(⊤, 15, 15); gs->DrawImage(⊥, 15, 535); for(int i = 0; i < charIndex; i++) gs->DrawImage(&csheet, 25 + (250 * i), 63); delete gs; EndPaint(hwnd, &Ps); } That is in WM_PAINT like it belongs, everywhere else my code is good, i can comment the entire section out and the program will run fine(minus the menu that is non existant). I think my problem is with the images for my menu, i am thinking i am going about loading them wrong or something similar to that, but could be wrong. The image are there, and i have displayed them using win32 itself so i know the images themselves arn't the problem, les the format is unsupported by gdi+. If anyone is able to provide help, i would appreciate it because i've been stuck on this part for little over an hour.
JohnBolton
JohnBolton
You forgot to mention what the problem is.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
siferion
siferion
Heh guess I did, well it compiles with no error or warning, but when I load the menu it paints the window black(which is the first thing i did for menu) then gives me a NullReferenceError before loading a single image onto the screen. When I load the debuger it jumps to gdiplusbitmap library, the part where it loads the image based on filename.

Edit: Even when I comment out the graphic lines, the DrawString function also gives a System.NullReferenceException error, I've read almost everything about gdi+ that is on msdn now and I still can't figure this out.

The error message that the debugger brings up is this:
"An unhandled exception of type 'System.NullReferenceException' occurred in Game.exe

Additional information: Object reference not set to an instance of an object."

[Edited by - siferion on October 29, 2005 11:50:31 PM]
siferion
siferion
I finally figured it out, the way i was calling hInstance in my WinMain was causing problems with gdi+. Now i just need to figure out how to draw text on top of the images.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.