Author Topic: Hard application crash when resampling image from JS  (Read 4443 times)

Offline David Serrano

  • PTeam Member
  • PixInsight Guru
  • ****
  • Posts: 503
Hard application crash when resampling image from JS
« on: 2007 September 17 02:32:32 »
This is almost the same code I pasted in the "Unable to copy and resample image" message:

Code: [Select]
#include <pjsr/Interpolation.jsh>
#include <pjsr/SampleType.jsh>
#include <pjsr/UndoFlag.jsh>

var w = ImageWindow.activeWindow;
if (w.isNull)
    throw Error ("No image window.");

var v = w.mainView;

var copy_img = new ImageWindow (
    v.image.width, v.image.height,
    v.image.numberOfChannels, v.image.bitsPerSample,
    v.image.sampleType == SampleType_Real,
    true, "foobar23204"
);
copy_img.show();
with (copy_img.mainView) {
    beginProcess (UndoFlag_NoSwapFile);
    //image.apply (v.image); // crash
    //image.assign (v.image); // crash
    //image.clonePixelData (v.image); // err
    //var ap = new Array; v.image.getPixels (ap); image.setPixels (ap); // crash
    //image.transfer (v.image); // err
    image.resample (640, 480, Interpolation_BicubicBSpline);
    endProcess();
}

//copy_img = null;
gc();


The important difference is that I moved the "image.resample" line before the endProcess one. When uncommenting one of the five previous lines, the behaviour of the application is as noted: crash in 3 of the cases and error in the other 2. If no line is uncommented, the application crashes too.

The main PixInsight window disappears and the console from which I run the application says:

Code: [Select]
terminate called after throwing an instance of 'pcl::EUnixSegmentationViolation'
/usr/bin/PixInsight: line 5:  6389 Aborted                 /usr/lib/pixinsight/PixInsight32 $*
--
 David Serrano

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Hard application crash when resampling image from JS
« Reply #1 on: 2007 September 17 03:12:50 »
Hi David,

This is not a bug, actually, but just that you're fooling memory management routines  8)

I have explained it on this thread of the Software Development section. The problem's here:

Code: [Select]
image.resample (640, 480, Interpolation_BicubicBSpline);

and is that you're trying to allocate something like 4x10^12 bytes, which is funny  :lol:
Juan Conejero
PixInsight Development Team
http://pixinsight.com/