Forums | developer.brewmp.com Forums | developer.brewmp.com

Developer

Forums

Forums:

Hi,
I am facing heap problem while running my game application in LGVX 6000 emulator.
I am guessing my problem as heap problem because my game application works without any problem if i set the heap to "windows heap" option.

As per data sheet LGVX 6000 has heap limit upto 500 kb.

Game details:
i am using 81 images ( bmp files ) .bar file.
.bar file size is 402kb.
My .dll size is 473kb (built using Microsoft Visualc++ editor)
I have 25 dat files of 3 kb each out side the dll.
I have 10 sound files out side dll.

Game progresses for upto 2 stages. Later it says memory reference error. ( ls see the attached screen shot.
How can i check what is the heap size of my running alication . what is the way to make my game work under 500kb heap??

This is a memory access error...debug your program in the Emulator/Visual Studio to find out which line is causing the problem.

This is a memory access error...debug your program in the Emulator/Visual Studio to find out which line is causing the problem.

Yaa.. that's true..but it runs perfectly without any error when i set the heap to "Windows heap" option in device configurator.
Thanx for the immediate reply..

Yaa.. that's true..but it runs perfectly without any error when i set the heap to "Windows heap" option in device configurator.
Thanx for the immediate reply..

mohlendo wrote:This is a memory access error...debug your program in the Emulator/Visual Studio to find out which line is causing the problem.
thanx for your reply mohlendo...
but i have one analysys for my problem..here it is..
Each time it points to different location.
When i try to optimize the aplication it is proceeding further further and failing after proceeding the game some more steps ahead.

mohlendo wrote:This is a memory access error...debug your program in the Emulator/Visual Studio to find out which line is causing the problem.
thanx for your reply mohlendo...
but i have one analysys for my problem..here it is..
Each time it points to different location.
When i try to optimize the aplication it is proceeding further further and failing after proceeding the game some more steps ahead.

Well, you evidently have a NULL pointer. One or more of your pointers are simply not properly initialized. This is most likely happening when you're trying to load data or images and they fail because the phone is running out of memory.
So, go in, and trace through your code to see where it fail. Chances are you are really just runing out of memory. In which case you will have to address that problem and not look for some weird blind "optimization."

Well, you evidently have a NULL pointer. One or more of your pointers are simply not properly initialized. This is most likely happening when you're trying to load data or images and they fail because the phone is running out of memory.
So, go in, and trace through your code to see where it fail. Chances are you are really just runing out of memory. In which case you will have to address that problem and not look for some weird blind "optimization."

Dragon wrote:Well, you evidently have a NULL pointer. One or more of your pointers are simply not properly initialized. This is most likely happening when you're trying to load data or images and they fail because the phone is running out of memory.
thanx.......for the reply..
see anything wrong in my way of memory handling..
This methjod is called after completing each stage.
--------------------------
void read(CBughuntApp * pi )
{
char *temp = NULL;
char *sub = NULL;
ISHELL_CreateInstance(pi->a.m_pIShell, AEECLSID_FILEMGR,(void **)&pi->m_pIFileMgr );
pi->stagecal=0;
pi->stagecal = pi->stage % 25;
IFILEMGR_GetInfo(pi->m_pIFileMgr,fileName[pi->stagecal],&info);
pi->pIFile=IFILEMGR_OpenFile(pi->m_pIFileMgr,fileName[pi->stagecal],_OFM_READ);
if(!pi->pIFile )
{
}
else
{
IFILE_SetCacheSize(pi->pIFile,info.dwSize);//set's the file cache..
}
temp = (char *)MALLOC(info.dwSize);
sub = MALLOC(4);
IFILE_Read(pi->pIFile,(void *)temp,info.dwSize);
pi->limit=(info.dwSize/4);
while(pi->jlimit)
{
for(pi->i=0;pi->i<4;pi->i++)
{
sub[pi->i] = temp[pi->k];
pi->k++;
}
pi->arr[pi->j]=ATOI(sub);
pi->j++;
ii=0;
}
ii=0;
for(pi->i=0;pi->istage%25];pi->i++)
{
pi->s1[pi->i]=pi->arr[ii];
ii++;
}
kk=mapfilesize[pi->stage%25];
for(pi->i=0;pi->i<144;pi->i++)
{
pi->secondarray[pi->i]=pi->arr[kk];
kk++;
}
TileMap(pi,0);
FREEIF(temp);
temp = NULL;
FREEIF(sub);
sub = NULL;
IFILE_Release(pi->pIFile);
pi->pIFile = NULL;
IFILEMGR_Release(pi->m_pIFileMgr);
pi->m_pIFileMgr = NULL;
}
-------------------

