diff --git a/main b/main index a11839a..0ce566d 100755 Binary files a/main and b/main differ diff --git a/main.c b/main.c index 3013afc..1bc9ada 100644 --- a/main.c +++ b/main.c @@ -70,7 +70,7 @@ struct NewWindow aboutWindowLayout = { 40, 40, ABOUT_WINDOW_WIDTH, ABOUT_WINDOW_HEIGHT, 0, 1, - IDCMP_REFRESHWINDOW | IDCMP_CLOSEWINDOW | BUTTONIDCMP, + IDCMP_CLOSEWINDOW, WFLG_DRAGBAR | WFLG_DEPTHGADGET | WFLG_CLOSEGADGET | WFLG_ACTIVATE, NULL, NULL, @@ -133,6 +133,7 @@ struct Menu *menu; struct Device *TimerBase; struct timerequest *TimerIO; struct timeval currentSystemTime; +struct MsgPort *timerPort; // sound stuff // get that bell @@ -155,6 +156,7 @@ ULONG timerStartTime = 0, timerDistance, timerBuild; BOOL timerIsRunning = FALSE; BOOL timerStarted = FALSE; BOOL terminated = FALSE; +BOOL openAboutWindowNext = FALSE; /** * Initialize system stuff. @@ -163,8 +165,6 @@ BOOL terminated = FALSE; // parameter. // http://www.hipooniosamigasite.org/amigadocs/files/LOON-DOCS-DISKS/LOON5/LatticeC.pt3 int setup(void) { - struct MsgPort *timerPort; - // make sure the font exists on the computer // http://amigadev.elowar.com/read/ADCD_2.1/Includes_and_Autodocs_3._guide/node0308.html if (NULL == (topaz80Font = OpenFont(&Topaz80))) { @@ -218,15 +218,12 @@ int setup(void) { */ void teardown(void) { // http://amigadev.elowar.com/read/ADCD_2.1/Devices_Manual_guide/node0196.html - struct MsgPort *tempTimerPort; - if (TimerIO) { CloseDevice((struct IORequest *)TimerIO); - tempTimerPort = TimerIO->tr_node.io_Message.mn_ReplyPort; - - if (tempTimerPort) { - DeletePort(tempTimerPort); - } + DeleteExtIO((struct IORequest *)TimerIO); + } + if (timerPort) { + DeletePort(timerPort); } // all right, then. keep your secrets. if (visualInfo) FreeVisualInfo(visualInfo); @@ -527,6 +524,14 @@ int openAboutWindow(void) { ULONG windowSignal; BOOL closeAbout = FALSE; + + // Something is causing a small memory leak when I do this and I don't know + // what it is. CodeWatcher reports a bunch of 40 byte blocks, most likely + // Intuition messages. + // + // nope, false positive, checked with avail before and after running and + // the used/free counts are exactly the same: + // https://eab.abime.net/showthread.php?t=104360 aboutWindow = OpenWindow(&aboutWindowLayout); if (!aboutWindow) { @@ -584,16 +589,21 @@ int openAboutWindow(void) { while (!closeAbout) { Wait(windowSignal); - while (!closeAbout && (iMessage = GT_GetIMsg(aboutWindow->UserPort))) { - switch (iMessage->Class) { - case IDCMP_CLOSEWINDOW: - closeAbout = TRUE; - break; - case IDCMP_REFRESHWINDOW: - GT_BeginRefresh(window); - GT_EndRefresh(window, TRUE); - break; + while (iMessage = GT_GetIMsg(aboutWindow->UserPort)) { + if (!closeAbout) { + switch (iMessage->Class) { + case IDCMP_CLOSEWINDOW: + closeAbout = TRUE; + break; + case IDCMP_REFRESHWINDOW: + GT_BeginRefresh(window); + GT_EndRefresh(window, TRUE); + break; + } } + + // ensure messages are garbage collected + GT_ReplyIMsg(iMessage); } } @@ -648,10 +658,7 @@ void handleIntuitionMessage(struct IntuiMessage *iMessage) { terminated = TRUE; break; case MENU_ABOUT_ID: - // yes, this blocks, deal with it - // it also returns non-zero if something goes wrong. - // in that case, kill the program - if (openAboutWindow()) terminated = TRUE; + openAboutWindowNext = TRUE; break; } break; @@ -833,14 +840,26 @@ int main() { if (foundSignals & windowSignal) { // drain the window event queue - while ((!terminated) && (iMessage = GT_GetIMsg(window->UserPort))) { - handleIntuitionMessage(iMessage); + while (iMessage = GT_GetIMsg(window->UserPort)) { + if (!terminated) { + handleIntuitionMessage(iMessage); + } + + // if we don't reply, the event won't be garbage collected. + // we still have to drain any other messages that show up + GT_ReplyIMsg(iMessage); } } if ((foundSignals & timerSignal) && timerIsRunning) { handleTimerMessage(); } + + if (openAboutWindowNext) { + if (openAboutWindow()) terminated = TRUE; + + openAboutWindowNext = FALSE; + } } clearUI();