TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: mr_nick on June 15, 2012, 03:31:17 AM

Title: Reactor causes fatal error.
Post by: mr_nick on June 15, 2012, 03:31:17 AM
OK, I'm fairly new to the world of reactors and have run into a problem which I'm hoping somebody can help me with.

I have created a very basic reactor as a test. As you can see, it doesn't actually do anything other than set a variable so I know the error isn't caused by something I'm doing with the reactor.

Code: [Select]
(defun np:test (reactor callbackdata / )
  (setq abc 123)
)
(if (not np:reactor1)
  (setq np:reactor1
    (vlr-command-reactor nil '((:vlr-commandwillstart . np:test)))
  )
)

OK, so the problem I have found is that if I load this reactor into a drawing and then use the MVSETUP command but escape out without completing the command, AutoCAD throws an error and becomes unusable. When I then close AutoCAD down I am met with multiple unhandled exception errors before the app finally closes.

I then altered the reactor from a vlr-command-reactor to a vlr-editor-reactor and found that with this, I am no longer met with the same error while escaping out of MVSETUP. However, when I close CAD down I am eventually left with an 'AutoCAD Application has stopped working' error dialog on screen which reports that acad.exe as crashed.

I am working on AutoCAD Architecture 2012 (although I have tried it on 2013 to with the same results) on Windows 7 64bit. I don't currently have access to a 32 bit machine to test whether it is platform specific or not.

Is there anybody out there who can confirm whether they get the same errors as me or whether I am doing something fundamentally wrong in the way I am handling reactors?
Title: Re: Reactor causes fatal error.
Post by: jbuzbee on June 15, 2012, 11:06:41 AM
You have to code for ANY event that can happen: CommandStart, CommandEnded, CommandCancelled.  Have a look at the following;
This series of Command Reactors automatically sets the ANNOBJ layerkey current when certain commands fire and resets the previously current layer on CommandEnded.

James Buzbee

Code: [Select]
;;; Command Will Start ;
(defun kb:CommandWillStart (calling-reactor commands / lname)
  (cond ((member (car commands)
                 (list "MTEXT" "-MTEXT" "DTEXT" "TEXT" "-TEXT" "LEADER" "QLEADER" "MLEADER"
                       )
                 )
         (setq lname (AECGENERATELAYERKEY "ANNOBJ"))
         )
        ((member (car commands)
                 (list "DIMLINEAR" "DIMALIGNED" "DIMBASELINE" "DIMCONTINUE" "DIMDIAMETER"
                       "DIMANGULAR" "DIMRADIUS" "DIMORDINATE" "QDIM"
                       )
                 )
         (setq lname (AECGENERATELAYERKEY "DIMLINE"))
         )
        ((member (car commands) (list "VPORTS" "-VPORTS"))
         (setq lname (AECGENERATELAYERKEY "ANNDTOBJ"))
         )
        ((member (car commands) (list "IMAGE" "-IMAGE")) ;"-XREF" "XREF" "XATTACH"
         (setq lname "XREF")
         )
        )
  (if lname
    (kb:setclayer lname T)
    )
  )

;;; Command Ended ;
(defun kb:CommandEnded (calling-reactor commands / dwgdimscale doc)
  (cond ((member (car commands)
                 (list "MTEXT" "-MTEXT" "DTEXT" "TEXT" "-TEXT"
                       "LEADER" "QLEADER" "MLEADER" "DIMLINEAR" "DIMALIGNED" "DIMBASELINE"
                       "DIMCONTINUE" "DIMDIAMETER" "DIMANGULAR" "DIMRADIUS" "DIMORDINATE"
                       "QDIM" "MVIEW" "VPORTS" "-VPORTS" "IMAGE" "-IMAGE"
                       )
                 )
         (kb:resetclayer)
         )
        ((member (car commands) (list "CLOSE" "QUIT"))
         (if (dcl_Form_IsActive ADT_ADTPalette)
           (progn (dcl_form_Close ADT_ADTPalette))
           )
         (if (dcl_Form_IsActive DetailManager_DMPalette)
           (progn (dcl_form_Close DetailManager_DMPalette))
           )
         )
        ((member (car commands) (list "PASTECLIP" "PURGE" "BLOCK" "INSERT" "-PURGE" "-BLOCK" "-INSERT"))
         (if (dcl_Form_IsActive Blocks_BlockManager)
           (c:Blocks_BlockManager_OnInitialize)
           )
         (if (dcl_Form_IsActive ADT_ADTPalette)
           (c:ADT_ADTPalette_OnInitialize)
           )
         )
        )
  )

;;; Command Cancelled ;
(defun kb:CommandCancelled (calling-reactor commands /)
  (cond ((member (car commands)
                 (list "MTEXT" "-MTEXT" "DTEXT" "TEXT" "-TEXT" "LEADER" "QLEADER" "MLEADER"
                       "DIMLINEAR" "DIMALIGNED" "DIMBASELINE" "DIMCONTINUE" "DIMDIAMETER"
                       "DIMANGULAR" "DIMRADIUS" "DIMORDINATE" "QDIM" "MVIEW" "VPORTS"
                       "-VPORTS" "IMAGE" "-IMAGE"
                       )
                 )
         (kb:resetclayer)
         )
        )
  )

;;; Construct the Command Reactor ;
(defun kb::ConstructCommandReactor (/)
  (if (= (type *kbCommandReactor*) 'VLR-Command-Reactor)
    (progn (vlr-remove *kbCommandReactor*) (setq *kbCommandReactor* nil))
    )
  (if (/= (type *kbCommandReactor*) 'VLR-Command-Reactor)
    (setq *kbCommandReactor*
           (VLR-Command-Reactor
             "kbTools Command Reactor" ; Data associated with the editor reactor
             ;; call backs
             '
              ((:VLR-commandWillStart . kb:CommandWillStart)
               (:VLR-commandEnded . kb:CommandEnded)
               (:VLR-commandCancelled . kb:CommandCancelled)
               )
             ) ;_ end of vlr-editor-reactor
          )
    )
  (if (not (vlr-added-p *kbCommandReactor*))
    (progn (vlr-add *kbCommandReactor*)
           (vlr-set-notification *kbCommandReactor* 'active-document-only)
           )
    )
      ;added 09.26.2003
  (princ)
  )

;;; load reactors ;

(if kb::ConstructCommandReactor
  (kb::ConstructCommandReactor)
  )
Title: Re: Reactor causes fatal error.
Post by: BlackBox on June 15, 2012, 01:00:35 PM
OK, I'm fairly new to the world of reactors and have run into a problem which I'm hoping somebody can help me with.

<snip>

Is there anybody out there who can confirm whether they get the same errors as me or whether I am doing something fundamentally wrong in the way I am handling reactors?

Welcome to the world of Reactors!

I've tested the code you posted, and while I would not code it that way personally, the code tests fine using Civil 3D 2011:

Code: [Select]
Command: mvsetup

Initializing...
Enable paper space? [No/Yes] <Y>: *Cancel*

Command: !abc
123

As for the issue you are experiencing, I am unfamiliar with Architecture (being a Civil guy)... But I do use Reactors for several purposes in our setup. Is there something specific you'd like assistance with?

As the code James has posted illustrates, Reactors can be utilized to perform several different tasks, and in different circumstances; they're not all powerful, but they pack quite a punch.

You have to code for ANY event that can happen: CommandStart, CommandEnded, CommandCancelled. 

This statement is incorrect... One need only code for the Events which one intends to monitor, or react to, and _not_ "ANY event that can happen."

However, as a minimum standard (IMO)... A responsible developer will implement CommandCancelled, CommandEnded, and CommandFailed Event Callback(s) when modifying the end-user's environment (i.e., settings, sysvars, etc.) via the CommandWillStart Event.

While a best practice, these are _not_ necessary for the CommandWillStart Callback to perform.
Title: Re: Reactor causes fatal error.
Post by: BlackBox on June 15, 2012, 01:06:39 PM
@ mr_nick -

You may find this post (http://www.theswamp.org/index.php?topic=41861.msg469921#msg469921) to be helpful; (if you scroll down a bit) it contains a few different Command Reactor examples, with some extra goodies as an attachment.

Note - This is not the only way to code a Command Reactor, and the dependent Callback functions. This is only intended to be an example. I'm sure there are better, smarter, faster ways of doing this.

HTH
Title: Re: Reactor causes fatal error.
Post by: mr_nick on June 18, 2012, 11:35:47 AM
Sorry for the delay in responding - not been getting any notifications.

Anyway, I seem to have pinpointed the cause of the error. As it turned out, the MVSETUP command is a lisp file so I was able to put in a few flags and find the source of the error. It seems that in the error routine, command-s has been used rather than the more common command. And it is command-s that is crashing the reactor. If you have the CommandWillStart reactor loaded and then issue this line of code then AutoCAD will crash

(command-s "_.line" "0,0,0" "10,10,0" "")

If I edit the MVSETUP file to use command rather than command-s then no fatal error is encountered.
Title: Re: Reactor causes fatal error.
Post by: mr_nick on June 19, 2012, 01:18:12 AM

...I've tested the code you posted, and while I would not code it that way personally, the code tests fine using Civil 3D 2011:

Code: [Select]
Command: mvsetup

Initializing...
Enable paper space? [No/Yes] <Y>: *Cancel*


Command: !abc
123

Seems that command-s  slipped in to the 2012 release of AutoCAD and that's why it works OK for you. I've logged a bug report with Autodesk about this so will wait and see if anything comes back. In the meantime it looks like I'll need to swap out the affected files which contain command-s calls with older copies from 2011 and hope that nothing bad happens  :|
Title: Re: Reactor causes fatal error.
Post by: mr_nick on June 19, 2012, 07:54:06 AM
From AutoCAD Help Files
Important. Although the command-s function is similar to the command function, caution should be taken when using U or UNDO to roll back the system state if there is an AutoCAD command already in progress when the AutoLISP expression is entered. In that case, the results of running UNDO may cause the command in progress to fail or even crash AutoCAD.
-------

So, the fact that a command reactor is running at the time of the command-s undo is what is triggering the crash. Looks like Autodesk didn't consider reactors when implementing this command.
Title: Re: Reactor causes fatal error.
Post by: Lee Mac on June 19, 2012, 08:16:04 AM
What is the purpose of the command-s function? Is this new to 2012?
Title: Re: Reactor causes fatal error.
Post by: mr_nick on June 19, 2012, 08:20:31 AM
Full explanation here (http://docs.autodesk.com/ACDMAC/2013/ENU/filesALRMac/GUID-43D3D099-D59E-4503-A355-FB5A1364CA22.htm)
Title: Re: Reactor causes fatal error.
Post by: Lee Mac on June 19, 2012, 08:30:50 AM
Full explanation here (http://docs.autodesk.com/ACDMAC/2013/ENU/filesALRMac/GUID-43D3D099-D59E-4503-A355-FB5A1364CA22.htm)

Google is my friend  :oops:

Thanks  :-)
Title: Re: Reactor causes fatal error.
Post by: jbuzbee on June 20, 2012, 03:31:53 PM
Quote
This statement is incorrect... One need only code for the Events which one intends to monitor, or react to, and _not_ "ANY event that can happen."

Any good developer will: Reactors are dangerous.  It's all well and good for you to hack together bad code for your own use, but until you have a better grasp of reactors you should refrain from giving advice.

Just sayin.

jb
Title: Re: Reactor causes fatal error.
Post by: owenwengerd on June 20, 2012, 04:11:30 PM
James, please clarify what you mean and why you think it is dangerous.
Title: Re: Reactor causes fatal error.
Post by: BlackBox on June 20, 2012, 05:30:29 PM

You have to code for ANY event that can happen: CommandStart, CommandEnded, CommandCancelled. 

This statement is incorrect... One need only code for the Events which one intends to monitor, or react to, and _not_ "ANY event that can happen."

However, as a minimum standard (IMO)... A responsible developer will implement CommandCancelled, CommandEnded, and CommandFailed Event Callback(s) when modifying the end-user's environment (i.e., settings, sysvars, etc.) via the CommandWillStart Event.

While a best practice, these are _not_ necessary for the CommandWillStart Callback to perform.

@ mr_nick -

You may find this post (http://www.theswamp.org/index.php?topic=41861.msg469921#msg469921) to be helpful; (if you scroll down a bit) it contains a few different Command Reactor examples, with some extra goodies as an attachment.

Note - This is not the only way to code a Command Reactor, and the dependent Callback functions. This is only intended to be an example. I'm sure there are better, smarter, faster ways of doing this.

Any good developer will: Reactors are dangerous.  It's all well and good for you to hack together bad code for your own use, but until you have a better grasp of reactors you should refrain from giving advice.

Just sayin.

James,

I meant no disrespect in my reply to you... Your statement _is_ incorrect.

I am always interested in constructive criticism... Can you provide examples as to where I have:


Otherwise, kindly retract your false allegations.
Title: Re: Reactor causes fatal error.
Post by: mr_nick on June 20, 2012, 09:11:57 PM
Gents,

This has all got very messy and decidedly off-topic.

My initial post with the reactor example was purely that - an example. It was not a piece of my actual code and thus it was not constructed with any other 'supporting' features.

My point was, that simply having the reactor present in a session, regardless of what it was actually doing, a fatal error was triggered when the command-s function was used. No manner of building reactors in correct or incorrect ways will get past this issue - Autodesk even went to the trouble of writing in their own help files that command-s will crash AutoCAD when used incorrectly, something they seem to have done after not reading their help. Do as we say, not as we do.
Title: Re: Reactor causes fatal error.
Post by: jbuzbee on June 21, 2012, 09:41:51 AM
Owen,
I bow to your genius.  My experience with reactors has been predicated with experience with ObjectDBX: A programmer must code for every possible event.  I learned reactors and ObjectDBX from Tony T. Would you not agree?

jb
Title: Re: Reactor causes fatal error.
Post by: owenwengerd on June 21, 2012, 10:11:16 AM
James, I'm no lisp reactor genius, in fact just the opposite. I do agree that a programmer should write code that works in every scenario (or exits gracefully). It sounded like you were claiming that it's necessary to handle every reactor event, including events that the code doesn't care about. If that's true, I'd like to know why.
Title: Re: Reactor causes fatal error.
Post by: jbuzbee on June 21, 2012, 10:21:21 AM
Owen,
It's just been my experience: AutoDesk included, I think in 2002, the document event: multiple documents opened required an event to signify which document the reactor should "react" too.  I had Fatal Errors, AutoCad would close, prior to the document argument was included in the call back function.  AutoDesk obviously found that as a problem and corrected it.  Reactors are dangerous if not coded correctly.  That's my experience.

jb
Title: Re: Reactor causes fatal error.
Post by: owenwengerd on June 21, 2012, 11:08:03 AM
I don't doubt that reactors are dangerous and must be written correctly. Since I have almost no experience with reactors in lisp, I'm hoping to learn something from your experience so that I know how to write them correctly when I do use them. Just to make sure I'm clear and can put this issue to rest, it is NOT necessary to write a handler for all reactor events, correct?
Title: Re: Reactor causes fatal error.
Post by: BlackBox on June 21, 2012, 11:32:27 AM
I stand by my original statement:

You have to code for ANY event that can happen: CommandStart, CommandEnded, CommandCancelled. 

This statement is incorrect... One need only code for the Events which one intends to monitor, or react to, and _not_ "ANY event that can happen."

However, as a minimum standard (IMO)... A responsible developer will implement CommandCancelled, CommandEnded, and CommandFailed Event Callback(s) when modifying the end-user's environment (i.e., settings, sysvars, etc.) via the CommandWillStart Event.

While a best practice, these are _not_ necessary for the CommandWillStart Callback to perform.



For consideration... As a simple proof of concept.

... Coding for CommandWillStart Event alone, and intentionally excluding CommandCancelled, ComandEnded, and CommandFailed Events as they are not required for the task being performed within the CommandWillStart Event's Callback function:

Code - Auto/Visual Lisp: [Select]
  1. ;;;--------------------------------------------------------------------;
  2. ;;; Start ReactorFoo function:
  3. (defun ReactorFoo:Start  ()
  4.  
  5.   ;; Command reactors
  6.   (or *ReactorFoo_Command*
  7.       (setq *ReactorFoo_Command*
  8.              (vlr-command-reactor
  9.                nil
  10.                '((:vlr-commandWillStart . CallbackFoo:CommandWillStart)))))
  11.  
  12.   (prompt "\n \n  >>  ReactorFoo Loaded ")
  13.   (princ))
  14. ;;;--------------------------------------------------------------------;
  15. ;;; CallbackFoo:CommandWillStart function:
  16. (defun CallbackFoo:CommandWillStart (rea cmd)
  17.   (alert "You _DO NOT_ have to code for ANY event that can happen")
  18.   (princ))
  19. ;;;--------------------------------------------------------------------;
  20. ;;; Start ReactorFoo function:
  21. (defun c:StartR ()
  22.   (ReactorFoo:Start))
  23. ;;;--------------------------------------------------------------------;
  24. ;;; Stop ReactorFoo function:
  25. (defun c:StopR ()
  26.   (if *ReactorFoo_Command*
  27.     (progn
  28.       (vlr-remove *ReactorFoo_Command*)
  29.       (setq *ReactorFoo_Command* nil)
  30.       (prompt "\n  >>  ReactorFoo stopped ")))
  31.     (princ))
  32. ;;;--------------------------------------------------------------------;
  33. (ReactorFoo:Start)
  34.  





To paraphrase TheMaster (http://www.theswamp.org/index.php?topic=41602.msg470400#msg470400)... The only Event not being properly reacted to is jbuzbee's ability to concede to having made a mistake... I respectfully ask him (again), to either back up his claims against me (http://www.theswamp.org/index.php?topic=42009.msg471976#msg471976), or kindly retract the false allegations.
Title: Re: Reactor causes fatal error.
Post by: jbuzbee on June 21, 2012, 11:40:55 AM
Really,
The example code I provided, if you (RenderMan) would have examined, clearly shows that if your changing any state of the drawing one must code for the event if the command was cancelled.  I will concede that if the routine does not require a change with command ended that could be excluded.  However, creating and destroying code is definetely required with reactors: again, look at my code provided.

jb
Title: Re: Reactor causes fatal error.
Post by: Lee Mac on June 21, 2012, 12:19:36 PM
(http://i159.photobucket.com/albums/t151/204950/popcorn.gif)
Title: Re: Reactor causes fatal error.
Post by: BlackBox on June 21, 2012, 12:32:43 PM

Firstly, I appreciate your concession, James... And I mean that sincerely.

I am no expert, and have much to learn about a great many things; I am here to learn, and help others along the way.

The example code I provided, if you (RenderMan) would have examined, clearly shows that if your changing any state of the drawing one must code for the event if the command was cancelled.  I will concede that if the routine does not require a change with command ended that could be excluded.

Other than the fact that I explicitly covered this in my original post (http://www.theswamp.org/index.php?topic=42009.msg471421#msg471421) to this thread, and your stating it here now, where is it exactly that we differ?  :?

I am still utterly perplexed at how you jumped to the conclusion that I 'hack together bad code for [my] own use', or that I somehow need a 'better grasp of reactors [before] giving advice'...? 

Please clarify what source code, or opinion that I (RenderMan) have posted to justify your statements (http://www.theswamp.org/index.php?topic=42009.msg471962#msg471962)... Otherwise, I fully expect that you will do the honorable thing, and retract your false allegations.
Title: Re: Reactor causes fatal error.
Post by: jbuzbee on June 21, 2012, 12:40:33 PM
Fine, you win.  I'm going back to my Platform now and see how much money I made yesturday.
Title: Re: Reactor causes fatal error.
Post by: BlackBox on June 21, 2012, 12:51:48 PM
Fine, you win.  I'm going back to my Platform now and see how much money I made yesturday.

... Normality is restored.
Title: Re: Reactor causes fatal error.
Post by: owenwengerd on June 21, 2012, 01:24:22 PM
For the benefit of future readers of this thread, here is my conclusion from all this: It is NOT necessary to write event handlers for un-needed events in general, but if you need to perform some kind of cleanup or finalizing type action that was initiated in a CommandWillStart event, then you must handle all of CommandCancelled, ComandEnded, and CommandFailed to be sure your cleanup/finalizer code executes.
Title: Re: Reactor causes fatal error.
Post by: dgorsman on June 21, 2012, 01:35:13 PM
Because its possible to have different "reactions" to the same event or object, its generally a good idea to understand whats going on with all of them in use, including their possible interactions, even if just to avoid debugging problems later (spaghetti is for lunch, not code :) ).  So its important to plan them from a systemic/overall perspective, rather than the typical encapsulated approach seen in many beginner implementations of LISP code.
Title: Re: Reactor causes fatal error.
Post by: CAB on June 21, 2012, 02:02:15 PM
For the benefit of future readers of this thread, here is my conclusion from all this: It is NOT necessary to write event handlers for un-needed events in general, but if you need to perform some kind of cleanup or finalizing type action that was initiated in a CommandWillStart event, then you must handle all of CommandCancelled, ComandEnded, and CommandFailed to be sure your cleanup/finalizer code executes.
The "clean-up" applies in any lisp that changes environmental variables and the user can hit Escape prematurely end the routine.
 
 I don't speak from experience but just the way I understood the reactors to work when I say that the reactors are not fired in a reliable order so other reactors may run & change the environment before yours fires
 and therefore you save variables that are not the setting before the event. When you restore the variables you may or may not be in the correct order when CommandCancelled, ComandEnded, and CommandFailed
 are fired. If someone knows better please speak up.
Title: Re: Reactor causes fatal error.
Post by: jbuzbee on June 21, 2012, 03:23:25 PM
Quote
If someone knows better please speak up.

Renderman?  You seem to be the local expert.

jb

Oh, BTW I made a sh*tload of money yesturday . . ..
Title: Re: Reactor causes fatal error.
Post by: BlackBox on June 21, 2012, 04:33:54 PM
Owen,
I bow to your genius.  My experience with reactors has been predicated with experience with ObjectDBX: A programmer must code for every possible event.  I learned reactors and ObjectDBX from Tony T. Would you not agree?

If someone knows better please speak up.

Renderman?  You seem to be the local expert.

That is kind of you to say (despite the sarcasm), and quite sad, really... As you're the one touting your super-star tutelage.

Regardless, you've 'put me on the spot'...

Quote
For the benefit of future readers of this thread, here is my conclusion from all this: It is NOT necessary to write event handlers for un-needed events in general, but if you need to perform some kind of cleanup or finalizing type action that was initiated in a CommandWillStart event, then you must handle all of CommandCancelled, ComandEnded, and CommandFailed to be sure your cleanup/finalizer code executes.

Because its possible to have different "reactions" to the same event or object, its generally a good idea to understand whats going on with all of them in use, including their possible interactions, even if just to avoid debugging problems later (spaghetti is for lunch, not code :) ).  So its important to plan them from a systemic/overall perspective, rather than the typical encapsulated approach seen in many beginner implementations of LISP code.

The "clean-up" applies in any lisp that changes environmental variables and the user can hit Escape prematurely end the routine.
 
 I don't speak from experience but just the way I understood the reactors to work when I say that the reactors are not fired in a reliable order so other reactors may run & change the environment before yours fires
 and therefore you save variables that are not the setting before the event. When you restore the variables you may or may not be in the correct order when CommandCancelled, ComandEnded, and CommandFailed
 are fired. If someone knows better please speak up.

In my limited experience, Dgorsman’s sentiment holds true for the customizations incorporated into our deployment(s).

For this reason, I choose to manage multiple reactors (i.e., Command, DocManager, etc.) from a single project, if not a monolithic file, rather than having each series of Reactor(s), Callback(s), and dependent Sub-Function(s) loaded independently, and running in parallel.

Multiple reactors can function successfully when run at the same time, it all falls back on the code which has been implemented as to the ease with which this will hold true. As Dgorsman has noted already, the latter can easily lead to potential problems, if one does not effectively plan accordingly.

While I have also read that Events are not always going to fire in the order anticipated, it has proven beneficial for our customizations to have each, the CommandCancelled, CommandEnded, and CommandFailed Events call the same Callback function, to both minimize the code necessary for “clean up” following the CommandWillStart Event, and simplify the task of maintaining the code in the future.

Through this Callback methodology, I prefer to COND (http://exchange.autodesk.com/autocad/enu/online-help/browse#WS1a9193826455f5ff1a32d8d10ebc6b7ccc-6a7a.htm)itionally filter for specific Commands, which also allows for me to execute code in addition to that which is invoked conditionally if desired.

For the most part, our Reactor ‘framework’ has relatively remained the same, despite additional enhancements being made over the years. As one recent example, adding programmatic CapsLock (http://www.theswamp.org/index.php?topic=41461.msg465692#msg465692) functionality for *Text editing Commands.

Within our CommandWillStart Event, all necessary settings, system variables, etc. are stored either to Global Variables within the ActiveDocument (via Setq (http://exchange.autodesk.com/autocad/enu/online-help/browse#WS1a9193826455f5ff1a32d8d10ebc6b7ccc-6952.htm)), to the Registry (via Setenv (http://exchange.autodesk.com/autocad/enu/online-help/browse#WS1a9193826455f5ff1a32d8d10ebc6b7ccc-6956.htm), or vl-registry-write (http://exchange.autodesk.com/autocad/enu/online-help/browse#WS1a9193826455f5ff1a32d8d10ebc6b7ccc-688c.htm)), or to Dictionary/XRecord (via Entmakex (http://exchange.autodesk.com/autocad/enu/online-help/browse#WS1a9193826455f5ff1a32d8d10ebc6b7ccc-6a45.htm), or vlax-ldata-put (http://exchange.autodesk.com/autocad/enu/online-help/browse#WS1a9193826455f5ff1a32d8d10ebc6b7ccc-680c.htm)) as needed by the code being performed given the Command argument supplied.

If there exists the potential for a Command invocation to change settings prior to the CommandWillStart Event, then I have neither experienced this personally, nor possess the aptitude to account for such changes given my limited experience.

Perhaps as I continue to grow my skills at developing with .NET technologies, I will have a better understanding in the future.

If others have experienced such undesired behavior, I’d be interested to learn more.



Oh, BTW I made a sh*tload of money yesturday . . ..

Congrats dood; too bad you can't buy manners, talent, or respect... Just saying  :kewl:.
Title: Re: Reactor causes fatal error.
Post by: TimSpangler on June 21, 2012, 08:12:31 PM
Congrats dood; too bad you can't buy manners, talent, or respect... Just saying  :kewl:.
:roll:

Mat,

James has been around for as long as I can remember, I have learned a great deal from him over the years, He is VERY talented and VERY respected around here.  He's one whose talent is only over shadowed by his originality, and his out of the box thinking.  We are all here for the same reason.  Inflated ego's and all.  :kewl:
Title: Re: Reactor causes fatal error.
Post by: BlackBox on June 22, 2012, 02:31:30 AM

Being relatively new to TheSwamp, and development in general... It's unfortunate that the positive characteristics which you have attributed to James, characteristics that I know to be included in the reputation that precedes him, were not represented here at all.

Instead James' flaming, baseless accusations, name dropping, and pettiness prevailed; behavior that I expect from an adolescent, and not such a well respected veteran... I look forward to when this is not the case.
Title: Re: Reactor causes fatal error.
Post by: mr_nick on June 22, 2012, 02:52:42 AM
So, in amongst all this squabbling has anybody actually tested to see if 'their' method, be it considered right or wrong by anybody else, allows the use of the MVSETUP command to behave with a CommandWillStart reactor in AutoCAD 2012/2013?
Title: Re: Reactor causes fatal error.
Post by: Kerry on June 22, 2012, 03:13:04 AM

mr_nick

Forget about MVSETUP.
Have you tested your reactor with a LINE command and hit ESC part way through. Then close the drawing.

Regards
kdub.
Title: Re: Reactor causes fatal error.
Post by: mr_nick on June 22, 2012, 03:21:02 AM

Have you tested your reactor with a LINE command and hit ESC part way through. Then close the drawing.


Nothing untoward happens for me, but that's beside the point as I wanted to know if anybody could get MVSETUP to work using their method. I know that the code I posted is incomplete as it was merely meant as a quick example. My 'proper' code did actually have other reactors to handle other events (as has been discussed at length) but MVSETUP, or as it actually turns out command-s, crashes my system regardless of what I try.
Title: Re: Reactor causes fatal error.
Post by: Kerry on June 22, 2012, 03:50:22 AM

The code you posted crashes AutoCAD 2013 when closing after I run the LINE command.

lets try again.

Can you post the complete code you are using.
Title: Re: Reactor causes fatal error.
Post by: mr_nick on June 22, 2012, 04:18:56 AM
Odd because my code snippet causes no error with an escaped line command in either 2012 or 2013 (at my end anyway).

As a side note, I have just loaded RenderMans 'foo' reactor code into 2013. Again, no problems escaping out of a line command but if I escape from MVSETUP then I get a fatal error.
Title: Re: Reactor causes fatal error.
Post by: BlackBox on June 22, 2012, 07:44:57 AM
I believe you mentioned that MVSETUP is a LISP file; open that in VLIDE and place a breakpoint at the top of the defun call. Load the code with the breakpoint, and use F8 to step through the code in order to identify what line exactly is causing your error.

FWIW - I agree with Kerry; you should try posting the complete code you're using after anonymizing it of necessary.

** Edit - my 'foo' reactor does not include CommandCancelled, CommandEnded, or CommandFailed Events or a suitable Callback for same.
Title: Re: Reactor causes fatal error.
Post by: mr_nick on June 22, 2012, 07:58:07 AM
I already tracked the exact cause and posted this on the very first page - it is a call to command-s which was introduced in 2012. You already said that your machine doesn't crash but you reported that you were using Civil 2011 hence you won't have command-s on your system and thus no fatal error.

And for further reference, the code posted by jbuzbee also crashes AutoCAD 2013 with a fatal error when using command-s.
Title: Re: Reactor causes fatal error.
Post by: BlackBox on June 22, 2012, 08:25:24 AM

I recalled your posting that, and did reread your posts from the first page. I then tested MVSETUP on Civil 3D 2012, and AutoCAD 2013, both of which result in ultimately fatal errors following several Exceptions on my end.

As an aside, Civil 3D 2012 as AutoCAD (i.e., Map), reported 'unknown command' for MVSETUP, using an OOTB Profile, yet Civil 3D 2012 (as Civil 3D) includes MVSETUP out of the gate.

Title: Re: Reactor causes fatal error.
Post by: mr_nick on June 22, 2012, 08:29:40 AM
The error is obviously not isolated to MVSETUP - it is anything that uses command-s. From what I've found, that includes MVSETUP, EDGE, AI_UTILS.

Using this simple command will trigger a fatal error when a command reactor is loaded:

(command-s "_.line" "0,0,0" "10,10,0" "")

Title: Re: Reactor causes fatal error.
Post by: TimSpangler on June 22, 2012, 08:53:46 AM
I remember reading somewhere (not being a master of reactors my self) that you can not use "command" in a reactor?

From AfraLisp
Quote
A word of warning! Did you notice how I used ActiveX statements and functions to "Save" and "SaveAs". You cannot use interactive functions from within a reactor as AutoCAD may still be processing a command at the time the event is triggered. Therefore, avoid the use of input-acquisition methods such as getPoint, ensel, and getkword, as well as "selection set" operations and the command function.

*EDIT
Try changing it to vl-cmdf
Title: Re: Reactor causes fatal error.
Post by: mr_nick on June 22, 2012, 08:59:39 AM
Command is NOT being used within the reactor. Command-s is being used in a drawing which has a reactor running. Doesn't matter what the reactor is actually doing - just it's actual presence is enough to cause the crash.

Hence loading RenderMans or jbuzbees code samples and then using command-s you will crash AutoCAD.
Title: Re: Reactor causes fatal error.
Post by: jbuzbee on June 22, 2012, 09:01:18 AM
jeez you guy's can't be this stupid.  You CAN'T use ANY form of COMMAND in a reactor.

Stop.
Title: Re: Reactor causes fatal error.
Post by: TimSpangler on June 22, 2012, 09:03:47 AM
Command is NOT being used within the reactor. Command-s is being used in a drawing which has a reactor running. Doesn't matter what the reactor is actually doing - just it's actual presence is enough to cause the crash.

Hence loading RenderMans or jbuzbees code samples and then using command-s you will crash AutoCAD.

Still the same thing.
Title: Re: Reactor causes fatal error.
Post by: mr_nick on June 22, 2012, 09:04:46 AM
If that is the case, why does the old version of MVSETUP not crash AutoCAD  when it uses a command call but the new version which uses command-s triggers the crash.
Title: Re: Reactor causes fatal error.
Post by: Lee Mac on June 22, 2012, 09:20:39 AM
I was very tempted to ignore this thread, not wanting to get involved in the somewhat heated discussions, but having seen these last two posts, I felt I needed to offer my viewpoint - take it or leave it.

jeez you guy's can't be this stupid.  You CAN'T use ANY form of COMMAND in a reactor.

Stop.

Still the same thing.

No, this is not the same thing.

Of course you can use command with a reactor running in the drawing - otherwise if a reactor was running, how else would you use AutoCAD!? If this were the case, command reactors would be redundant - if you cannot use a command whilst a reactor is running, then what exactly are they meant to monitor?

Indeed you cannot any form of command within the callback function of a reactor.

But from what I understand of this thread, the OP is remarking on the fact that AutoCAD will crash when the new command-s function is used independently of the reactor callback function whilst a reactor is running.

This would appear to be an overisight when Autodesk implemented the command-s function.

My 2c.
Title: Re: Reactor causes fatal error.
Post by: mr_nick on June 22, 2012, 09:27:38 AM
Thankyou Lee. At last, somebody is actually reading what I've been trying to get across. I know commands cannot be used INSIDE reactors but they should be able to run ALONGSIDE reactors.
Title: Re: Reactor causes fatal error.
Post by: TimSpangler on June 22, 2012, 09:44:14 AM

Indeed you cannot any form of command within the callback function of a reactor.

I believe that both James and I said this?

Quote from: jbuzbee
You CAN'T use ANY form of COMMAND in a reactor.
Quote from: TimSpangler
I remember reading somewhere (not being a master of reactors my self) that you can not use "command" in a reactor?

But from what I understand of this thread, the OP is remarking on the fact that AutoCAD will crash when the new command-s function is used independently of the reactor callback function whilst a reactor is running.

Just commenting because the title clearly says "Reactor causes fatal error".  Just trying to get to the bottom of the issue.  If you are running the mvsetup from the callback then it is being used IN a reactor, YES?

Maybe no one really understands what the OP is actually asking.?  :oops:
Title: Re: Reactor causes fatal error.
Post by: Lee Mac on June 22, 2012, 09:49:11 AM
I understood the OP was running MVSETUP independently outside of any callback function, and AutoCAD was crashing because the reactor was conflicting with the command-s function that is used within the latest version of the MVSETUP command.

I realise that both you and James commented on the fact that commands may not be used within a reactor callback function, and I support this fact, however, I was disputing your comment regarding the use of commands outside of the reactor callback function:

Command is NOT being used within the reactor. Command-s is being used in a drawing which has a reactor running. Doesn't matter what the reactor is actually doing - just it's actual presence is enough to cause the crash.

Still the same thing.

In any case, since this appears to be a poor implementation of the new command-s function, I very much doubt that this issue can be resolved without Autodesk providing a fix.
Title: Re: Reactor causes fatal error.
Post by: mr_nick on June 22, 2012, 09:53:52 AM
To clarify...

At the point when the original post was made, I did not know the exact cause of the crash. All I knew for sure was that when I used MVSETUP with no reactor loaded, AutoCAD did not crash. When I had a reactor running in the background and used MVSETUP AutoCAD crashed hence me stating that the 'reactor causes fatal error'.

In between times I then discovered that it was actually the interaction between command-s and command reactors that was the cause of the error. I have stated in all my posts that I was not using any command WITHIN my reactor - as shown with the very basic reactor I posted in the original post. I have also pointed out that reactors posted by two other people also trigger the exact same error so the fault was nothing whatsover to do with my possibly inept attempt at coding a reactor.

So, regardless of how safe you feel you have or have not coded your reactor code, MVSETUP will crash AutoCAD if you are using 2012 or 2013.
Title: Re: Reactor causes fatal error.
Post by: jbuzbee on June 22, 2012, 09:55:18 AM
Tim, I'm out.  You have a commanding grip on this issue, and as I'm out of this business (and just wanting to lend a helping hand - not expecting to get blasted by a noob - I offered a complete example.) I'll leave the rest to you.  Thanks.

Goodbye
Title: Re: Reactor causes fatal error.
Post by: mr_nick on June 22, 2012, 09:58:12 AM
Am I that noob?

If so, I admit that yes I am a noob but regardless of that, the example you provided still causes AutoCAD to crash when MVSETUP is used on AutoCAD 2012. I was blasting nobody, simply trying to get my point across.
Title: Re: Reactor causes fatal error.
Post by: TimSpangler on June 22, 2012, 10:15:24 AM
I'm running 2011 so I can't test this as "command-s" doesn't exist.

So if you open the mvsetup.lsp (save a copy of the original) and replace "command-s" with "command" does it solve the problem?
Title: Re: Reactor causes fatal error.
Post by: BlackBox on June 22, 2012, 10:17:35 AM
I'm running 2010 so I can't test this as "command-s" doesn't exist.

So if you open the mvsetup.lsp (save a copy of the original) and replace "command-s" with "command" does it solve the problem?

Page #1 -

If I edit the MVSETUP file to use command rather than command-s then no fatal error is encountered.
Title: Re: Reactor causes fatal error.
Post by: TimSpangler on June 22, 2012, 10:20:14 AM
Thanks  :lol:

So there was no ? in this post, just an observation? information?  :wink:
Title: Re: Reactor causes fatal error.
Post by: mr_nick on June 22, 2012, 10:23:00 AM
Thanks  :lol:

So there was no ? in this post, just an observation? information?  :wink:

It started out as a question and I stumbled across the trigger afer my own observations. It just gost lost among all the posturing.
Title: Re: Reactor causes fatal error.
Post by: TimSpangler on June 22, 2012, 10:29:35 AM
It just gost lost among all the posturing.

There was posturing?  huh, didn't notice   :wink:

It happens (too often) there are those who need to prove that they know something about something.

Lessons learned.  :kewl: