OpenGL + WinXP woes..

Started by
8 comments, last by Klopper 21 years, 8 months ago
Im having a problem with an OGL application im attempting to run. It crashes when ran, and the line its pointing to is: int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { And when I debug it, the error says: "The instruction at "0x77e6163c" refenced memory at "0xcccccccc". The memory could not be "written". Any idea on what might cause this? I will post the rest of the source if needed. thanks [edited by - Klopper on July 26, 2002 3:10:04 PM]
Advertisement
That message sounds like your trying to write to a NULL pointer somehow, post your winmain function.
Here is my WinMain function...


  int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd){    fwndHeight = GetSystemMetrics(SM_CYSCREEN); //Get height of screen resolution    fwndWidth = GetSystemMetrics(SM_CXSCREEN);  //Get width of screen resolution    WNDCLASSEX windowClass;             MSG        msg;             bool       done;            RECT windowRect;    DWORD dwExStyle;    DWORD dwStyle;    LPSYSTEMTIME time; // System time    // Start log with date    FILE *log = fopen("log.txt", "w");        // Get time info and print it    GetSystemTime(time);    fprintf(log, "-My Game Template- Run Log\n\n");    fprintf(log, "Logged: %d:%d %d/%d/%d\n", time->wHour-7, time->wMinute, time->wMonth, time->wDay, time->wYear);    if(MessageBox(NULL, "Would you like to run in fullscreen?", "Display Settings,", MB_YESNO|MB_ICONQUESTION)==IDNO)                {                    fullscreen = false;                }    windowRect.left = (long)0;    windowRect.right = (long)fwndWidth;    windowRect.top = (long)0;    windowRect.bottom = (long)fwndHeight;    windowClass.cbSize          = sizeof(WNDCLASSEX);    windowClass.style           = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;    windowClass.lpfnWndProc     = WndProc;    windowClass.cbClsExtra      = 0;    windowClass.cbWndExtra      = 0;    windowClass.hInstance       = hInstance;    windowClass.hIcon           = LoadIcon(NULL, IDI_APPLICATION);              windowClass.hCursor         = LoadCursor(NULL, IDC_ARROW);              windowClass.hbrBackground   = NULL;    windowClass.lpszMenuName    = NULL;                                     windowClass.lpszClassName   = className;    windowClass.hIconSm         = LoadIcon(NULL, IDI_WINLOGO);              if (!RegisterClassEx(&windowClass))    {        fprintf(log, "\nCreating window...          [ FAILED ]");        return 0;    }    fprintf(log, "\nCreating window...          [ OK ]");            if(fullscreen)    {        DEVMODE dm; //device mode        memset(&dm, 0, sizeof(dm));        dm.dmSize = sizeof(dm);        dm.dmPelsWidth = fwndWidth;        dm.dmPelsHeight = fwndHeight;        dm.dmBitsPerPel = fwndBits;        dm.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;            if(ChangeDisplaySettings(&dm, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)        {            //switch to windowed mode            MessageBox(NULL,                 "The display settings requires 16-bits per pixel.\nCombat Platoon will continue in windowed mode.", "Display Error", MB_OK);            fullscreen = false;        }    }        if(fullscreen)        {            dwExStyle = WS_EX_APPWINDOW;            dwStyle = WS_POPUP;           // simple window with no borders or title bar            ShowCursor(FALSE);            // hide the cursor for now        }        else        {            dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;            dwStyle = WS_OVERLAPPEDWINDOW;        }        AdjustWindowRectEx(&windowRect, dwStyle, FALSE, dwExStyle);    hwnd = CreateWindowEx(dwExStyle,                                                          className,                                              windowTitle,                            dwStyle | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,                          0, 0,                                                   windowRect.right - windowRect.left,                                                     windowRect.bottom - windowRect.top,                                                     NULL,                          NULL,                          hInstance,                                                  NULL);    if (!hwnd)        return 0;    ShowWindow(hwnd, SW_SHOW);    UpdateWindow(hwnd);    done = false;        fclose(log); // Close our log    while (!done)    {        PeekMessage(&msg, hwnd, NULL, NULL, PM_REMOVE);        if (msg.message == WM_QUIT)         {            done = true;            engine.CleanUp();        }        else        {                 // Draw our game                 engine.RenderScene();            SwapBuffers(g_HDC);             TranslateMessage(&msg);             DispatchMessage(&msg);        }    }    if(fullscreen)    {        ChangeDisplaySettings(NULL, 0); //switch back to desktop        ShowCursor(TRUE);    }return msg.wParam;}   


[edited by - klopper on July 27, 2002 3:10:57 AM]

[edited by - klopper on July 27, 2002 3:12:43 AM]
It looks like GetSystemTime is your culprit. You are passing it a pointer to unallocated space. Try this:

SYSTEMTIME time;
GetSystemTime(&time);

This should fix it.
quote:Original post by strtok
It looks like GetSystemTime is your culprit. You are passing it a pointer to unallocated space. Try this:

SYSTEMTIME time;
GetSystemTime(&time);

This should fix it.


I get this error when I run that..

c:\documents and settings\zach\desktop\projects\2dogl\main.cpp(100) : error C2664: 'GetSystemTime' : cannot convert parameter 1 from 'struct _SYSTEMTIME ** ' to 'struct _SYSTEMTIME *'

UPDATE: When I comment those lines out, it compiles and runs fine. Any idea on how I can get the system time?


[edited by - Klopper on July 27, 2002 3:24:31 PM]
quote:Original post by Klopper
Original post by strtok
It looks like GetSystemTime is your culprit. You are passing it a pointer to unallocated space. Try this:

SYSTEMTIME time;
GetSystemTime(&time);

This should fix it.


I get this error when I run that..

c:\documents and settings\zach\desktop\projects\2dogl\main.cpp(100) : error C2664: ''GetSystemTime'' : cannot convert parameter 1 from ''struct _SYSTEMTIME ** '' to ''struct _SYSTEMTIME *''

UPDATE: When I comment those lines out, it compiles and runs fine. Any idea on how I can get the system time?


[edited by - Klopper on July 27, 2002 3:24:31 PM]

GetSystemTime (time) ….

Metal Typhoon
Metal Typhoon
Make sure you''re not defining time as a pointer.
i.e. don''t define it like this
LPSYSTEMTIME time;
or
SYSTEMTIME time;

Instead you must define it like this

SYSTEMTIME time;

and then when you pass it to GetSystemTime you must pass the address of time, &time. So like this

GetSystemTime(&time);

GetSystemTime takes a pointer to a SYSTEMTIME structure, but if you simply define time as a pointer, it won''t be pointing to a SYSTEMTIME struct.

I think that should solve all your troubles.

Ian Halliday yo
PWEENED
Ian Halliday yoPWEENED
quote:Original post by Billymon
Make sure you''re not defining time as a pointer.

SYSTEMTIME time;

and then when you pass it to GetSystemTime you must pass the address of time, &time. So like this

GetSystemTime(&time);

GetSystemTime takes a pointer to a SYSTEMTIME structure, but if you simply define time as a pointer, it won''t be pointing to a SYSTEMTIME struct.



When I use what you said, I get about 10 errors:


  c:\documents and settings\zach\desktop\projects\2dogl\main.cpp(102) : error C2819: type ''_SYSTEMTIME'' does not have an overloaded member ''operator ->''        d:\program files\microsoft visual studio\vc98\include\winbase.h(249) : see declaration of ''_SYSTEMTIME''c:\documents and settings\zach\desktop\projects\2dogl\main.cpp(102) : error C2227: left of ''->wHour'' must point to class/struct/unionc:\documents and settings\zach\desktop\projects\2dogl\main.cpp(102) : error C2819: type ''_SYSTEMTIME'' does not have an overloaded member ''operator ->''        d:\program files\microsoft visual studio\vc98\include\winbase.h(249) : see declaration of ''_SYSTEMTIME''c:\documents and settings\zach\desktop\projects\2dogl\main.cpp(102) : error C2227: left of ''->wMinute'' must point to class/struct/unionc:\documents and settings\zach\desktop\projects\2dogl\main.cpp(102) : error C2819: type ''_SYSTEMTIME'' does not have an overloaded member ''operator ->''        d:\program files\microsoft visual studio\vc98\include\winbase.h(249) : see declaration of ''_SYSTEMTIME''c:\documents and settings\zach\desktop\projects\2dogl\main.cpp(102) : error C2227: left of ''->wMonth'' must point to class/struct/unionc:\documents and settings\zach\desktop\projects\2dogl\main.cpp(102) : error C2819: type ''_SYSTEMTIME'' does not have an overloaded member ''operator ->''        d:\program files\microsoft visual studio\vc98\include\winbase.h(249) : see declaration of ''_SYSTEMTIME''c:\documents and settings\zach\desktop\projects\2dogl\main.cpp(102) : error C2227: left of ''->wDay'' must point to class/struct/unionc:\documents and settings\zach\desktop\projects\2dogl\main.cpp(102) : error C2819: type ''_SYSTEMTIME'' does not have an overloaded member ''operator ->''        d:\program files\microsoft visual studio\vc98\include\winbase.h(249) : see declaration of ''_SYSTEMTIME''c:\documents and settings\zach\desktop\projects\2dogl\main.cpp(102) : error C2227: left of ''->wYear'' must point to class/struct/union  
ah, heh. Those errors are because you were originally writing your program with time as a pointer, but now you''ve changed it to a normal object.

To access members of a pointer, you need to use the -> (arrow) operator, as you''ve obviously done in your program.

To access members of a normal object, you use the . (dot) operator. So simply change all your time-> to time.

ptr->member is equivalent to (*ptr).member, -> is just shorthand

here''s an article on pointers if you''d like to learn more about them
http://www.gamedev.net/reference/articles/article1697.asp

I hope this time i''ve solved all your problems


Ian Halliday yo
PWEENED
Ian Halliday yoPWEENED
Thanks very much, works perfectly now.

This topic is closed to new replies.

Advertisement