Hi all,
I have a problem with my code and I just can't find the bug. I open my window but when I close it nothing happens. Below is a snippet of the code. After doing some testing I can see it never reaches the part "while(( result = IIntuition->IDoMethod( winobj, WM_HANDLEINPUT, &code )) != WMHI_LASTMSG )". If I place the code to break from the program using CTRL C between the two while's it will do that. I stared at a dozen examples and I just can't find the cause.
while( !done )
{
while(( result = IIntuition->IDoMethod( winobj, WM_HANDLEINPUT, &code )) != WMHI_LASTMSG )
{
switch( result & WMHI_CLASSMASK )
{
case WMHI_CLOSEWINDOW:
done = TRUE;
break;
}
}
}
Coder
This code is badly missing a Wait(). Like it is now it does a busy-loop.
Apart from that the code is correct. Your problem is not here. Maybe "winobj" is not initialised correctly. Or "IIntuition".
@Coder
Assuming there is a Wait() somewhere before the loop in your example (we don't want busy-looping on Amiga) then I would ask if you initialized the "done" variable (done = FALSE) before entering the while(!done) loop. The "while((result=" part would never be executed if the "done" variable is set to TRUE by a previous code section.
X1000 - OS 4.1FE
There are various examples included with the SD in examples/reaction/os4_examples. Check those out to see what the event loop code should look like.
Simon
@Coder
Make sure that you set WA_IDCMP to IDCMP_CLOSEWINDOW when you create the window object so that intuition knows that you are interested in hearing about close window events.
@salass00
Is WMHI_CLOSEWINDOW not taking care of this?
Coder
@thomas
The wait() is there. winobj and IIntuition seems to be correct compared to example code.
Coder
@xenic
I have set done to FALSE.
Coder
Hi Simon,
I use the new way that Trixie described in his guide. So the examples use a different way like RA_handleinput for example.
Coder
RA_HandleInput is just a macro which is defined in <reaction/reaction_macros.h>
Simon
@Coder
No, how could it?
The WA_IDCMP is a mask telling intuition which classes of IDCMP message that it should send to your window. If the IDCMP_CLOSEWINDOW bit isn't set you won't get any close window events and your "case WMHI_CLOSEWINDOW:" will never happen.
This is true for normal Intuition windows, but window.class automatically sets IDCMP_CLOSEWINDOW if WFLG_CLOSEGADGET is set. You only need to set *additional* IDCMP flags through WA_IDCMP. For example IDCMP_VANILLAKEY needs to be set explicitly.
I am starting to believe the problem lies in the below snippet of code.
/* Obtain window pointer and signal mask from the window object. */
IIntuition->GetAttrs(winObj,
WINDOW_Window, (uint32 *)&window,
WINDOW_SigMask, &sigMask, TAG_END);
Because CTRL-C does set done on TRUE and closes the window.
Coder
You major problem is that you don't have the overview over the whole code. If you only look at one statement you will never find the mistake.
Of course this statement is syntactically correct and it does what it should do. But do you know what it shall do? Did you understand what it is good for and where in the program it should reside?
Your error can be everywhere. It can even be that the statement is not in the right place of the code. But you'll find this out only if you look at the entire code at once and not at only one statement at a time.
So please, either quote your entire program here. Or if you find it too big or too confidential, then please put together a small complete example which behaves the same as your problem program.
Often one finds the mistake by oneself while trying to recreate the problem.
@coder
The ReAction BOOPSI class extension does handle the input loop differently than the standard Intuition. The loop works well and is well documented by the OS4 SDK examples (my tutorial barely touches the subject and only mentions to avoid the macro). If it looks like you have everything in place than chances are your problem lies elsewhere. We really need to see the entire code to help you.
But you gave me some inspiration for a new tutorial :-) I'll try to write something on the input loop during X-mastime.
AmigaOne X5000-020 / 2GB RAM / Sapphire Pulse Radeon RX 560 / AmigaOS 4.1 Final Edition Update 2
I am going through my code with precision to find the bug. I already eliminated some possible causes and I am sure I will find it soon.
Happy Christmas everyone!
Coder