Script Segmentation violation

hvb356

Well-known member
Hi,

one of my scripts constantly produces a severe error when running on a MAC: *** PCL UNIX Signal Handler: Critical signal caught (11): Segmentation violation.

Any ideas, how to start the analysis?

My problem: I'm not in the posession of a MAC.

Regards

Hartmut
 
Hi Hartmut,

I think I've found what has been causing segmentation faults. The following code fragment is from lines 1139 to 1151 of your script:

JavaScript:
      onPaint = function( x0, y0, x1, y1 )
      {
         var g = new Graphics(dialog.lblTick);
         var str = (dialog.progress * 100).toFixed() + '%';
         var r = g.textRect( x0, y0, x1, y1, str, TextAlign_Center );
         g.drawTextRect( r, str);
         if (dialog.progress > 0)
         {
            var x = (x1 - x0) * dialog.progress;
            g.pen = new Pen(0xffff0000, 5);
            g.drawLine(0, 2, x, 2);
         }
      }

In this onPaint() event handler function you create a new Graphics object . The Graphics.begin() method is being called implicitly because you have constructed Graphics with a Control argument (dialog.lblTick). However, you have forgotten to call Graphics.end() before returning from the event handler function. As you know, doing this is calling for a crash. As a result of JavaScript's lazy (optimized) garbage collection policy, the Graphics object is not always destroyed immediately after returning from the function, which explains why the segmentation fault happens sometimes very soon, sometimes later, etc.

The problem gets fixed by simply adding the appropriate call to Graphics.end():

JavaScript:
      onPaint = function( x0, y0, x1, y1 )
      {
         var g = new Graphics(dialog.lblTick);
         var str = (dialog.progress * 100).toFixed() + '%';
         var r = g.textRect( x0, y0, x1, y1, str, TextAlign_Center );
         g.drawTextRect( r, str);
         if (dialog.progress > 0)
         {
            var x = (x1 - x0) * dialog.progress;
            g.pen = new Pen(0xffff0000, 5);
            g.drawLine(0, 2, x, 2);
         }
         g.end();
      }

These problems can be difficult to find and fix if working on Windows. For any development tasks in PixInsight, I strongly recommend working on Linux, where a simple inspection of the terminal output gives you more than enough information to diagnose this type of problems very easily in most cases.

Besides this problem, I've found the following error:

EmissionLineIntegration.js, line 506: TypeError: this.curves.xyy is undefined

where line 506 is:

JavaScript:
         Console.writeln("Curve points " + this.curves.xyy.length);

Let me know if this helps.
 
Dear Juan,

Thank you very, very much for your answer. Tomorrow I can correct and re-publish this script.

Have a nice weekend

Hartmut
 
Back
Top