Page 1 of 3 123 LastLast
Results 1 to 10 of 27

Thread: Win32 - Memory Allocation

  1. #1
    Member Contributor
    Join Date
    Jun 2001
    Posts
    54

    Win32 - Memory Allocation

    Hi,
    This question is mainly about windows, i have a

    #define MAX_SIZE 125000

    that i use for array sizes to store data read from a text file. Now when i define array, that use more than 250000, my program crashes just after opening the OGL window.

    GLfloat rectangles[MAX_SIZE];
    GLfloat triangles[MAX_SIZE];
    GLfloat quadColours[MAX_SIZE];
    GLfloat triColours[MAX_SIZE];

    Above are my declarations, any idea what is happening or any advice would be most grateful.

    Thanks, Paul

  2. #2
    Member Newbie
    Join Date
    Mar 2001
    Location
    .., ..., ...
    Posts
    31

    Re: Win32 - Memory Allocation

    Hi there,
    Why don't you allocate memory for your arrays dynamically?

    Like:
    GLfloat *rectangles=new GLfloat[num_of_rectangles];
    ...

    My wild guess (Just thinking about old dos problems):
    Your "solution" uses MAX_SIZE * 4 * sizeof(GLfloat) bytes for the arrays on the heap (somebody, correct me if i'm wrong). "My" "solution" uses 4 * sizeof(GLfloat) bytes for the arrays on the heap and the dynamic memory somewhere else (dunno *g*). I guess the heap is limited somehow in OS, while the other memory is limited by your RAM...

    Please correct me if i am wrong, thx
    It does not matter who is right, when there is no one left!!!

  3. #3
    Senior Member Regular Contributor
    Join Date
    Feb 2001
    Location
    Australia
    Posts
    431

    Re: Win32 - Memory Allocation

    Does the crash happen when you're trying to read from the files? Or before? One of the most valuable tips I can pass on if you don't know where is the line: std::cout << "Here in file: " << __FILE__ << ", line: " << __LINE__ << std::endl;
    Good old stdout debugging

    Unless you have a _very_ old computer, you won't be running out of RAM. I would guess it's an access violation. What error do you get? Also, have you thought about using the C++ STL vector container. I use them probably more than arrays and they're very handy - no more buffer overflows. They may be a fraction slower (or maybe a lot) but their usefulness makes up for it.

    <edit>BTW Geniuz, you've got your memories mixed up. Heap memory is dynamically allocated, stack memory managed by the system </edit>

    [This message has been edited by ffish (edited 06-18-2001).]

  4. #4
    Member Contributor
    Join Date
    Jun 2001
    Posts
    54

    Re: Win32 - Memory Allocation

    Hi,
    When the program crashes, i am left with the following,

    Loaded 'C:\WINDOWS\SYSTEM\WINMM.DLL', no matching symbolic information found.
    Loaded 'C:\WINDOWS\SYSTEM\glut32.dll', no matching symbolic information found.
    Loaded 'C:\WINDOWS\SYSTEM\DCIMAN32.DLL', no matching symbolic information found.
    Loaded 'C:\WINDOWS\SYSTEM\USER32.DLL', no matching symbolic information found.
    Loaded 'C:\WINDOWS\SYSTEM\GLU32.DLL', no matching symbolic information found.
    Loaded 'C:\WINDOWS\SYSTEM\GDI32.DLL', no matching symbolic information found.
    Loaded 'C:\WINDOWS\SYSTEM\ADVAPI32.DLL', no matching symbolic information found.
    Loaded 'C:\WINDOWS\SYSTEM\KERNEL32.DLL', no matching symbolic information found.
    Loaded 'C:\WINDOWS\SYSTEM\CRTDLL.DLL', no matching symbolic information found.
    Loaded 'C:\WINDOWS\SYSTEM\OPENGL32.DLL', no matching symbolic information found.
    Loaded 'C:\WINDOWS\SYSTEM\VERSION.DLL', no matching symbolic information found.
    Loaded 'C:\WINDOWS\SYSTEM\NTDLL.DLL', no matching symbolic information found.
    Loaded 'C:\WINDOWS\SYSTEM\DDRAW.DLL', no matching symbolic information found.
    Loaded 'C:\WINDOWS\SYSTEM\NVARCH32.DLL', no matching symbolic information found.
    Loaded 'C:\WINDOWS\SYSTEM\NVOPENGL.DLL', no matching symbolic information found.
    First-chance exception in My Game V01.exe (NVOPENGL.DLL): 0xC0000005: Access Violation.
    First-chance exception in My Game V01.exe (NVOPENGL.DLL): 0xC0000005: Access Violation.
    First-chance exception in My Game V01.exe (NVOPENGL.DLL): 0xC0000005: Access Violation.
    The program 'C:\Windows\Desktop\OpenGL\Projects\My Game V01\Debug\My Game V01.exe' has exited with code 0 (0x0).

    [This message has been edited by Zeus_666 (edited 06-18-2001).]

  5. #5
    Senior Member Regular Contributor
    Join Date
    Feb 2001
    Location
    Australia
    Posts
    431

    Re: Win32 - Memory Allocation

    Hmmm, <scratches chin/> first thoughts were an access violation, but not in NVOpenGL.dll. I don't know without debugging it. You can send it to me if you like (e-mail in profile) but I won't look at it until tomorrow (exam in the morning) or you can debug it yourself (much more valuable to you).

    If you want to do it yourself, stick descriptive printf/cout statements (like my post above) in places where you think the problem might be. Find the exact line where the error occurs in your source and try to determine the source of the error. Make sure you know what the program state should be before and after the error. If the problem is an OpenGL one, become familiar with glGetError(). Also, become familiar with a good debugger. VC++'s one is quite good.

    Debugging and rigorous testing suck, but they are the best way to learn how to program better. <rant>Buy a book on testing and learn how to do unit testing, structural testing, integration testing, etc</rant>.

    Cheers.

    <edit>Oh, now that you've edited it I see it's a different problem. I would think it's a project settings problem, maybe. Try starting a new project then add your source files to it. Again, you're welcome to send the source to me (zipfile or .tar.gz, e-mail in profile, remove the nospam part from the address)</edit>

    [This message has been edited by ffish (edited 06-18-2001).]

  6. #6
    Member Contributor
    Join Date
    Jun 2001
    Posts
    54

    Re: Win32 - Memory Allocation

    Hi,
    Ok, step by step debugging as i hate it. After commenting out line after line (i will make fewer changes in one go next time) i have discovered that the error is caused by the addition of the line

    glEnableClientState(GL_COLOR_ARRAY);

    When my program tries to draw and this line is uncommented, the program will crash.

    ----------------------------------------
    O, while you are still online, i would like to thank you for your help today as you appear to have been online all day and Good luck in the exam tomorrow.
    ----------------------------------------

    Thanks, Paul

  7. #7
    Senior Member Regular Contributor
    Join Date
    Nov 2000
    Location
    Dunblane, Scotland
    Posts
    333

    Re: Win32 - Memory Allocation

    Does any one no what the lines like this

    Loaded 'C:\WINDOWS\SYSTEM\DDRAW.DLL', no matching symbolic information found.

    are all about? I have them everywhere in my progams, don't think it is a problem.


    As for the problem in hand (well on the monitor) I don't really know, it sounds like an Opnegl problem but they don't really exist and are certainly very rare. Have you got the latest drivers?

    Tim
    Reality is for idiots only the best over come it!

  8. #8
    Member Contributor
    Join Date
    Jun 2001
    Posts
    54

    Re: Win32 - Memory Allocation

    Hi,
    If you mean for my graphics card, i have the latest Nvidia Geforce 2 drivers but not the latest Detonator driver's.

  9. #9
    Senior Member Regular Contributor
    Join Date
    Feb 2001
    Location
    Australia
    Posts
    431

    Re: Win32 - Memory Allocation

    <Changes mind again/>That information comes from the bottom line in your debugger, right? I get that "no matching ... " crap too. It's the line with the access violation that is important.

    Although glEnableClientState shouldn't produce errors like this often, I do remember having problems with it in the past. Can you post, step by step, how you set up your vertex arrays, and how you render them? I would think that your vertex array is trying to render from an array where you are trying to go outside the array's bounds. I'd almost put money on it, in fact. I want to know how you fill up your array with data, how you let OpenGL know where the data is (gl{Vertex/Color/etc}Pointer), the rendering function (glDraw{Elements/Arrays}) and the location of all of these relative to each other.

    It can't hurt to download the latest drivers (Det 12.60?) if you have the time also.

    Tim, that line is the secret line that tells us OpenGL is just a clever wrapper for Direct Draw

  10. #10
    Member Contributor
    Join Date
    Jun 2001
    Posts
    54

    Re: Win32 - Memory Allocation

    Hi,
    Below is all the code applicable

    int numberRectangles;
    int numberTriangles;

    GLfloat rectangles[MAX_SIZE];
    GLfloat triangles[MAX_SIZE];
    GLfloat quadColours[MAX_SIZE];
    GLfloat triColours[MAX_SIZE];

    -----------------------------------

    void init (void)
    {
    glShadeModel(GL_SMOOTH);
    glEnable(GL_DEPTH_TEST);
    glEnableClientState(GL_VERTEX_ARRAY);
    //glEnableClientState(GL_NORMAL_ARRAY);
    glEnableClientState(GL_COLOR_ARRAY);
    }

    -----------------------------------

    void OpenMapAndParse ()
    {
    ifstream fin; //FILE POINTER TO MAP FILE
    // float rectangles[MAX_SIZE];
    int i;

    fin.open("map1.map"); //OPEN THE FILE

    //GET WORLD DATA
    fin >> worldWidth;
    fin >> worldDepth;
    fin >> numberRectangles;
    fin >> numberTriangles;

    //READ RECTANGLE VERTEX DATA
    for(i = 0; i < (12 * numberRectangles); i++)
    fin >> rectangles[i];

    //READ TRIANGLE VERTEX DATA
    for(i = 0; i < (9 * numberTriangles); i++)
    fin >> triangles[i];

    //READ QUAD COLOURS DATA
    for(i = 0; i < (12 * numberRectangles); i++)
    fin >> quadColours[i];

    for(i = 0; i < (9 * numberRectangles); i++)
    fin >> triColours[i];


    fin.close(); //CLOSE THE FILE
    }

    -----------------------------------

    int main(int argc, char** argv)
    {
    //C++ STUFF 1ST
    OpenMapAndParse ();

    if (worldWidth > worldDepth)
    visabilityRange = worldWidth + 10;

    if (worldDepth > worldWidth)
    visabilityRange = worldDepth + 10;

    //OPENGL STUFF 2ND
    glutInit ( &argc, argv );
    glutInitDisplayMode ( GLUT_DOUBLE | GLUT_RGB );
    glutInitWindowSize ( 700, 700 );
    glutInitWindowPosition ( 100, 100 );
    glutCreateWindow ( "hello" );
    init ();
    glutDisplayFunc ( display );
    glutReshapeFunc ( reshape );
    glutKeyboardFunc ( keyboard );
    glutSpecialFunc ( keyboardSpecial );
    glutMainLoop ();
    return 0;
    }

    -----------------------------------

    That is a large part of my code, It appears to be working now though, I think it may have something to do with the leaving out of the glColorPointer, i had not placed that line in at the time. The map data is as follows now:

    60
    40
    7
    4

    -25.0 6.0 -5.0 -25.0 6.0 -35.0 -25.0 -1.0 -35.0 -25.0 -1.0 -5.0
    25.0 6.0 -35.0 -25.0 6.0 -35.0 -25.0 -1.0 -35.0 25.0 -1.0 -35.0
    25.0 6.0 -5.0 25.0 6.0 -35.0 25.0 -1.0 -35.0 25.0 -1.0 -5.0
    25.0 6.0 -5.0 2.0 6.0 -5.0 2.0 -1.0 -5.0 25.0 -1.0 -5.0
    2.0 6.0 -5.0 -5.0 6.0 -5.0 -5.0 3.0 -5.0 2.0 3.0 -5.0
    -2.0 6.0 -5.0 -25.0 6.0 -5.0 -25.0 -1.0 -5.0 -2.0 -1.0 -5.0

    12.0 2.0 -5.0 12.0 2.0 -14.0 12.0 -1.0 -14.0 12.0 -1.0 -5.0


    -25.0 6.0 -35.0 -25.0 6.0 -5.0 0.0 12.0 -20.0
    -25.0 6.0 -35.0 25.0 6.0 -35.0 0.0 12.0 -20.0
    25.0 6.0 -35.0 25.0 6.0 -5.0 0.0 12.0 -20.0
    -25.0 6.0 -5.0 25.0 6.0 -5.0 0.0 12.0 -20.0

    1.0 0.0 0.0 1.0 0.0 0.0 1.0 0.0 0.0 1.0 0.0 0.0
    1.0 0.0 0.0 1.0 0.0 0.0 1.0 0.0 0.0 1.0 0.0 0.0
    1.0 0.0 0.0 1.0 0.0 0.0 1.0 0.0 0.0 1.0 0.0 0.0
    1.0 0.0 0.0 1.0 0.0 0.0 1.0 0.0 0.0 1.0 0.0 0.0
    1.0 0.0 0.0 1.0 0.0 0.0 1.0 0.0 0.0 1.0 0.0 0.0
    1.0 0.0 0.0 1.0 0.0 0.0 1.0 0.0 0.0 1.0 0.0 0.0

    0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0

    1.0 1.0 0.0 1.0 1.0 0.0 1.0 1.0 1.0
    1.0 1.0 0.0 1.0 1.0 0.0 1.0 1.0 1.0
    1.0 1.0 0.0 1.0 1.0 0.0 1.0 1.0 1.0
    1.0 1.0 0.0 1.0 1.0 0.0 1.0 1.0 1.0

    Thanks, Paul

Page 1 of 3 123 LastLast

Similar Threads

  1. Dynamic memory allocation
    By scagja in forum OpenGL: GLSL
    Replies: 3
    Last Post: 06-13-2009, 02:40 PM
  2. vbo and memory allocation
    By Bruno in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 11-10-2004, 01:22 AM
  3. VAR memory allocation
    By omaha_os3 in forum OpenGL: Advanced Coding
    Replies: 6
    Last Post: 01-08-2002, 08:12 AM
  4. AGP memory allocation problem
    By Olive in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 05-27-2001, 11:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean