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..
when I used the delete function to delete the array it works until it reaches a different and specific row number (28) means works more but the array will be deleted before I use it which is unwanted. at any case, I need the program to work till the end of the rows (128).
any one can help me in this please?
how can I get rid of this error and make the program works? is there any problem about the array pointer, either the way of defining it or the way i am using it? if not what is the problem here, any idea?
many thanks in advance
here is parts of the OpenGL code in C++ environment:
#include <iostream>
#include <stdlib.h>
//#include "glext.h"
//#include "glew.h"
.
.
#include <GL/glut.h>
#endif
#include "stdafx.h"
#include <windows.h>
using namespace std;
.
.
int column_index = 0;
int row_index = 0;
.
.
unsigned char *pixels_index = new unsigned char[3*1024*768];
.
void update(int value) {
.
unsigned char *pixels_index_temp = new unsigned char[3*8*6];
.
.
int x_column = 8*column_index;
int y_row = 6*row_index;
glReadPixels(x_column, y_row, 8, 6, GL_RGB, GL_UNSIGNED_BYTE, pixels_index_temp);
for (int yi=0;yi<6;yi++)
{
for (int xi=0;xi<8;xi++)
{
int local_index = 3*(yi*w_temp + xi);
int global_index = 3*((row_index*w*h_temp) + (yi*w) + (column_index*w_temp) + xi);
pixels_index[global_index] = pixels_index_temp[local_index];
pixels_index[global_index + 1] = pixels_index_temp[local_index + 1];
pixels_index[global_index + 2] = pixels_index_temp[local_index + 2];
}
}
delete [] pixels_index_temp;
.
.
if (row_index < 128){glutTimerFunc(100, update, 0);}
else {
..
..
.
.
delete [] pixels_index;
}