Author Topic: [PJSR 1.8]Change of behavior of window close  (Read 5226 times)

Offline bitli

  • PTeam Member
  • PixInsight Guru
  • ****
  • Posts: 513
[PJSR 1.8]Change of behavior of window close
« on: 2013 January 04 10:27:06 »
In 1.7, I had to do a lot of horrible tricks to find which window a process had created (in VaryParams). One of the problem was that it was difficult to know if a view had been closed previously. I keep track of all view uniqueid and close operations. This kind of works.  I still do the same thing in 1.8, but in some case it did not work so well. It seems that the windows are kept longer than they used to.  I think that I have a work around by calling gc(true) before enumerating the windows. This is ugly at best.
The question: is there now a way to know that a window/view was requested to close (I do not care if QT effectively closed the window yet or not).  Or better is there a way to know which windows were created by the execution of a process ?
-- bitli

Offline mschuster

  • PTeam Member
  • PixInsight Jedi
  • *****
  • Posts: 1087
Re: [PJSR 1.8]Change of behavior of window close
« Reply #1 on: 2013 January 04 10:37:14 »
+1. I use tricks also. A solution would be good.
Mike

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Re: [PJSR 1.8]Change of behavior of window close
« Reply #2 on: 2013 January 05 04:29:40 »
This problem has already been fixed in PI 1.8.0.

In 1.8.0 RC1, you can use the following property:

Boolean ImageWindow.isClosed

to filter out closed windows. For example:

Code: [Select]
var windows = ImageWindow.windows;
for ( var i = 0; i < windows.length; ++i )
   if ( !windows[i].isClosed )
      console.writeln( windows[i].mainView.id );

In 1.8.0 RC2 we have a new property of ImageWindow, namely:

Array ImageWindow.openWindows

which returns an array with windows that have not been closed and are not being destroyed. The old windows property:

Array ImageWindow.windows

continues as before, i.e. it includes all windows, also those windows that are pending of garbage collection.
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline bitli

  • PTeam Member
  • PixInsight Guru
  • ****
  • Posts: 513
Re: [PJSR 1.8]Change of behavior of window close
« Reply #3 on: 2013 January 05 05:21:47 »
Thanks, I added the use of isClose conditionally on the version. It helps in handling the window close state, but I still have a problem which is systematic if I do not do gc(true) between two call of a process, and occasional if I do the gc(true). 
I continue to investigate, but it seems that the script cannot recongize the primary view created by a process in some case. As I keep track of closed windows/views and skip them when looking for the resulting window, is it possible that a uniqueId or window is reused ?
I'll keep you informed of my investigations.
-- - bitli

Offline bitli

  • PTeam Member
  • PixInsight Guru
  • ****
  • Posts: 513
Re: [PJSR 1.8]Change of behavior of window close
« Reply #4 on: 2013 January 05 08:24:53 »
OK, I tracked down as much as I could.  My findings:

In some rare cases, ImageWindow.windows return a single ImageWindow object, instead of an array of ImageWindow. I am not able to reproduce it in a simple case, this happens only in PJSR 1.8RC1, when I call multiple process in the same script, and only on a function that was called 2 level deep (I know it sounds crazy).  ImageWindow.windows returns the proper array just before and just after calling the method use ImageWindow internally.
This happens far less often if I call gc(true) between the execution of the processes, but still happens (after 6 to 8 calls to a process, instead of after the second one).
Also PI crashes quite often when I exit it after having that problem.  Maybe some memory corruption somewhere?

There is not much I can do, I will pack the other small corrections (they impact only error handling and tests), and the use of isClose, as a new version.  I added code to test the above condition and throw an exception in case it happens. This does not seem to be the case when using VaryParams interactively (in opposition of calling it via the test scripts).

I can give you indication to reproduce the problem, but it is somewhat lengthy.
-- bitli