Je restructure un peu mon code, et j'ai fais les choses suivantes:
la structure:
typedef struct _ENVIRONMENTDESC
{
INT_HANDLER ai1;
INT_HANDLER ai5;
LCD_BUFFER screen;
LPVOID frame;
BOOL initialized;
} ENVIRONMENTDESC, *PENVIRONMENTDESC;
l'initialisation:
PENVIRONMENTDESC InitializeEnvironment()
{
PENVIRONMENTDESC pEnvironment=NULL;
int nBytes=GRAY_BIG_VSCREEN_SIZE*2+LCD_SIZE*2;
// initializes the ENVIRONMENTDESC structure
pEnvironment=(PENVIRONMENTDESC) malloc(sizeof(ENVIRONMENTDESC));
if (pEnvironment)
{
// reset the ENVIRONMENTDESC structure
memset(pEnvironment, 0, sizeof(ENVIRONMENTDESC));
// initializes the off screen image
pEnvironment->frame=malloc(nBytes);
if (pEnvironment->frame)
{
// reset the frame's content
memset(pEnvironment->frame, 0, nBytes);
// saves the screen
LCD_save(pEnvironment->screen);
// saves the interruptions
pEnvironment->ai1=GetIntVec(AUTO_INT_1);
pEnvironment->ai5=GetIntVec(AUTO_INT_5);
// sets the interruptions
SetIntVec(AUTO_INT_1, DUMMY_HANDLER);
SetIntVec(AUTO_INT_5, DUMMY_HANDLER);
// activates grays
if (GrayOn())
{
GrayClearScreen();
pEnvironment->initialized=TRUE;
}
}
}
return pEnvironment;
}
la libération:
void UninitializeEnvironment(PENVIRONMENTDESC* pEnvironment)
{
if (*pEnvironment)
{
if ((*pEnvironment)->initialized)
GrayOff();
SAFE_FREE((*pEnvironment)->frame);
if ((*pEnvironment)->ai1)
SetIntVec(AUTO_INT_1, (*pEnvironment)->ai1);
if ((*pEnvironment)->ai5)
SetIntVec(AUTO_INT_1, (*pEnvironment)->ai5);
GKeyFlush();
LCD_restore((*pEnvironment)->screen);
SAFE_FREE(*pEnvironment);
pEnvironment=NULL;
}
}
Et lorsque j'exécute:
int main()
{
PENVIRONMENTDESC pEnvironment=NULL;
pEnvironment=InitializeEnvironment();
if (pEnvironment && pEnvironment->initialized)
{
// start the game
while (!KeyPressed(ESC_KEY))
{
}
}
UninitializeEnvironment(&pEnvironment);
return 0;
}
ça crash à la sortie. Il semble qu'il y ait un problème avec les interruptions ai1 et ai5 car lorsque je mets en commentaire les lignes gérant les interruptions, ça marche. Je ne vois pas pourquoi...
J'ai peut-être loupé quelque chose...
Si quelqu'un a une explication ça serait la bienvenue
Fred.