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

Developer

Forums

Forums:

Hi,

When I run my program in emulator(I want to read QCP file into a buffer and then play it), it gives me MEMMOVE corruption and then emulator resets. I read somewhere that I might pass in the wrong parameter. If I wrap these CRT functions with my wrapper function where you do error checking for parameters.

I isolated the problem to this line of code:

byte* pRes= NULL;
byte* pData= NULL;
int sizeSnd= 0;
uint16 id = 0;

pRes = (byte *)ISHELL_LoadResDataEx(m_pIShell, MOON_RES_FILE, id, RESTYPE_IMAGE,NULL,&mSize);
pData= pRes+*pRes;
sizeSnd = (int)mSize;
lpSound[i] = (byte *)MALLOC(sizeSnd);
MEMCPY(lpSound[i], pData, sizeSnd);

What can be the solution?

Thank you.

Anybody knows about this?
Thank you.

Anybody knows about this?
Thank you.

Simple, Your mSize variable is wrong
ISHELL_LoadResData passes the full size including the header that your jumping over using the line
pData= pRes+*pRes;
All you need to do is adjust your size to skip the header...
sizeSnd -= *pRes;
Before you use it. I.e
byte* pRes= NULL;
byte* pData= NULL;
int sizeSnd= 0;
uint16 id = 0;
pRes = (byte *)ISHELL_LoadResDataEx(m_pIShell, MOON_RES_FILE, id, RESTYPE_IMAGE,NULL,&mSize);
mSize -= *pRes; //<---------- This Line Here
pData= pRes+*pRes;
sizeSnd = (int)mSize;
lpSound[i] = (byte *)MALLOC(sizeSnd);
MEMCPY(lpSound[i], pData, sizeSnd);
- Skavenger

Simple, Your mSize variable is wrong
ISHELL_LoadResData passes the full size including the header that your jumping over using the line
pData= pRes+*pRes;
All you need to do is adjust your size to skip the header...
sizeSnd -= *pRes;
Before you use it. I.e
byte* pRes= NULL;
byte* pData= NULL;
int sizeSnd= 0;
uint16 id = 0;
pRes = (byte *)ISHELL_LoadResDataEx(m_pIShell, MOON_RES_FILE, id, RESTYPE_IMAGE,NULL,&mSize);
mSize -= *pRes; //<---------- This Line Here
pData= pRes+*pRes;
sizeSnd = (int)mSize;
lpSound[i] = (byte *)MALLOC(sizeSnd);
MEMCPY(lpSound[i], pData, sizeSnd);
- Skavenger

Skavenger wrote:Simple, Your mSize variable is wrong
ISHELL_LoadResData passes the full size including the header that your jumping over using the line
pData= pRes+*pRes;
All you need to do is adjust your size to skip the header...
sizeSnd -= *pRes;
Before you use it. I.e
byte* pRes= NULL;
byte* pData= NULL;
int sizeSnd= 0;
uint16 id = 0;
pRes = (byte *)ISHELL_LoadResDataEx(m_pIShell, MOON_RES_FILE, id, RESTYPE_IMAGE,NULL,&mSize);
mSize -= *pRes; //<---------- This Line Here
pData= pRes+*pRes;
sizeSnd = (int)mSize;
lpSound[i] = (byte *)MALLOC(sizeSnd);
MEMCPY(lpSound[i], pData, sizeSnd);
- Skavenger
Thank you, Skavenger. That solved the problem.

Skavenger wrote:Simple, Your mSize variable is wrong
ISHELL_LoadResData passes the full size including the header that your jumping over using the line
pData= pRes+*pRes;
All you need to do is adjust your size to skip the header...
sizeSnd -= *pRes;
Before you use it. I.e
byte* pRes= NULL;
byte* pData= NULL;
int sizeSnd= 0;
uint16 id = 0;
pRes = (byte *)ISHELL_LoadResDataEx(m_pIShell, MOON_RES_FILE, id, RESTYPE_IMAGE,NULL,&mSize);
mSize -= *pRes; //<---------- This Line Here
pData= pRes+*pRes;
sizeSnd = (int)mSize;
lpSound[i] = (byte *)MALLOC(sizeSnd);
MEMCPY(lpSound[i], pData, sizeSnd);
- Skavenger
Thank you, Skavenger. That solved the problem.