C++ Unhandled exception error
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 24

Thread: C++ Unhandled exception error

  1. #1
    Join Date
    Sep 2010
    Posts
    13

    C++ Unhandled exception error

    Hi everybody

    I defined an array pointer to hold a massive amount of data, (actually the RGB data of a screen with 1024*768 pixels). the data is assigned from another temporary array to the this array within a function that calculates the values of the temporary array and then assign them to the global one using FOR loops. the global array values should be kept saved to be used in an OpenGL function as a store of an image data and then display the image on the screen.

    when I run the program, the program works fine until it reaches a specific row number of the screen rows (row number 16 of 128 rows) and crash giving the following message:

    Unhandled exception at 0x7c812afb in OPENGL_.....exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0012fbb4..

    any one can help me in this please?
    how can I get rid of this error and make the program works?
    I get the same message when I add a delete function (delete [] pixels_index to delete the array of pointers, for that reason I think the problem is about the array (pixels_index)

    many thanks in advance

    here is parts of the OpenGL code in C++ environment:
    Code:
    
    int main(int argc, char** argv) {
    	glutInit(&argc, argv);
    
    	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);	
    	glutInitWindowSize(1024, 768);
    	
    
    
    	glutCreateWindow("OPENGL_BRUNEL");
    	
    	initRendering();
    	glutDisplayFunc(drawScene);
    	
    	
    	glViewport(0, 0, 1024, 768);
    	glMatrixMode(GL_PROJECTION);
    	glLoadIdentity();
    	glFrustum(-1.0 , 1.0, -1.0, 1.0, 3, 200);
    
    
    	glutTimerFunc(2500, update, 0);
    
    	
    	glutMainLoop();
             delete [] pixels_index;
    	return 0;
    }
    Last edited by Yohanna; October 6th, 2010 at 10:19 PM.

  2. #2
    Join Date
    Jun 2009
    Location
    oklahoma
    Posts
    199

    Re: C++ Unhandled exception error

    If you want someone to even read your post, replace your code using the [ code ] tags so its actually readable.

  3. #3
    Join Date
    Sep 2010
    Posts
    13

    Re: C++ Unhandled exception error

    Quote Originally Posted by jnmacd View Post
    If you want someone to even read your post, replace your code using the [ code ] tags so its actually readable.

    Thank you for reply

    I wonder how to do that, I used code as a tag but it does not look correct

  4. #4
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,392

    Re: C++ Unhandled exception error

    Please, don't duplicate your posts, edit your OP instead.
    And read here about tags and other useful features
    Victor Nijegorodov

  5. #5
    Join Date
    May 2009
    Location
    Bengaluru, India
    Posts
    422

    Re: C++ Unhandled exception error

    us elike this ""
    Code:
      ...
    ""

  6. #6
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,392

    Re: C++ Unhandled exception error

    Quote Originally Posted by vcdebugger View Post
    us elike this ""
    Code:
      ...
    ""
    You should have replaced you duplicated quotation marks with noparse tags:

    [CODE] ...[/CODE]
    Victor Nijegorodov

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

    Re: C++ Unhandled exception error

    Unhandled exception at 0x7c812afb in OPENGL_.....exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0012fbb4..
    What does the debugger tell you about the crash ? And where does it happen ?

  8. #8
    Join Date
    Sep 2010
    Posts
    13

    Re: C++ Unhandled exception error

    Thanks to you all for help

    the output from debug says:


    'OPENGL_BRUNEL.exe': Loaded 'D:\Documents and Settings\Shafik\Desktop\PhD\OPENGL_BRUNEL\Release\OPENGL_BRUNEL.exe', Symbols loaded.
    'OPENGL_BRUNEL.exe': Loaded 'C:\WINDOWS\system32\ntdll.dll'
    'OPENGL_BRUNEL.exe': Loaded 'C:\WINDOWS\system32\kernel32.dll'
    'OPENGL_BRUNEL.exe': Loaded 'C:\WINDOWS\system32\user32.dll'
    'OPENGL_BRUNEL.exe': Loaded 'C:\WINDOWS\system32\gdi32.dll'
    'OPENGL_BRUNEL.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.30729.4148_x-ww_d495ac4e\msvcp90.dll'
    'OPENGL_BRUNEL.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.30729.4148_x-ww_d495ac4e\msvcr90.dll'
    'OPENGL_BRUNEL.exe': Loaded 'C:\WINDOWS\system32\opengl32.dll'
    'OPENGL_BRUNEL.exe': Loaded 'C:\WINDOWS\system32\msvcrt.dll'
    'OPENGL_BRUNEL.exe': Loaded 'C:\WINDOWS\system32\advapi32.dll'
    'OPENGL_BRUNEL.exe': Loaded 'C:\WINDOWS\system32\rpcrt4.dll'
    'OPENGL_BRUNEL.exe': Loaded 'C:\WINDOWS\system32\secur32.dll'
    'OPENGL_BRUNEL.exe': Loaded 'C:\WINDOWS\system32\glu32.dll'
    'OPENGL_BRUNEL.exe': Loaded 'C:\WINDOWS\system32\ddraw.dll'
    'OPENGL_BRUNEL.exe': Loaded 'C:\WINDOWS\system32\dciman32.dll'
    'OPENGL_BRUNEL.exe': Loaded 'C:\WINDOWS\system32\glut32.dll', Binary was not built with debug information.
    'OPENGL_BRUNEL.exe': Loaded 'C:\WINDOWS\system32\winmm.dll'
    'OPENGL_BRUNEL.exe': Loaded 'C:\WINDOWS\system32\imm32.dll'
    'OPENGL_BRUNEL.exe': Loaded 'C:\WINDOWS\system32\lpk.dll'
    'OPENGL_BRUNEL.exe': Loaded 'C:\WINDOWS\system32\usp10.dll'
    'OPENGL_BRUNEL.exe': Loaded 'C:\WINDOWS\system32\uxtheme.dll'
    'OPENGL_BRUNEL.exe': Loaded 'C:\WINDOWS\system32\msctf.dll'
    'OPENGL_BRUNEL.exe': Loaded 'D:\Documents and Settings\All Users\Application Data\Real\RealPlayer\BrowserRecordPlugin\Chrome\Hook\rpchromebrowserrecordhelper.dll'
    'OPENGL_BRUNEL.exe': Loaded 'C:\WINDOWS\system32\shell32.dll'
    'OPENGL_BRUNEL.exe': Loaded 'C:\WINDOWS\system32\shlwapi.dll'
    'OPENGL_BRUNEL.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.Windows.GdiPlus_6595b64144ccf1df_1.0.6001.22319_x-ww_f0b4c2df\GdiPlus.dll'
    'OPENGL_BRUNEL.exe': Loaded 'C:\WINDOWS\system32\ole32.dll'
    'OPENGL_BRUNEL.exe': Loaded 'C:\WINDOWS\system32\msvcp71.dll'
    'OPENGL_BRUNEL.exe': Loaded 'C:\WINDOWS\system32\msvcr71.dll'
    'OPENGL_BRUNEL.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.5512_x-ww_35d4ce83\comctl32.dll'
    'OPENGL_BRUNEL.exe': Loaded 'C:\WINDOWS\system32\comctl32.dll'
    'OPENGL_BRUNEL.exe': Loaded 'C:\WINDOWS\system32\version.dll'
    'OPENGL_BRUNEL.exe': Unloaded 'C:\WINDOWS\system32\version.dll'
    'OPENGL_BRUNEL.exe': Loaded 'C:\WINDOWS\system32\msctfime.ime'
    'OPENGL_BRUNEL.exe': Loaded 'C:\WINDOWS\system32\sisgl.dll'
    'OPENGL_BRUNEL.exe': Loaded 'C:\WINDOWS\system32\mcd32.dll'
    'OPENGL_BRUNEL.exe': Unloaded 'C:\WINDOWS\system32\mcd32.dll'
    Set chip to SiS661
    CMD_GET_VM_BASE 32.
    CMD_ENABLE_3D_HW escape not supported
    CMD_GET_VM_BASE 32.
    CMD_GET_ENG_IO 32Cmd Queue len = 1M
    Use Buffer Mode
    Use Buffer Mode
    WGL Message:WGL: DDraw: Allocate: Create: DDERROR = DDERR_OUTOFVIDEOMEMORY

    (the last line is repeated many times)...


    First-chance exception at 0x7c812afb in OPENGL_BRUNEL.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0012fbb8..
    Unhandled exception at 0x7c812afb in OPENGL_BRUNEL.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0012fbb8..



    when I run the program, it works till it reaches the value 16 of the variable row_index (it crashes at the same value every time I run the program) and crashes pointing at the code line:
    Code:
    pixels_index[global_index] = pixels_index_temp[local_index];
    and sending the message (undandeled exception .....)

    I delebrately put the function [ delete [] pixels_index; ] inside the function (update) it gave me the same message and pointed at the same line in the code, that means to me that the program is deleting the array of pointers pixels_index on its own

    I wonder if any one has an idea about that.

    about some variables in the code:

    w is the width of the computer screen that displays the image, it is a global variable set to be 1024 pixels, each pixel has 3 colours RGB (red, green, blue) and so it needs 3 bytes (24 bit) in memory to be written. h is the height 768 pixels.
    w_temp, and h_temp are temporary width and height set to be 8 and 6 respectively. The small window of 8*6 pixels is scanning the image from the lower left corner to the right and then again towards the top until it reaches the upper right corner, for that reason the number of bytes in memory will start with 0 and ends up with 3*1024*768.
    in another file the global variable are defined as follows:
    extern int column_index;
    extern int row_index;
    extern int w;
    extern int h;
    the OpenGL function reads the pixels values of the small screen in the same way (lower left to upper right indicated with the local index) and saved in an array of 3*8*6 elements and then in the FOR loop the values are saved in their corresponding locations in the main array pixel_index. after scanning the whole image the resulting array pixels_index that holds the pixels values will be displayed on the screen using opengl functions after row_index reaches 128 and gets out of the IF statement.
    The image will be loaded from a file called tris0.md2


    It is a vital task for me to solve this problem and your help would be really appreciated. many thanks in advance
    Last edited by Yohanna; September 27th, 2010 at 11:27 AM.

  9. #9
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,392

    Re: C++ Unhandled exception error

    Quote Originally Posted by Yohanna View Post
    when I run the program, it works till it reaches the value 16 of the variable row_index (it crashes at the same value every time I run the program) and crashes pointing at the code line:
    Code:
    pixels_index[global_index] = pixels_index_temp[local_index];
    and sending the message (undandeled exception .....)
    And what are the values of global_index and local_index in that case?
    Victor Nijegorodov

  10. #10
    Join Date
    Oct 2009
    Posts
    577

    Smile Re: C++ Unhandled exception error

    Quote Originally Posted by Yohanna View Post
    Thanks to you all for help

    the output from debug says:


    WGL Message:WGL: DDraw: Allocate: Create: DDERROR = DDERR_OUTOFVIDEOMEMORY

    (the last line is repeated many times)...
    ...
    It sounds as if the video controller runs out-of-memory. If so, one of the pointers in the assign statement probably is NULL and that's why an exception was thrown ...

    Can you tell where in your code allocations were made? (In calls to OpenGL)

  11. #11
    Join Date
    Apr 1999
    Posts
    27,427

    Re: C++ Unhandled exception error

    Quote Originally Posted by Yohanna View Post
    Thanks to you all for help

    the output from debug says:
    Nowhere do you mention use of a debugger. Are you using one?
    It is a vital task for me to solve this problem and your help would be really appreciated. many thanks in advance
    You can't write programs if you're not prepared to debug them on your own. It sounds like you took some code, compiled it, and hoped for the best, and if something goes wrong, throw together arbitrary bits of code to see if the problem goes away.

    Instead, you should have prepared for the inevitable step of having to debug the program at some point, whether that point is now or in the future.
    Code:
    WGL Message:WGL: DDraw: Allocate: Create: DDERROR = DDERR_OUTOFVIDEOMEMORY
    That should give you a clue as to what happened.

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; September 27th, 2010 at 12:28 PM.

  12. #12
    Join Date
    Oct 2009
    Posts
    577

    Smile Re: C++ Unhandled exception error

    Code:
    _model = MD2Model::load("tris0.md2");
    I assume for each call of MD2Model::load there is memory allocated. But you never call cleanup what should free the memory.

  13. #13
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Fairfax, VA
    Posts
    10,888

    Re: C++ Unhandled exception error

    Quote Originally Posted by itsmeandnobodyelse View Post
    Can you tell where in your code allocations were made? (In calls to OpenGL)
    The majority of the GPU-side allocations in that code would have occurred in gluBuild2DMipmaps() and glTexImage2D().

    FYI, if you are ever planning to modify an OpenGL texture without resizing it, the second download should be done with glTexSubImage2D() even if you're overwriting the entire image, because that is guaranteed not to do any reallocation.

    Here it looks like a WGL issue, though, so I'm not sure what's going on.

  14. #14
    Join Date
    Sep 2010
    Posts
    13

    Re: C++ Unhandled exception error

    Quote Originally Posted by VictorN View Post
    And what are the values of global_index and local_index in that case?
    global_index = 312549
    local_index = 141 (which is the index of the Red value of the upper right pixel in the 8*6 rectangle of pixels, the last two values of this window will be 142 for Green and 143 for Blue which is teh last value in the rectangle, the coordinates of this pixels are xi=7 and yi=5)

    column index = 94
    row_index = 16


    many thanks to you

  15. #15
    Join Date
    Sep 2010
    Posts
    13

    Re: C++ Unhandled exception error

    Quote Originally Posted by itsmeandnobodyelse View Post
    It sounds as if the video controller runs out-of-memory. If so, one of the pointers in the assign statement probably is NULL and that's why an exception was thrown ...

    Can you tell where in your code allocations were made? (In calls to OpenGL)
    thank you

    if I understand properly, you mean the location of the exception?
    the debugger points to the line of code where the pixels values are assigned to the array of pointers after reading the buffer with glReadPixels, the pixels values are saved in an array pixels_index_temp and assigned to pixels_index array

    pixels_index[global_index] = pixels_index_temp[local_index];

    the global array pixels_index is going to be displayed on screen after the whole scanning process

    I hope I answered your question
    many thanks to you

Page 1 of 2 12 LastLast

Tags for this Thread

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center