Dragon wrote:Well, you evidently have a NULL pointer. One or more of your pointers are simply not properly initialized. This is most likely happening when you're trying to load data or images and they fail because the phone is running out of memory.
thanx.......for the reply..
see anything wrong in my way of memory handling..
This methjod is called after completing each stage.
--------------------------
void read(CBughuntApp * pi )
{
char *temp = NULL;
char *sub = NULL;
ISHELL_CreateInstance(pi->a.m_pIShell, AEECLSID_FILEMGR,(void **)&pi->m_pIFileMgr );
pi->stagecal=0;
pi->stagecal = pi->stage % 25;
IFILEMGR_GetInfo(pi->m_pIFileMgr,fileName[pi->stagecal],&info);
pi->pIFile=IFILEMGR_OpenFile(pi->m_pIFileMgr,fileName[pi->stagecal],_OFM_READ);
if(!pi->pIFile )
{
}
else
{
IFILE_SetCacheSize(pi->pIFile,info.dwSize);//set's the file cache..
}
temp = (char *)MALLOC(info.dwSize);
sub = MALLOC(4);
IFILE_Read(pi->pIFile,(void *)temp,info.dwSize);
pi->limit=(info.dwSize/4);
while(pi->jlimit)
{
for(pi->i=0;pi->i<4;pi->i++)
{
sub[pi->i] = temp[pi->k];
pi->k++;
}
pi->arr[pi->j]=ATOI(sub);
pi->j++;
ii=0;
}
ii=0;
for(pi->i=0;pi->istage%25];pi->i++)
{
pi->s1[pi->i]=pi->arr[ii];
ii++;
}
kk=mapfilesize[pi->stage%25];
for(pi->i=0;pi->i<144;pi->i++)
{
pi->secondarray[pi->i]=pi->arr[kk];
kk++;
}
TileMap(pi,0);
FREEIF(temp);
temp = NULL;
FREEIF(sub);
sub = NULL;
IFILE_Release(pi->pIFile);
pi->pIFile = NULL;
IFILEMGR_Release(pi->m_pIFileMgr);
pi->m_pIFileMgr = NULL;
}
-------------------

hi dragon !!!
another place where i am using memory allocation is in this method
-------------------------------------------------------------------------------------
boolean StoreData(CBughuntApp * pi)
{
int linecount=0;
char *ptr=MALLOC(100);
FileInfo fi;
//DBGPRINTF("inside storedata");
if (ISHELL_CreateInstance(pi->a.m_pIShell, AEECLSID_FILEMGR, (void **)&pi->m_pIFileMgr) != SUCCESS)
{
//DBGPRINTF("failed");
pi->m_pIFileMgr = NULL;
return FALSE;
}
pi->pIFile = IFILEMGR_OpenFile(pi->m_pIFileMgr, "bughunt.dat", _OFM_CREATE);
//DBGPRINTF("storing the values");
if(pi->pIFile)
{
SPRINTF(ptr,"%d\n%d\n%d\n%d\n%d\n",pi->stage,item_index[3],pi->total_money,high_money,high_stage);
//SPRINTF(ptr,"%d\n%d\n%d\n%d\n%d\n",1,70,50,30,20);
//DBGPRINTF("ptr %s",ptr);
if(IFILE_Write(pi->pIFile,(char*)ptr,100)==0)
DBGPRINTF("unsuccessful");
}
FREEIF(ptr);
if(m_bRemoveFlag==TRUE)
{
IFILE_Release(pi->pIFile);
IFILEMGR_Remove(pi->m_pIFileMgr,"bughunt.dat");
pi->pIFile = NULL;
}
//DBGPRINTF("file is removed");
while (IFILEMGR_EnumNext(pi->m_pIFileMgr, &fi))
//DBGPRINTF(fi.szName);
IFILEMGR_Release(pi->m_pIFileMgr);
pi->m_pIFileMgr=NULL;
return TRUE;

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

hi dragon !!!
another place where i am using memory allocation is in this method
-------------------------------------------------------------------------------------
boolean StoreData(CBughuntApp * pi)
{
int linecount=0;
char *ptr=MALLOC(100);
FileInfo fi;
//DBGPRINTF("inside storedata");
if (ISHELL_CreateInstance(pi->a.m_pIShell, AEECLSID_FILEMGR, (void **)&pi->m_pIFileMgr) != SUCCESS)
{
//DBGPRINTF("failed");
pi->m_pIFileMgr = NULL;
return FALSE;
}
pi->pIFile = IFILEMGR_OpenFile(pi->m_pIFileMgr, "bughunt.dat", _OFM_CREATE);
//DBGPRINTF("storing the values");
if(pi->pIFile)
{
SPRINTF(ptr,"%d\n%d\n%d\n%d\n%d\n",pi->stage,item_index[3],pi->total_money,high_money,high_stage);
//SPRINTF(ptr,"%d\n%d\n%d\n%d\n%d\n",1,70,50,30,20);
//DBGPRINTF("ptr %s",ptr);
if(IFILE_Write(pi->pIFile,(char*)ptr,100)==0)
DBGPRINTF("unsuccessful");
}
FREEIF(ptr);
if(m_bRemoveFlag==TRUE)
{
IFILE_Release(pi->pIFile);
IFILEMGR_Remove(pi->m_pIFileMgr,"bughunt.dat");
pi->pIFile = NULL;
}
//DBGPRINTF("file is removed");
while (IFILEMGR_EnumNext(pi->m_pIFileMgr, &fi))
//DBGPRINTF(fi.szName);
IFILEMGR_Release(pi->m_pIFileMgr);
pi->m_pIFileMgr=NULL;
return TRUE;

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

few more places where ia m handling memory----
-------------------------------------------------------------
static int ReadLine(IFile* pIFile, FileCache* fc, char* Buf, int BufSize)
{
int BufSpot = 0;
int iReturn = TRUE;
while (1)
{
char c;
if (!fc->ValidBytes)
{
fc->ValidBytes = IFILE_Read(pIFile, fc->Buf, sizeof(fc->Buf));
if (!fc->ValidBytes)
{
iReturn = -1;
break;
}
fc->BufPtr = fc->Buf;
}
c = *fc->BufPtr++;
fc->ValidBytes--;
// Will take just LF or CR-LF as terminator
if (c == '\n')
{
if (BufSpot > 0 && Buf[BufSpot - 1] == '\r')
Buf[--BufSpot] = 0;
break;
}
if (BufSpot < BufSize - 1)
Buf[BufSpot++] = c;
else
iReturn = FALSE;
}
Buf[BufSpot] = 0;
FREEIF(Buf);
return iReturn;

boolean readStoreData(CBughuntApp * pi)
{
char FileBuf[128];
FileCache fc;
uint16 nID = 0;
int linecount=0;
if (ISHELL_CreateInstance(pi->a.m_pIShell, AEECLSID_FILEMGR, (void **)&pi->m_pIFileMgr) != SUCCESS)
{
pi->m_pIFileMgr = NULL;
return FALSE;
}
pi->pIFile = IFILEMGR_OpenFile(pi->m_pIFileMgr, "bughunt.dat", _OFM_READWRITE);
if(pi->pIFile)
{
////DBGPRINTF("file opened");
MEMSET(&fc, 0, sizeof(fc));
while (linecount<=5)
{
ReadLine(pi->pIFile, &fc, FileBuf, sizeof(FileBuf));
linecount++;
if(linecount==1)
{
pi->stage=ATOI(FileBuf);
////DBGPRINTF("%d",pi->stage);
}
if(linecount==2)
{
item_index[3]=ATOI(FileBuf);
////DBGPRINTF("%d",item_index[3]);
}
if(linecount==3)
{
pi->total_money=ATOI(FileBuf);
////DBGPRINTF("%d",pi->total_money);
}
if(linecount==4)
{
high_money=ATOI(FileBuf);
////DBGPRINTF("%d",high_money);
}
if(linecount==5)
{
high_stage=ATOI(FileBuf);
////DBGPRINTF("%d",high_stage);
}
}
IFILE_Release(pi->pIFile);
pi->pIFile=NULL;
}
IFILEMGR_Remove(pi->m_pIFileMgr,"bughunt.dat");
IFILEMGR_Release(pi->m_pIFileMgr);
pi->m_pIFileMgr=NULL;
return TRUE;

boolean StoreData(CBughuntApp * pi)
{
int linecount=0;
char *ptr=MALLOC(100);
FileInfo fi;
//DBGPRINTF("inside storedata");
if (ISHELL_CreateInstance(pi->a.m_pIShell, AEECLSID_FILEMGR, (void **)&pi->m_pIFileMgr) != SUCCESS)
{
//DBGPRINTF("failed");
pi->m_pIFileMgr = NULL;
return FALSE;
}
pi->pIFile = IFILEMGR_OpenFile(pi->m_pIFileMgr, "bughunt.dat", _OFM_CREATE);
if(pi->pIFile)
{
SPRINTF(ptr,"%d\n%d\n%d\n%d\n%d\n",pi->stage,item_index[3],pi->total_money,high_money,high_stage);
if(IFILE_Write(pi->pIFile,(char*)ptr,100)==0)
DBGPRINTF("unsuccessful");
}
FREEIF(ptr);
if(m_bRemoveFlag==TRUE)
{
IFILE_Release(pi->pIFile);
IFILEMGR_Remove(pi->m_pIFileMgr,"bughunt.dat");
pi->pIFile = NULL;
}
//DBGPRINTF("file is removed");
while (IFILEMGR_EnumNext(pi->m_pIFileMgr, &fi))
//DBGPRINTF(fi.szName);
IFILEMGR_Release(pi->m_pIFileMgr);
pi->m_pIFileMgr=NULL;
return TRUE;

few more places where ia m handling memory----
-------------------------------------------------------------
static int ReadLine(IFile* pIFile, FileCache* fc, char* Buf, int BufSize)
{
int BufSpot = 0;
int iReturn = TRUE;
while (1)
{
char c;
if (!fc->ValidBytes)
{
fc->ValidBytes = IFILE_Read(pIFile, fc->Buf, sizeof(fc->Buf));
if (!fc->ValidBytes)
{
iReturn = -1;
break;
}
fc->BufPtr = fc->Buf;
}
c = *fc->BufPtr++;
fc->ValidBytes--;
// Will take just LF or CR-LF as terminator
if (c == '\n')
{
if (BufSpot > 0 && Buf[BufSpot - 1] == '\r')
Buf[--BufSpot] = 0;
break;
}
if (BufSpot < BufSize - 1)
Buf[BufSpot++] = c;
else
iReturn = FALSE;
}
Buf[BufSpot] = 0;
FREEIF(Buf);
return iReturn;

boolean readStoreData(CBughuntApp * pi)
{
char FileBuf[128];
FileCache fc;
uint16 nID = 0;
int linecount=0;
if (ISHELL_CreateInstance(pi->a.m_pIShell, AEECLSID_FILEMGR, (void **)&pi->m_pIFileMgr) != SUCCESS)
{
pi->m_pIFileMgr = NULL;
return FALSE;
}
pi->pIFile = IFILEMGR_OpenFile(pi->m_pIFileMgr, "bughunt.dat", _OFM_READWRITE);
if(pi->pIFile)
{
////DBGPRINTF("file opened");
MEMSET(&fc, 0, sizeof(fc));
while (linecount<=5)
{
ReadLine(pi->pIFile, &fc, FileBuf, sizeof(FileBuf));
linecount++;
if(linecount==1)
{
pi->stage=ATOI(FileBuf);
////DBGPRINTF("%d",pi->stage);
}
if(linecount==2)
{
item_index[3]=ATOI(FileBuf);
////DBGPRINTF("%d",item_index[3]);
}
if(linecount==3)
{
pi->total_money=ATOI(FileBuf);
////DBGPRINTF("%d",pi->total_money);
}
if(linecount==4)
{
high_money=ATOI(FileBuf);
////DBGPRINTF("%d",high_money);
}
if(linecount==5)
{
high_stage=ATOI(FileBuf);
////DBGPRINTF("%d",high_stage);
}
}
IFILE_Release(pi->pIFile);
pi->pIFile=NULL;
}
IFILEMGR_Remove(pi->m_pIFileMgr,"bughunt.dat");
IFILEMGR_Release(pi->m_pIFileMgr);
pi->m_pIFileMgr=NULL;
return TRUE;

boolean StoreData(CBughuntApp * pi)
{
int linecount=0;
char *ptr=MALLOC(100);
FileInfo fi;
//DBGPRINTF("inside storedata");
if (ISHELL_CreateInstance(pi->a.m_pIShell, AEECLSID_FILEMGR, (void **)&pi->m_pIFileMgr) != SUCCESS)
{
//DBGPRINTF("failed");
pi->m_pIFileMgr = NULL;
return FALSE;
}
pi->pIFile = IFILEMGR_OpenFile(pi->m_pIFileMgr, "bughunt.dat", _OFM_CREATE);
if(pi->pIFile)
{
SPRINTF(ptr,"%d\n%d\n%d\n%d\n%d\n",pi->stage,item_index[3],pi->total_money,high_money,high_stage);
if(IFILE_Write(pi->pIFile,(char*)ptr,100)==0)
DBGPRINTF("unsuccessful");
}
FREEIF(ptr);
if(m_bRemoveFlag==TRUE)
{
IFILE_Release(pi->pIFile);
IFILEMGR_Remove(pi->m_pIFileMgr,"bughunt.dat");
pi->pIFile = NULL;
}
//DBGPRINTF("file is removed");
while (IFILEMGR_EnumNext(pi->m_pIFileMgr, &fi))
//DBGPRINTF(fi.szName);
IFILEMGR_Release(pi->m_pIFileMgr);
pi->m_pIFileMgr=NULL;
return TRUE;

Not sure what kind of response you are expecting from other forum members. You may have to improve your programming style to write better code. For example after opening file
if(!pi->pIFile )
{
< shouldn't you do error handling here>
}
else
{
....

....
You keep using file handle without checking its validity. There are lots of bad things are going on in your code.

Not sure what kind of response you are expecting from other forum members. You may have to improve your programming style to write better code. For example after opening file
if(!pi->pIFile )
{
< shouldn't you do error handling here>
}
else
{
....

....
You keep using file handle without checking its validity. There are lots of bad things are going on in your code.

You keep using file handle without checking its validity. There are lots of bad things are going on in your code.
Thanx ruben for your critical comment. Many thnx...
But still i say ...these are all my trials for solving the problem first and then improve the code style.

You keep using file handle without checking its validity. There are lots of bad things are going on in your code.
Thanx ruben for your critical comment. Many thnx...
But still i say ...these are all my trials for solving the problem first and then improve the code style.

Well, you're just going to be running around in circles if your "trials" are actually introducing errors. You need to narrow down exactly what is causing the problems, which involves handling error conditions.
PS: No one will read through that much code unless you use [code] tags.

Well, you're just going to be running around in circles if your "trials" are actually introducing errors. You need to narrow down exactly what is causing the problems, which involves handling error conditions.
PS: No one will read through that much code unless you use [code] tags.

Quote:
Game progresses for upto 2 stages. Later it says memory reference error. ( ls see the attached screen shot.
How can i check what is the heap size of my running alication . what is the way to make my game work under 500kb heap??
well the emulator gives a very rough indication of heapsize used when you don't use the windows heap option, this is an option that should only be used during initial development or down porting, since it switches off tracking and allows you to allocate as much memory as you need. of couse it can be way off, so a phone is the best bet, with one of the debug utilities.
uhh the answer to your second question is, use less memory, pack things, optimize, don't hold assets in memory that don't need to be there, cut down on memory allocations in game.
IMHO, its best to allocate one large block of memory at startup and write your own memory allocator. Unfortunately due to brews bad design API calls can allocate from the heap, so you have to factor that in too, or bypass them when you can.
Once you remove all allocations from the game loop, any game level that loads once, will always load, (presuming the first allocation works of course ;) )

Quote:
Game progresses for upto 2 stages. Later it says memory reference error. ( ls see the attached screen shot.
How can i check what is the heap size of my running alication . what is the way to make my game work under 500kb heap??
well the emulator gives a very rough indication of heapsize used when you don't use the windows heap option, this is an option that should only be used during initial development or down porting, since it switches off tracking and allows you to allocate as much memory as you need. of couse it can be way off, so a phone is the best bet, with one of the debug utilities.
uhh the answer to your second question is, use less memory, pack things, optimize, don't hold assets in memory that don't need to be there, cut down on memory allocations in game.
IMHO, its best to allocate one large block of memory at startup and write your own memory allocator. Unfortunately due to brews bad design API calls can allocate from the heap, so you have to factor that in too, or bypass them when you can.
Once you remove all allocations from the game loop, any game level that loads once, will always load, (presuming the first allocation works of course ;) )

I won't read through that much code even if it HAS code tags. :o
I'm always happy to help, but I don't see myself as a programming tutor or instructor. If someone does not understand how to find a NULL pointer in the debugger, there is not much other help I have to offer up. Sorry.

I won't read through that much code even if it HAS code tags. :o
I'm always happy to help, but I don't see myself as a programming tutor or instructor. If someone does not understand how to find a NULL pointer in the debugger, there is not much other help I have to offer up. Sorry.

Hi,
It seems that the heap of the device is full and it cannot allocate any more memory(specially VX6000).
If u try to load images or files it results in an NULL Pointer and the handset crashes at random locations.
-- Buster --

Hi,
It seems that the heap of the device is full and it cannot allocate any more memory(specially VX6000).
If u try to load images or files it results in an NULL Pointer and the handset crashes at random locations.
-- Buster --

Hi,
U r .bar file size big and i think u load all images in single one function? so when u required for image that time u load image or file and release within that function(if u not required for other canvas)write code as per canvas in Game programming.. it is basic requirement...
When u load image that time u check thier pointer is null or not.. other wise it will
crash after playing two three time...
like as
if(pMe->m_pIGameBackGround == NULL)
{
pMe->m_pIGameBackGround= ISHELL_LoadResImage(pMe->a.m_pIShell, XXX_RES_FILE, IDB_GAME_BACKGROUND);

or whatever...
second option..
u can use .bmp image with .bci image format.

Hi,
U r .bar file size big and i think u load all images in single one function? so when u required for image that time u load image or file and release within that function(if u not required for other canvas)write code as per canvas in Game programming.. it is basic requirement...
When u load image that time u check thier pointer is null or not.. other wise it will
crash after playing two three time...
like as
if(pMe->m_pIGameBackGround == NULL)
{
pMe->m_pIGameBackGround= ISHELL_LoadResImage(pMe->a.m_pIShell, XXX_RES_FILE, IDB_GAME_BACKGROUND);

or whatever...
second option..
u can use .bmp image with .bci image format.