CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Mar 2010
    Location
    Aalten, Holland
    Posts
    14

    My selfmade game keeps crashing

    Well hello,

    I created myself a game. I runs alright with Debugger, but without debugger, it crashes immediately.
    I tried to find the error, with cout. After each function or something I type a line like "cout << "DIRECTX::LoadTexture()\n";" or something similiar.

    Anyway, here is a piece of code.

    Code:
    IDAdd  = GUI::AddChild("Button", "Add Message", 100, 20, 698, 117, WS_VISIBLE | WS_CHILD | BS_BITMAP | BS_FLAT);	
    IDEdit = GUI::AddChild("Edit", "", 695, 20, 2, 117, WS_VISIBLE | WS_CHILD | WS_BORDER);
    IDList = GUI::AddChild("Listbox", "", 796, 125, 2, 2, WS_VISIBLE | WS_CHILD | WS_BORDER | WS_TABSTOP | WS_VSCROLL | LBS_DISABLENOSCROLL);
    
    cout<< "GUI::AddChild() Done\n";
    
    SendMessage(Childs[IDAdd],  BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)(HANDLE)LoadImage(NULL, "Images/AddMessage.bmp", IMAGE_BITMAP, 100, 20, LR_LOADFROMFILE));
    SendMessage(Childs[IDEdit], WM_SETFONT, (WPARAM)CreateFontA(15, 0, 0, 0, 0, FALSE, 0, 0, 0, 0, 0, 0, 0, "Comic Sans MS"), FALSE);
    SendMessage(Childs[IDList], WM_SETFONT, (WPARAM)CreateFontA(15, 0, 0, 0, 0, FALSE, 0, 0, 0, 0, 0, 0, 0, "Comic Sans MS"), FALSE);
    
    cout << "SendMessage() Done\n";
    
    Oldproc = (PROC)SetWindowLongPtr(Childs[1], GWL_WNDPROC, (DWORD)EditProc);
    cout << "Oldproc\n";
    assert(Oldproc);
    SetFocus(MainWnd);
    
    cout << "SetFocus() Done\n";
    
    cout << "DIRECTX:\n";
    DirectX		= new DIRECTX(MainWnd); // Creating DirectX
    cout << "DirectX = new DIRECTX(MainWnd);\n";
    The output was:
    Quote Originally Posted by Output
    GUI::AddChild() Done
    SendMessage() Done
    Oldproc
    SetFocus() Done
    DIRECTX:
    Its really weird. Because it crashes at the part where DIRECTX: is initialized.
    But the weird part is this:
    Code:
    DIRECTX::DIRECTX(HWND Window) {      
    	cout << "DIRECTX::DIRECTX\n";
    	DIRECTX::counter		= 0;
    	cout << "DIRECTX::counter\n";
    	DIRECTX::DXWindow		= Window;
    	cout << "DIRECTX::DXWindow\n";
    	DIRECTX::Interface		= 0;
    	cout << "DIRECTX::Interace\n";
    	DIRECTX::Device		= 0;
    	DIRECTX::Sprite		= 0;
    
    	DIRECTX::InitInterface();
    	cout << "DIRECTX::InitInterface();\n";
    	DIRECTX::InitDevice();
    	cout << "DIRECTX::InitDevice();\n";
    	DIRECTX::InitSprite();
    	cout << "DIRECTX::InitSprite();\n";
    
    }
    This is the Constructor of DIRECTX. But it immidiatly crashes after coming in the constructor, it doesn't even cout DIRECTX:IRECTX() T___T.

    I'm so ****ing stuck, does ANYBODY had this problem before? I really need to fix it, I'm so frustrated.

  2. #2
    Join Date
    Apr 2009
    Posts
    598

    Re: My selfmade game keeps crashing

    Oldproc = (PROC)SetWindowLongPtr(Childs[1], GWL_WNDPROC, (DWORD)EditProc);
    What do you have in EditProc()? Can't you avoid changing the default function for your controls? Are you calling Oldproc() for messages you don't handle in EditProc()?

  3. #3
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: My selfmade game keeps crashing

    The way the app crashes in the constructor of DIRECTX indicates there is some memory corruption in your program, prior to that call.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  4. #4
    Join Date
    Mar 2010
    Location
    Aalten, Holland
    Posts
    14

    Re: My selfmade game keeps crashing

    Quote Originally Posted by olivthill2 View Post
    What do you have in EditProc()? Can't you avoid changing the default function for your controls? Are you calling Oldproc() for messages you don't handle in EditProc()?
    Hmm, that might be really good possible. Thanks alot, ill try it out when I'm at home!

    Quote Originally Posted by cilu View Post
    The way the app crashes in the constructor of DIRECTX indicates there is some memory corruption in your program, prior to that call.
    But how? Because the constructor seems to crash before even doing anything o_O. It crashes before setting counter to 0.

  5. #5
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: My selfmade game keeps crashing

    The constructor of the parentclass of your DIRECTX class could be crashing. No way to know for sure with the info given, you'll have to find that out for yourself.

  6. #6
    Join Date
    Mar 2010
    Location
    Aalten, Holland
    Posts
    14

    Re: My selfmade game keeps crashing

    Quote Originally Posted by OReubens View Post
    The constructor of the parentclass of your DIRECTX class could be crashing. No way to know for sure with the info given, you'll have to find that out for yourself.
    Yes i already know that. But there it wouldn't be possible for the constructor to crash without doing anything yet.

  7. #7
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: My selfmade game keeps crashing

    Quote Originally Posted by Pynolathgeen View Post
    Yes i already know that. But there it wouldn't be possible for the constructor to crash without doing anything yet.
    Yes it can.

    I runs alright with Debugger, but without debugger, it crashes immediately.
    The debugger creates a lot of extra space around allocated memory, and without this your app crashes. It sounds like memory corruption in some way. It's probably not your constructor that is crashing. Btw, how are you so sure it's the constructor ?

  8. #8
    Join Date
    Mar 2010
    Location
    Aalten, Holland
    Posts
    14

    Re: My selfmade game keeps crashing

    Quote Originally Posted by Skizmo View Post
    Yes it can.


    The debugger creates a lot of extra space around allocated memory, and without this your app crashes. It sounds like memory corruption in some way. It's probably not your constructor that is crashing. Btw, how are you so sure it's the constructor ?
    Well, I put a small line like "Cout << "function: DIRECTX()\n";" after each function and it stopped working after saying "Directx:", the line before the constructor is called...

  9. #9
    Join Date
    Mar 2010
    Location
    Aalten, Holland
    Posts
    14

    Re: My selfmade game keeps crashing

    YES! I GOT IT. THANKS ALOT olivthill2! It was indeed the EditProc. I tries to call OldProc, but Oldproc is not a WindowProc =P. THANKS!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured