-
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;
}
-
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.
-
Re: C++ Unhandled exception error
Quote:
Originally Posted by
jnmacd
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
-
Re: C++ Unhandled exception error
Please, don't duplicate your posts, edit your OP instead.
And read here about tags and other useful features
-
Re: C++ Unhandled exception error
-
Re: C++ Unhandled exception error
Quote:
Originally Posted by
vcdebugger
You should have replaced you duplicated quotation marks with noparse tags:
[CODE] ...[/CODE]
-
Re: C++ Unhandled exception error
Quote:
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 ?
-
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
-
Re: C++ Unhandled exception error
Quote:
Originally Posted by
Yohanna
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?
-
Re: C++ Unhandled exception error
Quote:
Originally Posted by
Yohanna
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)
-
Re: C++ Unhandled exception error
Quote:
Originally Posted by
Yohanna
Thanks to you all for help
the output from debug says:
Nowhere do you mention use of a debugger. Are you using one?
Quote:
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
-
Re: C++ Unhandled exception error
Quote:
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.
-
Re: C++ Unhandled exception error
Quote:
Originally Posted by
itsmeandnobodyelse
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.
-
Re: C++ Unhandled exception error
Quote:
Originally Posted by
VictorN
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
-
Re: C++ Unhandled exception error
Quote:
Originally Posted by
itsmeandnobodyelse
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
-
Re: C++ Unhandled exception error
Quote:
Originally Posted by
Paul McKenzie
Nowhere do you mention use of a debugger. Are you using one?
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
Thank you very much
actually I am building the code step by step (on my own!)and it was working properly for all the previous steps, but now I encounter this problem since few days and I have no clue about how to solve it. I tried all the ways I am familiar with. but i am a student and trying to learn.
many thanks for your time
-
Re: C++ Unhandled exception error
Quote:
Originally Posted by
itsmeandnobodyelse
I assume for each call of MD2Model::load there is memory allocated. But you never call cleanup what should free the memory.
I used cleanup but it really doesn't make a big diference. it only changes the point where the program crashes . at any case I will keep calling it after loading the file.
Thank you for help
-
Re: C++ Unhandled exception error
Quote:
Originally Posted by
Paul McKenzie
Nowhere do you mention use of a debugger. Are you using one?
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
WGL Message:WGL: DDraw: Allocate: Create: DDERROR = DDERR_OUTOFVIDEOMEMORY
from thisshould I assume that the problem is about the video memory? if so, any suggestion to do ?
many thanks again
-
Re: C++ Unhandled exception error
Quote:
Originally Posted by
Lindley
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.
thank you very much
based on your note I am going to use subimage then
-
Re: C++ Unhandled exception error
Just remember you need to glTexImage2d() at least once for each texture, in order to get the memory for TexSubImage to work with!
-
Re: C++ Unhandled exception error
Quote:
Originally Posted by
Lindley
Just remember you need to glTexImage2d() at least once for each texture, in order to get the memory for TexSubImage to work with!
thanks for remark
I will be aware of that.
At any case, this part of the code is not reached at the moment because of the mentioned problem. the texture that is meant to be displayed with this part can not be reached before the row_index reaches the maximum value of 128:
Code:
if (row_index < 128){glutTimerFunc(100, update, 0);}
else {.the texture displayed with this part..}
I hope this would help to solve the problem but I dont have to try. and any other suggestion would be appreciated
thanks again
-
Re: C++ Unhandled exception error
Quote:
Originally Posted by
Yohanna
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
No, the error message you got means that the process runs out-of-memory. You therefore need to locate all calls where the process requests for memory (and the function called returns a pointer to that memory). Then you need to check whether the memory was freed later. I spotted one call where you load the model but where you never delete the pointer. If that function was called 1024 * 768 times you definitively have a memory problem even for big physical memory...
If I am right the exception is only a follow-up of the fact that the system can't provide ay more memory.
-
Re: C++ Unhandled exception error
Quote:
Originally Posted by
itsmeandnobodyelse
No, the error message you got means that the process runs out-of-memory. You therefore need to locate all calls where the process requests for memory (and the function called returns a pointer to that memory). Then you need to check whether the memory was freed later. I spotted one call where you load the model but where you never delete the pointer. If that function was called 1024 * 768 times you definitively have a memory problem even for big physical memory...
If I am right the exception is only a follow-up of the fact that the system can't provide ay more memory.
Thank you so much for help
I think I did what you suggested (to the best of my knowledge)
to locat memory I used the expressions such as :
unsigned char *pixels_index_temp = new unsigned char[144];
and after using the pointer the memory was freed using delete:
delete [] pixels_index_temp;
also, the model and the image loaded were deleted using cleanup function and delete image.
the function (update) is the only function that can return a pointer to the array pixels_index, but the array should be kept to be displayed within the same function and delete it later.
this funtion should load the image and the model 128*128 times and form the data array pixels_index_temp, this array will be displayed using OpengGL commands.
I got the same result with the same messages saying:
Unhandled exception at 0x7c812afb in OPENGL_......exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0012fbb4..
and
There is no source code available for the current location.
and here i sthe last bit of information displayed just before it crashes, these are information about the values stored in the array pixels_index and the address of the array pixels_index_temp before and after using the function delete (the same address):
row_index 20
the value stored in pixels_index[384351] B
row_index 20
the value stored in pixels_index[384354] /
row_index 20
the value stored in pixels_index[384357] รถ
address of pixels_index_temp BEFORE delete 0012FF1C
address of pixels_index_temp AFTER delete 0012FF1C
address of pixels_index 0012FF20 (only 4 bytes after the address of pixels_index_temp)
address of _model 004097E0
I hope to have any idea from you.
-
Re: C++ Unhandled exception error
Quote:
Originally Posted by
Paul McKenzie
Nowhere do you mention use of a debugger. Are you using one?
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
I am still waiting to hear your opinion
many thanks in advance