Ok, it seems I have made a beginners error. I have the following structures defined in my h file
The cpp code extract is as followsCode:typedef struct { unsigned char B; unsigned char G; unsigned char R; unsigned char A; } pix32; struct FinalTGAFile { char IDLen; //length of ID field char MapType; //0=none, 1=present char ImgType; //0=none, 1=c-map, 2=true, short FirstColor; //where to start in colormap short MapLen; //number of colors to set char EntrySize; //number of bits per color entry short Xorigin; short Width; short Height; char Depth; char Descriptor; pix32 Pixel[]; };
I then basically take a whole series of tga files and stitch them together by filling up the pix32 structure with pixels.Code://Create a new TGA header FinalTGAFile tgaCell; memset(&tgaCell,0, 18); tgaCell.ImgType = 2;//true-color tgaCell.Height = 100; tgaCell.Width = 4800; tgaCell.Depth = 32;//has alpha tgaCell.Descriptor = 32; //extract of code that moves the pixels around int j=0; int p; int count=0; for(int y=0; y<100;y++) { if(y<256) { int j=y*1024; for(int h=0;h<18;h++) { for (p=j; p<j+1024;p=p+4) { //Eventually this will bomb out when count gets too large tgaCell.Pixel[count].B = final].finalimage[p]; tgaCell.Pixel[count].G = final[h].finalimage[p+1]; tgaCell.Pixel[count].R = final[h].finalimage[p+2]; tgaCell.Pixel[count].A = final[h].finalimage[p+3]; count++;
Based on reading I have done it appears this is because this array is getting put on the stack (rather than heap) and so at some point in time it is larger than the max allowed memory.
However I am unsure of the method used to allocate this to the heap using the structures I have created. Can someone please provide some guidance on how to best do this..
Regards, Andrew




Reply With Quote