message cleanup

This forum is for general developer support questions.

message cleanup

Postby xenic » Wed Dec 27, 2017 8:50 pm

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
xenic
 
Posts: 1145
Joined: Sun Jun 19, 2011 1:06 am

Re: message cleanup

Postby tonyw » Wed Dec 27, 2017 11:44 pm

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
tonyw
AmigaOS Core Developer
AmigaOS Core Developer
 
Posts: 1312
Joined: Wed Mar 09, 2011 2:36 pm
Location: Sydney, Australia

Re: message cleanup

Postby trixie » Thu Dec 28, 2017 12:55 am

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.
Smoke me a kipper, I'll be back for breakfast!

AmigaOne X5000 @ 2GHz / 4GB RAM / Radeon R5 230 / ESI Juli@ / AmigaOS 4.1 Final Edition
SAM440ep-flex @ 667MHz / 1GB RAM / Radeon 9250 / AmigaOS 4.1 Final Edition
User avatar
trixie
 
Posts: 373
Joined: Thu Jun 30, 2011 3:54 pm
Location: Czech Republic

Re: message cleanup

Postby xenic » Thu Dec 28, 2017 10:40 pm

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
xenic
 
Posts: 1145
Joined: Sun Jun 19, 2011 1:06 am

Re: message cleanup

Postby trixie » Thu Dec 28, 2017 10:57 pm

@xenic

I don't think 15+ years have passed without anybody noticing that all ReAction programs do not clean up their messages.
Smoke me a kipper, I'll be back for breakfast!

AmigaOne X5000 @ 2GHz / 4GB RAM / Radeon R5 230 / ESI Juli@ / AmigaOS 4.1 Final Edition
SAM440ep-flex @ 667MHz / 1GB RAM / Radeon 9250 / AmigaOS 4.1 Final Edition
User avatar
trixie
 
Posts: 373
Joined: Thu Jun 30, 2011 3:54 pm
Location: Czech Republic

Re: message cleanup

Postby xenic » Thu Dec 28, 2017 11:03 pm

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
xenic
 
Posts: 1145
Joined: Sun Jun 19, 2011 1:06 am

Re: message cleanup

Postby trixie » Thu Dec 28, 2017 11:08 pm

@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.
Smoke me a kipper, I'll be back for breakfast!

AmigaOne X5000 @ 2GHz / 4GB RAM / Radeon R5 230 / ESI Juli@ / AmigaOS 4.1 Final Edition
SAM440ep-flex @ 667MHz / 1GB RAM / Radeon 9250 / AmigaOS 4.1 Final Edition
User avatar
trixie
 
Posts: 373
Joined: Thu Jun 30, 2011 3:54 pm
Location: Czech Republic

Re: message cleanup

Postby tonyw » Thu Dec 28, 2017 11:36 pm

@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
tonyw
AmigaOS Core Developer
AmigaOS Core Developer
 
Posts: 1312
Joined: Wed Mar 09, 2011 2:36 pm
Location: Sydney, Australia

Re: message cleanup

Postby trixie » Thu Dec 28, 2017 11:45 pm

@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.
Smoke me a kipper, I'll be back for breakfast!

AmigaOne X5000 @ 2GHz / 4GB RAM / Radeon R5 230 / ESI Juli@ / AmigaOS 4.1 Final Edition
SAM440ep-flex @ 667MHz / 1GB RAM / Radeon 9250 / AmigaOS 4.1 Final Edition
User avatar
trixie
 
Posts: 373
Joined: Thu Jun 30, 2011 3:54 pm
Location: Czech Republic

Re: message cleanup

Postby broadblues » Fri Dec 29, 2017 12:14 am

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 ...
User avatar
broadblues
AmigaOS Core Developer
AmigaOS Core Developer
 
Posts: 538
Joined: Sat Jun 18, 2011 3:40 am
Location: Portsmouth, UK

Next

Return to General Developer Support

Who is online

Users browsing this forum: No registered users and 1 guest