Hi Mike,
The first exception may be caused by, in decreasing order of feasibility:
* An antivirus or firewall program, which has interpreted some actions performed by PI as a treat. These problems happen from time to time, and there's basically nothing we can do to prevent them. This is part of Windows' idiosyncrasy (viruses, antiviruses, and all that ugly stuff).
* A virus, typically a Trojan. This may happen if the virus in question attaches itself to one of PI's processes.
* A hardware problem, for example some external device connected to your computer when you shut down it.
===
The second crash can be reproduced on all platforms, and is a bug in the core ViewList object. It is an obscure bug that your script triggers for some reason. Tracing the exact cause of the problem is difficult, but the overall mechanism is quite simple: if you uncomment line 1975 of your script, the viewList object gets corrupted upon destruction. As a result, it still exists (in an unstable state) when the image is closed, so it receives a notification (ViewList objects are always watching View objects to update their view lists dynamically), which cannot be handled properly and leads to a crash.
The bug does not happen if you select the "<No View Selected>" option in your dialog before closing it. This gives me a good hint about the cause of the problem: it is related to the currentView member of the ViewList class (now I'm referring to the C++ implementation of the core ViewList object).
You already have found a workaround that works until I can fix the bug. However, and although they are not directly related to this particular problem, let me make a few comments about your code:
* Your code is prone to garbage collection issues. The most important rule is: never leave a Control object unrooted.
For example:
function parametersDialogPrototype() {
// ...
var targetPane = new HorizontalSizer;
// ...
this.sizer.add(targetPane);
// ...
}
This is very likely to cause problems. targetPane is not a property of any object, and it is not being used directly. Sooner or later, the garbage collector will decide to destroy it under the scenes, with catastrophic results. Note that the fact that you have added targetPane to this.sizer does not change this---in fact, it promotes the unsafe code to a real problem---, since the mechanism of adding Control and Sizer objects to Sizer objects is completely unknown to the JavaScript engine.
The correct way to implement a dialog is as follows:
function parametersDialogPrototype() {
// ...
this.targetPane = new HorizontalSizer;
// ...
this.sizer.add(this.targetPane);
// ...
}
Now targetPane is a property of parametersDialogPrototype, so it cannot be garbage collected before its mother instance of parametersDialogPrototype.
* Try to avoid using the "with" statement. It has been deprecated and is not allowed in strict mode since
ECMAScript 5. For more information on the reasons why "with" is considered evil in JavaScript, see these blog posts:
http://www.2ality.com/2011/06/with-statement.htmlhttp://www.yuiblog.com/blog/2006/04/11/with-statement-considered-harmful/Although there are
some different opinions, believe me that the possible benefits of with (if any) don't compensate for the many problems it generates. I used to use with in my own code a few years ago, and there are some old scripts in the official PI distribution that still have with constructs, so I know how difficult it can be getting rid of them.
* Since PI 1.8.0 RC7, calling Control.restyle() is no longer necessary for dialogs, since this is done automatically by PJSR. So you can remove lines 1951 to 1953 in your code.