   A bit of DirectX Help - Solved!
  Edit: Thanks a ton to those that helped!!! Greatly appreciated.Alright, I know we're not supposed to post stuff that we're working on for school in these threads a la the No Homework Posts rule. I understand that, but I'm not asking for anyone to do my homework either. However, I'm completely lost at an exception that my program keeps throwing at me. Just a quick preface, we're just trying to get an asteroid to bounce around the screen haphazardly. This isn't anything big to me at all, I've already made a breakout clone with DirectX, and I'm working on various other things with it as well. However, it's all been pretty sloppy code, because I've been learning from the Beginning Game Programming book. That book doesn't use classes at all, and so far, neither does my class that I'm in. I wanna get a headstart on making this junk work in classes, and thus here I am now, in a rut. Damn thing worked before I decided to start using classes, and tried avoiding the mess of global variables in that book/class.Anyways, that being said, you can choose to respond or not or lock this thread, I felt this was a bit of a grey area. Here's the exception: "Unhandled exception at 0x004125e4 in f4ntweek2.exe: 0xC0000005: Access violation reading location 0x00000000."It occurs here:LPDIRECT3DSURFACE9 D3D::LoadSurface(char *filename, D3DCOLOR transcolor){LPDIRECT3DSURFACE9 image = NULL;D3DXIMAGE_INFO info;HRESULT result;//get bitmap inforesult = D3DXGetImageInfoFromFile(filename, &info);if(result != D3D_OK)return NULL;//create surfaceresult = d3ddev->CreateOffscreenPlainSurface(info.Width,info.Height,D3DFMT_X8R8G8B8,D3DPOOL_DEFAULT,&image,NULL); //Right here!!if(result != D3D_OK)return NULL;result = D3DXLoadSurfaceFromFile(image,NULL,NULL,filename,NULL,D3DX_DEFAULT,transcolor,NULL);if(result != D3D_OK)return NULL;return image;}Here's where the above function gets called:int Game::Game_Init(HWND hwnd){asteroid.x = 150;asteroid.y = 200;asteroid.movex = 5;asteroid.movey = 5;asteroid.height = 139;asteroid.width = 86;//MessageBox(hwnd, "Check", "Check", MB_OK);background = dev.LoadSurface("star.bmp", NULL);if(background == NULL){MessageBox(hwnd, "Stupid Image", "Image", MB_OK);return 0;}asteroid_image = dev.LoadTexture("asteroid.bmp", D3DCOLOR_XRGB(0,0,0));if(asteroid_image == NULL){MessageBox(hwnd, "Stupid Image1", "Image", MB_OK);return 0;}MessageBox(hwnd, "Check", "Check", MB_OK);result = D3DXCreateSprite(dev.d3ddev, &sprite_handler);return 1;}Any HINTS/help would be amazingly well appreciated. I want to know why this is throwing an exception, not just a quick fix. Thanks![Edited by - f4nt on May 31, 2006 4:52:38 PM]
  Is d3ddev == NULL perhaps?   ;  have you checked what the HRESULT code is?  That is usually a big help.  Use D3DXErrorLookup Util...;  Yeah, what Mite51 said... d3ddev == NULL, where is that beeing assigned?  Is it a global?  Is it a member?  If it's either one, I like using Hungarian notation...I.E. member pointer -> m_pd3ddev;gloable pointer -> g_pd3ddev;   ;  Alright, thanks a ton peeps! I still haven't solved it, but at least I know what the problem is.. d3ddev == NULL! The problem is that in my winmain file, d3ddev checks out fine all the way through.. It's in my game code that d3ddev suddenly becomes NULL, which I can't make sense of.. See in my winmain.cpp I have this:D3D dev;Game game(dev);//Is that what I'm doing wrong? Should it be more like this:D3D *dev = new D3d();Game *game = new Game(*dev);Is that right/wrong/otherwise? I'm guessing that I'm passing the object across to game incorrectly, and that it's getting a copy of my D3D class.. Instead of the actual object.. Right?edit:: The only problem with the above "solution" is that I'm having problems passing the object over as a pointer. No matter how I try to do it, the compiler complains about converting it or something.. What am I doing wrong?[Edited by - f4nt on May 31, 2006 2:50:29 PM]