Strange errors after script is run

jruuth

Member
Aug 31, 2018
22
10
I recently started getting some strange errors, most often when I exit or restart my script. Any hints on what could be the reason for these errors? And what do I need to fix on my script? My Javascript skills are very limited so it could be something very trivial.

I have tried adding processEvents() and gc() calls but if possible they make it worse. I have tried rooting objects and although I may miss some objects so far it has not had any effect.

The errors I get are similar like below:

Close dialog
*** Error [222]: C:/Program Files/PixInsight/src/scripts/AutoIntegrate.js, line 13816: TypeError: par.skip_blink is undefined


But par.skip_blink is statically initialized so the error is coming for some other reason. And most often the error comes from a different variable, Also once when I started the CodeSign script I got errors from my script like:

** Warning [162]: reference to undefined property narrowBandPalettes[itemIndex]

So CodeSign was starting but I got errors from my own script. I used to get errors from NumericControl.jsh but after some changes like hiding all globals I am getting similar errors from variables in my own script.

Sometimes but a lot more randomly I get call stacks with Qt code. The call stack is kind of long so not posting it here but it has lines like

6: _chkstk in module: C:\WINDOWS\SYSTEM32\ntdll.dll at address: 0x730D1F80
7: RtlRaiseException in module: C:\WINDOWS\SYSTEM32\ntdll.dll at address: 0x73081020
8: KiUserExceptionDispatcher in module: C:\WINDOWS\SYSTEM32\ntdll.dll at address: 0x730D0BA0
9: JS::AutoGCRooter::AutoGCRooter in module: C:\Program Files\PixInsight\bin\mozjs-24.dll at address: 0x3B95C4D0
10: JS_SetPrivate in module: C:\Program Files\PixInsight\bin\mozjs-24.dll at address: 0x3B8E65E0

20: QWidgetPrivate::sendPendingMoveAndResizeEvents in module: C:\Program Files\PixInsight\bin\Qt5Widgets.dll at address: 0x27FE26F0


Thanks,
Jarmo
 

jruuth

Member
Aug 31, 2018
22
10
It must be so that some events from old script run are still hanging out there and magically get executed when the instance is already garbage collected. I can repeat the problem every time when I start the script, click checkboxes like crazy, do nothing else and exit the script, and then run some processing. RIght now the error was

Processing completed.
TypeError: ({control:(void 0), infolabel:(void 0), statuslabel:(void 0), sizer:(void 0)}) is not a function
Processing stopped!


Is there a way to clear the event queue? I call processEvents() but I guess that is not enough.

Jarmo
 

Juan Conejero

PixInsight Staff
Sep 2, 2004
8,719
714
58
Valencia, Spain
pixinsight.com
Hi Jarmo,

Are you modifying the Global JavaScript object, or some of the standard objects such as Array, String, etc? In such case, this can be the cause of these problems. Modifying standard objects is not recommend because the JS engine depends internally on their default properties and methods, sometimes in very subtle ways. Always create new objects when you need extended functionality.

If this is not what happens, then perhaps you are hitting a bug in the JS engine, although this is very unlikely. We are currently in the process of replacing the current engine (SpiderMonkey 24, from 2014) with a newer version. However, this requires a huge amount of work (basically, a complete rewrite of the entire PJSR).

As for processEvents(), it is the only way to clear the event queue. This method can take two parameters:

void processEvents( [Boolean excludeUserInputEvents=false[, int iterations=1]] )

The iterations parameter allows you to execute a really exhaustive queue emptying operation by setting it to something like 10 for example.
 

jruuth

Member
Aug 31, 2018
22
10
Hi Juan,

Thanks for your comments! I tried calling processEvents(false, 10) but it did not help. As far as I know I am not modifying standard objects.

I have continued debugging and so far it looks like I get errors when I have a PreviewControl object hidden. By hidden I mean that I have called .hide() for the control or it is invisible in a different tab. I am using PreviewControl that I have found from some other script.

I tried to create a test program to repeat the problem but no luck so far. I will experiment more and let you know if I can find more details.

Regards,
Jarmo
 

jruuth

Member
Aug 31, 2018
22
10
Some good news. If I clean up all mouse callback functions in the PreviewControl object by setting them to null before exiting the script I do not get the error any more. Without the cleanup the problem repeats every time (100%).

PreviewControl cleanup helps even if none of my errors were coming from PreviewControl code. But the errors were on callback functions like CheckBox .onClick functions. Maybe a problem handling the mouse event queue when PreviewControl is not in focus, or something else.

Below is my cleanup code just to illustrate the “fix”.

Code:
function previewControlCleanup(control)
{
      control.zoomIn_Button.onMousePress = null;
      control.zoomOut_Button.onMousePress = null;
      control.zoom11_Button.onMousePress = null;
      control.zoomFit_Button.onMousePress = null;
      control.scrollbox.onHorizontalScrollPosUpdated = null;
      control.scrollbox.onVerticalScrollPosUpdated = null;
      control.forceRedraw = null;
      control.scrollbox.viewport.onMouseWheel = null;
      control.scrollbox.viewport.onMousePress = null;
      control.scrollbox.viewport.onMouseMove = null;
      control.scrollbox.viewport.onMouseRelease = null;
      control.scrollbox.viewport.onResize = null;
      control.scrollbox.viewport.onPaint = null;
}
Jarmo
 
  • Like
Reactions: bitli