Ok, to through some code out:
typedef struct {
unsigned char *data;
UInt32 length;
unsigned char transaction_id;
unsigned char pdu_type;
unsigned char status_code;
} WSPPDU;
typedef WSPPDU * WSPPDUPtr;
int WspInitPdu(WSPPDUPtr wsppdu)
{
wsppdu->data = NULL;
return(0);
}
void ImageLoadImages(GlobalsType *g)
{
Char *url;
UInt32 len = 0;
unsigned char *imgBuf= NULL;
WSPPDU wsppdu;
int wspRet = 0;
Err err;
BitmapPtr bmp = NULL;
ImagePtr img = NULL;
unsigned char *channel = NULL;
Int16 imgMaxWidth = 1;
Int16 imgOrigWidth = 1;
UInt16 maxw = 0;
UInt16 width = 0, height = 0;
load_top:
img = g->downloadImage;
WinDrawChar('a',0,0);
SysTaskDelay(2 * SysTicksPerSecond());
if (img && !img->download) {
g->downloadImage = img->next;
goto load_top;
} else if (!img) {
return;
}
WinDrawChar('b',0,0);
SysTaskDelay(2 * SysTicksPerSecond());
WspInitPdu(&wsppdu); // <-- Crash is here!!!!!
WinDrawChar('c',0,0);
SysTaskDelay(2 * SysTicksPerSecond());
url = Malloc(MAX_URL_LEN+1);
if (!url) {
g->downloadImage = img->next;
return;
}
URLCreateURLStr(img->location,url,g);
WinDrawChar('d',0,0);
SysTaskDelay(2 * SysTicksPerSecond());
if ((g->engineStop == true || g->userCancel == true) &&
!CacheFindCachedFile(url, true, g)) {
if (url)
Free(url);
g->downloadImage = img->next;
return;
}
WinDrawChar('e',0,0);
SysTaskDelay(2 * SysTicksPerSecond());
imgBuf = Malloc(DEF_RECEIVE_BUF+1);
if (!imgBuf) {
if (url)
Free(url);
g->downloadImage = img->next;
return;
} // ErrFatalDisplayIf (!imgBuf, "Malloc Failed");
WinDrawChar('f',0,0);
SysTaskDelay(2 * SysTicksPerSecond());
len = ImageDownloadImage(&wsppdu, url, imgBuf, g);
WinDrawChar('g',0,0);
SysTaskDelay(2 * SysTicksPerSecond());
if (len <= 0) {
goto cleanup;
}
WinDrawChar('h',0,0);
SysTaskDelay(2 * SysTicksPerSecond());
ImageHandleImage(len, &bmp, &width, &height, &channel, url, imgBuf,
isLink, &wsppdu, &wspRet, g);
WinDrawChar('i',0,0);
SysTaskDelay(2 * SysTicksPerSecond());
width = img->width;
height = img->height;
if (!wspRet && bmp) {
if (width > img->origWidth) {
imgMaxWidth = img->maxWidth;
imgOrigWidth = img->origWidth;
maxw = imgMaxWidth;
if (jpegLibRef && jpegLibRef != sysInvalidRefNum) {
BitmapType *newBmp;
UInt32 maxh = height * maxw / width;
if (BmpGetBitDepth(bmp) < 16)
goto bottom;
newBmp = pnoJpeg2Resample(jpegLibRef, bmp,
maxw, maxh, &err);
if (err != errNone) {
if (bmp) {
if (newBmp) BmpDelete(newBmp);
goto bottom;
} else {
if (newBmp) BmpDelete(newBmp);
if (channel) Free(channel);
goto cleanup;
}
}
if (bmp) BmpDelete(bmp);
bmp = newBmp;
width = maxw; height = maxh;
} else {
if (BmpGetBitDepth(bmp) < 16)
goto bottom;
bmp = BmpResizeBitmap(bmp, maxw, NULL, &width,
&height, true);
}
if (!bmp) {
if (channel) Free(channel);
goto cleanup;
}
}
bottom:
img->bitmap = bmp;
img->channel = channel;
img->download = false;
} else {
if (bmp)
BmpDelete(bmp);
if (wspRet == WSP_ERR_AUTHORIZE) {
if (imgBuf)
Free(imgBuf);
if (url)
Free(url);
ImageLoadImages(g);
//return renderImage(wmldck, wmlSrc, width, height,alt,
g);
return;
} else if ((wspRet == WSP_ERR_REDIRECT || wspRet ==
HTTP_ERR_REDIRECT) && g->urlBuf) {
if (imgBuf)
Free(imgBuf);
if (url)
Free(url);
if (img->location)
Free(img->location);
img->location = g->urlBuf;
ImageLoadImages(g);
/*tempRet = renderImage(wmldck, g->urlBuf, width,
height, alt, g);
Free(g->urlBuf);
return tempRet;*/
return;
} else {
img->download = false;
}
}
cleanup:
if (g->conn.connectionType == 'h' || g->conn.connectionType == 'd')
HTTPFlushCache();
if (imgBuf)
Free(imgBuf);
if (url)
Free(url);
g->downloadImage = img->next;
return;
}
Err ImageLoadThreadRun(void *userDataP, SndStreamRef stream, void *bufferP,
UInt32 bufferSize)
{
GlobalsType *g; // = (GlobalsType *)userDataP;
UInt16 width = 1; // for 8bit mono
//UInt32 oldA5;
//oldA5 = SysSetA5(g->registerA5);
#ifdef __GNUC__
CALLBACK_PROLOGUE
#endif
WinDrawChar('0',0,0);
SysTaskDelay(2 * SysTicksPerSecond());
FtrGet(wuAppType, ftrGlobals, (UInt32 *)&g);
WinDrawChar('1',0,0);
SysTaskDelay(2 * SysTicksPerSecond());
if (g->downloadImage && (g->state == BS_DOWNLOADING_IMG)) {
WinDrawChar('2',0,0);
SysTaskDelay(2 * SysTicksPerSecond());
ImageLoadImages(g);
WinDrawChar('3',0,0);
SysTaskDelay(2 * SysTicksPerSecond());
//updateScreen(g);
ImageLoadUpdateScreen(g);
WinDrawChar('4',0,0);
SysTaskDelay(2 * SysTicksPerSecond());
MemSet(bufferP, bufferSize * width, 0);
} else if (g->downloadImage) {
WinDrawChar('6',0,0);
SysTaskDelay(2 * SysTicksPerSecond());
MemSet(bufferP, bufferSize * width, 0);
} else {
MemSet(bufferP, bufferSize * width, 0);
WinDrawChar('7',0,0);
SysTaskDelay(2 * SysTicksPerSecond());
ImageLoadThreadStop(stream, g);
}
WinDrawChar('5',0,0);
SysTaskDelay(2 * SysTicksPerSecond());
//SysSetA5(oldA5);
#ifdef __GNUC__
CALLBACK_EPILOGUE
#endif
return errNone;
}
Basically, WspInitPdu is in a different section. I have tried the CALLBACK
stuff from callback.h and I have tried the SysSetA5 stuff. I have also made
sure that all of my structs are byte-aligned (except for maybe one or two, but
not WSPPDU). I crash when access WspInitPdu (not inside). ImageLoadImages works
fine when being called from the UI thread.
Any help? (as stated, I use the latest prc-tools and multilink).
Thanks,
Donald
--
For information on using the PalmSource Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/support/forums/