message cleanup

This forum is for general developer support questions.
xenic
Posts: 1185
Joined: Sun Jun 19, 2011 12:06 am

message cleanup

Post by xenic »

While searching through the GUI examples in the SDK, I noticed that none of them appear to be cleaning up queued Intuition messages before exiting. Can I assume that Reaction returns any queued messages when you dispose the window object?
AmigaOne X1000 with 2GB memory - OS4.1 FE
User avatar
tonyw
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 1479
Joined: Wed Mar 09, 2011 1:36 pm
Location: Sydney, Australia

Re: message cleanup

Post by tonyw »

While that may happen (and I don't know the answer to the question), it is good practice to clean up any messages that arrive at your port while you have it open, "during your watch". To leave them for someone else to clean up afterward would be Not A Good Idea.
cheers
tony
User avatar
trixie
Posts: 409
Joined: Thu Jun 30, 2011 2:54 pm
Location: Czech Republic

Re: message cleanup

Post by trixie »

AFAIK in a ReAction input loop you don't directly deal with any messages arriving at the window port. You just Wait() for your signal and then while-loop the WM_HANDLEINPUT method until it returns WMHI_LASTMSG. Without knowing the actual internals of the Window Class, I'd bet the messages are duly cleaned up inside the method.
The Rear Window blog

AmigaOne X5000 @ 2GHz / 4GB RAM / Radeon RX 560 / ESI Juli@ / AmigaOS 4.1 Final Edition
SAM440ep-flex @ 667MHz / 1GB RAM / Radeon 9250 / AmigaOS 4.1 Final Edition
xenic
Posts: 1185
Joined: Sun Jun 19, 2011 12:06 am

Re: message cleanup

Post by xenic »

tonyw wrote:While that may happen (and I don't know the answer to the question), it is good practice to clean up any messages that arrive at your port while you have it open, "during your watch". To leave them for someone else to clean up afterward would be Not A Good Idea.
If you're right then all the GUI examples in the SDK need to be fixed with a message cleanup.
AmigaOne X1000 with 2GB memory - OS4.1 FE
User avatar
trixie
Posts: 409
Joined: Thu Jun 30, 2011 2:54 pm
Location: Czech Republic

Re: message cleanup

Post by trixie »

@xenic

I don't think 15+ years have passed without anybody noticing that all ReAction programs do not clean up their messages.
The Rear Window blog

AmigaOne X5000 @ 2GHz / 4GB RAM / Radeon RX 560 / ESI Juli@ / AmigaOS 4.1 Final Edition
SAM440ep-flex @ 667MHz / 1GB RAM / Radeon 9250 / AmigaOS 4.1 Final Edition
xenic
Posts: 1185
Joined: Sun Jun 19, 2011 12:06 am

Re: message cleanup

Post by xenic »

trixie wrote:AFAIK in a ReAction input loop you don't directly deal with any messages arriving at the window port. You just Wait() for your signal and then while-loop the WM_HANDLEINPUT method until it returns WMHI_LASTMSG. Without knowing the actual internals of the Window Class, I'd bet the messages are duly cleaned up inside the method.
True but the problem is that most examples allow the input loop to respond to messages after a window close message or an error that sets the "done=TRUE" flag.. Here is a snippet of code to demonstrate what I mean:

Code: Select all

while (!done)
{
   Wait(waitmask);
   while ((input = RA_HandleInput(windowobj,&code)) != WMHI_LASTMSG)
   {
      switch (input & WMHI_CLASSMASK)
      {
         case WMHI_CLOSEWINDOW:
            done = TRUE;
            break;
         case WMHI_RAWKEY:
         {
            switch( code )
            {
               case 0x25:
               {
                  <function that does stuff>
                  break;
               }
            }
If the user holds down a key on the keyboard while he clicks the window close gadget, the "done=TRUE" will be set but the loop might continue until the last WMHI_RAWKEY message. If there are any WMHI_RAWKEY messages after the window close message is processed, then whatever function is performed for WMHI_RAWKEY messages will be performed after the window close message.

A test should be added to prevent any code being executed after "done=TRUE" is set. I think it should look like this:

Code: Select all

while (!done)
{
   Wait(waitmask);
   while ((input = RA_HandleInput(windowobj,&code)) != WMHI_LASTMSG)
   {
      if (done == TRUE)
      {
          continue;
      }
      switch (input & WMHI_CLASSMASK)
      {
         case WMHI_CLOSEWINDOW:
            done = TRUE;
            break;
         case WMHI_RAWKEY:
         {
            switch( code )
            {
               case 0x25:
               {
                  <function that does stuff>
                  break;
               }
            }
The message loop will continue until WMHI_LASTMSG without executing any addition code (functions).
AmigaOne X1000 with 2GB memory - OS4.1 FE
User avatar
trixie
Posts: 409
Joined: Thu Jun 30, 2011 2:54 pm
Location: Czech Republic

Re: message cleanup

Post by trixie »

@xenic

The people who have worked on ReAction in the past decade - Rigo, Steven Solie, Fredrik Wikstrom - would surely be able to shed some light on this.
The Rear Window blog

AmigaOne X5000 @ 2GHz / 4GB RAM / Radeon RX 560 / ESI Juli@ / AmigaOS 4.1 Final Edition
SAM440ep-flex @ 667MHz / 1GB RAM / Radeon 9250 / AmigaOS 4.1 Final Edition
User avatar
tonyw
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 1479
Joined: Wed Mar 09, 2011 1:36 pm
Location: Sydney, Australia

Re: message cleanup

Post by tonyw »

@xenic

That is true, but you could in theory receive a message from *any* source to the Intuition port - a window close, a resize, an iconify command...

It just goes to show that you should clear out the port message queue before you close the window.
cheers
tony
User avatar
trixie
Posts: 409
Joined: Thu Jun 30, 2011 2:54 pm
Location: Czech Republic

Re: message cleanup

Post by trixie »

@tonyw
It just goes to show that you should clear out the port message queue before you close the window.
But who says the WM_CLOSE and OM_DISPOSE methods invoked on the window object do not perform the message clean-up? Frankly, the Window Class would have to have been written by a monkey to omit such a crucial step.
The Rear Window blog

AmigaOne X5000 @ 2GHz / 4GB RAM / Radeon RX 560 / ESI Juli@ / AmigaOS 4.1 Final Edition
SAM440ep-flex @ 667MHz / 1GB RAM / Radeon 9250 / AmigaOS 4.1 Final Edition
User avatar
broadblues
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 600
Joined: Sat Jun 18, 2011 2:40 am
Location: Portsmouth, UK
Contact:

Re: message cleanup

Post by broadblues »

xenic wrote:While searching through the GUI examples in the SDK, I noticed that none of them appear to be cleaning up queued Intuition messages before exiting. Can I assume that Reaction returns any queued messages when you dispose the window object?
RTFA (Read the fantabulous auitodocs)

NAME
WM_CLOSE -- Close the window.
--8<---
If the window is sharing a message
port with another window the port will be cleaned of messages
intended for this Window.
--8<-----
From Close Window()
FUNCTION
Closes an Intuition window. Unlinks it from the system, deallocates
its memory, and makes it disappear.

When this function is called, all IDCMP messages which have been sent
to your window are deallocated. If the window had shared a message
Port with other windows, you must be sure that there are no unreplied
messages for this window in the message queue.
Second paragraph is dealt with by the earlier statement about WM_CLOSE.

If you are using plain intuition windows, with a shared user port, things might get a little more complex, but the OP was about Reaction, so I'm not going to get my hands dirty with that, in this quickl reply ...
Post Reply