 |
Anaristos Sorcerer
Joined: 17 Jul 2007 Posts: 821 Location: California
|
Posted: Sat Jun 26, 2010 1:05 am
[320B-321B] onExit EVENT doesn't seem to be fairing. |
Here is my onExit EVENT:
Code: |
#FORALL @conntab {
comRef = %db( %i, Object)
#IF (%bitand( %db( %i, Flags), %db( @comflags, isTest))) {comRef = %db( %i, TestObject)}
#VAR @comRef ""
#CALL %vartype( @comRef, 8)
}
;;
#ECHO %cr
;;
#ECHO <color orange>onExit: </color><color white>COM Objects released</color>
;;
#ECHO %cr
|
Upon inspection, the variables are not reset and the exit message is not displayed. So I can only conclude that the event is not firing.
If I run the scrip manually, it works.
NOTE: I make a call to %vartype because the #VAR command was setting the variables to literal type. |
|
_________________ Sic itur ad astra.
Last edited by Anaristos on Mon Jun 28, 2010 12:55 am; edited 1 time in total |
|
|
 |
Zugg MASTER

Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Sat Jun 26, 2010 2:16 am |
There is a known bug where onExit does not fire sometimes. onExit means that the MUD window is closing, so any output you do during this event will be lost anyway, so I'm not really sure how you are testing this. So you need to give me more information about when you expect this to fire and exactly how you are testing it.
Quote: |
#VAR command was setting the variables to literal type |
Yes, that is because you have the line:
which sets the variable to the "" literal string. Also, you should not have a @ before the name of the variable. I think you want
which will set it to a null com reference. Although since you are about to exit anyway, it doesn't matter what the vartype of @comref is when you exit. Assigning the "" string will also clear the com reference correctly.
Finally, I'm not exactly sure what you are doing with this, but remember that you cannot store a COM reference within a string list or database variable. So I'm not sure what you are doing with the "comRef = %db(%i,Object)" line. This will not return a proper COM reference. Never has and never will. |
|
|
 |
Anaristos Sorcerer
Joined: 17 Jul 2007 Posts: 821 Location: California
|
Posted: Sat Jun 26, 2010 2:34 am |
THe comRef variable is used as an indirect referece. I pull the name of the actual variable and load it into comRef
so
works. The script that is supposed to be executed by the event works if I just execute it from the command line. However, when I close the window (using FILE|Close window or File|Close all) nothing happens. |
|
_________________ Sic itur ad astra. |
|
|
 |
Zugg MASTER

Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Sat Jun 26, 2010 2:41 pm |
Oh, OK, I see what you are trying to do. So yes, the @ is correct in that case.
I think the issue you have is already on my bug list, but I'll take a look when I get home on Tuesday. Also, is CMUD not automatically clearing your COM variables when closing your session? It is supposed to do that so maybe that's another bug? |
|
|
 |
Anaristos Sorcerer
Joined: 17 Jul 2007 Posts: 821 Location: California
|
Posted: Mon Jun 28, 2010 12:54 am |
No, this is a different problem. According to the documenation, when the session window closes the onExit event will fire. I haven't gotten it to fire for me. I showed what it is supposed to do, the script I showed has no problem and it is not in question (for the purposes of this post). I indicated that if I execute the script from the command line (or attach the script to the onDisconnect event) it runs. The onExit event is not being visited at all.
|
|
_________________ Sic itur ad astra. |
|
|
 |
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Mon Jun 28, 2010 4:39 am |
But how do you know the onExit event is "not being visited at all"? Zugg already said that the #ECHO commands in the onExit event won't show up in your window because the window is being closed.
|
|
|
 |
Anaristos Sorcerer
Joined: 17 Jul 2007 Posts: 821 Location: California
|
Posted: Mon Jun 28, 2010 6:39 am |
I know because the reason I an using the event is to release COM references. Especially, externally held references to CMUD. When I try to exit CMUD I am informed that I am still holding the references and I have to reply before CMUD can terminate, this means the routine didn't run which only would fail to run if the onExit even didn't fire. Besides, when the far application is about to start the cleanup it informs me that it is in the process of calling the garbage collector and CMUD wouldn't be able to exit until I released that message, so even if CMUD is no longer addressing the session window I have a visual indicator that the routine is running. If I put the clean up routine in the onDisconnect event it works. But I don't want to release the objects if I am not exiting the client and that's why I want it in the onExit event.
|
|
_________________ Sic itur ad astra. |
|
|
 |
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Mon Jun 28, 2010 6:11 pm |
Ah! Then that should be reported as a bug. Zugg said:
Quote: |
Also, is CMUD not automatically clearing your COM variables when closing your session? It is supposed to do that so maybe that's another bug? |
|
|
|
 |
Anaristos Sorcerer
Joined: 17 Jul 2007 Posts: 821 Location: California
|
Posted: Mon Jun 28, 2010 8:58 pm |
Maybe it is a bug but AFAIK CMUD has never cleared the COM variables on closing. When necessary I have cleared them in the onLoad event. A simple test will verify this. Make a COM connection, make sure that before you quit the contents of the varible is COMObject, uncheck the default box if checked, quit the application and then start it again. Inspection of the variable will show that it is not cleared, though it is no longer a COM variable (the reference is gone). COM variables have been treated like any other varible without a default value since I've been working with them.
Also, the point is not whether COM variables are being reset on exit or not by the application. The point is that if I tried to do anything else, it wouldn't get done because the onExit event is not firing. For instance, I have implemented Initializers and Finalizers in some of my applications. I successfully call the Initializers from the onLoad event, but the call to the Finilizers doesn't get done unless I put it in the onDisconnect event (which is premature). I want the Finalizers to run from the onExit event, as they should. |
|
_________________ Sic itur ad astra. |
|
|
 |
Zugg MASTER

Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Thu Jul 01, 2010 5:33 pm |
Quote: |
Maybe it is a bug but AFAIK CMUD has never cleared the COM variables on closing |
Works for me here. Create a session and then type:
Code: |
#VAR Conn %comcreate( "ADODB.Connection") |
on the command line to create a COM object ADO reference. Now try closing the session. I don't get any warning about any COM connections still being open.
Yes, the variable itself will still exist and will not be deleted, and the COM reference will be gone when you restart CMUD. But I don't get any warning about CMUD still holding the COM reference. So if you can give a procedure to reproduce that then maybe I can track it down.
In any case, I confirmed that onExit is running is you close the window with the X in the upper right corner (of the window, not the CMUD application), but does *not* run when using File/CloseWindow or File/CloseAll |
|
|
 |
Zugg MASTER

Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Thu Jul 01, 2010 5:47 pm |
OK, this is fixed for the next version. However, be *very* careful with the code you put in your OnExit handler. When CMUD is in the process of exiting, anything that creates new threads (like using #WAITxxx, etc) could cause the application to hang. Any crash in your onExit code would probably also prevent your package from being saved and you might not get any error messages about it.
I also confirmed that in some cases (using CloseWindow or CloseAll) the COM variables were *not* being cleared. This is actually done in the same CMUD routine that calls the OnExit handler. So this should also be fixed. You should not need to write an OnExit handler just to clear COM variables. |
|
|
 |
|
|