Omnimaga

Calculator Community => TI Calculators => Calculator C => Topic started by: blue_bear_94 on December 25, 2012, 06:08:25 pm

Title: [68k] Function not working as expected
Post by: blue_bear_94 on December 25, 2012, 06:08:25 pm
Whenever I call enableUndo for this program (from a menu), I get light gray vertical lines as on the image attached. I think I did everything right, so here is the excerpt I am having trouble with:
Code: [Select]
typedef struct {
void* prevl,*prevd;
char canUndo:1,isUndone:1;
} UndoInfo;
void* allocBUB(void)
{
void* buffer=NULL;
if (!(buffer=calloc(LCD_SIZE,1)))
{
dlgError(DMA_ERROR,MEMALLOC_FAIL);
return NULL;
}
return buffer;
}
int allocGBUB(void** lbuff,void** dbuff)
{
if (!(*lbuff=allocBUB()))
{
return 0;
}
if (!(*dbuff=allocBUB()))
{
free(*lbuff);
return 0;
}
return 1;
}
void enableUndo(UndoInfo* p) {
GrayOff();
SetIntVec(AUTO_INT_1,I1);
SetIntVec(AUTO_INT_5,I5);
//*v: this may be the cause of the gray bars
p->canUndo=allocGBUB((void**)p,(void**)((char*)p+4));
SetIntVec(AUTO_INT_1,DUMMY_HANDLER);
SetIntVec(AUTO_INT_5,DUMMY_HANDLER);
GrayOn();
}
I would appreciate any assistance given!
Title: Re: [68k] Function not working as expected
Post by: Lionel Debroux on December 26, 2012, 02:26:10 am
I haven't looked at the entire code base yet, but three stylistic notes on your excerpt:
* why are you killing gray mode before allocating data, and activating it back later ? :)
* you're using a bit field in struct UndoInfo, but bit fields are inefficient (and once in every while, when faced with bit fields, compilers generate incorrect code which corrupts memory). As your struct needs padding anyway, why not using two chars, instead of a char containing two bits ?
* "DMA" is seldom used for abbreviating Dynamic Memory Allocation, it usually stands for Direct Memory Access.

One of the causes of screen corruption with a repeatable pattern is a stack overflow... but here, you're precisely not allocating on the stack. Another cause is an invalid argument passed to a string drawing routine, but that seems less likely.
Title: Re: [68k] Function not working as expected
Post by: blue_bear_94 on December 26, 2012, 12:26:13 pm
1. The dialog boxes are supposed to be in black-and-white, not some shade of gray. Does it matter whether I kill gray mode before allocating data or after?
2. Sure.
3. ...
4. Maybe I've used a lot of stack space for, maybe, function calling?

Edit: I changed canUndo and isUndone to regular char types, and the repeatable pattern no longer occurs.
Title: Re: [68k] Function not working as expected
Post by: Lionel Debroux on December 26, 2012, 03:37:36 pm
Indeed, AMS dialogs just don't work in grayscale mode. But what about pushing most of the code of enableUndo() - and possibly similar routines - to the error path (dlgError()) ?
Title: Re: [68k] Function not working as expected
Post by: blue_bear_94 on December 26, 2012, 03:56:23 pm
But what about pushing most of the code of enableUndo() - and possibly similar routines - to the error path (dlgError()) ?

Excuse me? (I don't understand what you mean.)