Author Topic: Heap corruption invoking PCL function "ProcessInstance::IconsByProcessId"  (Read 1311 times)

Offline enzosantin

  • Member
  • *
  • Posts: 59
    • http://www.enzosantin-astro.com
Sorry for the duplicate post, but it could be a bug, so I have moved it here, under "bug reports".


I'm not an experienced programmer in C++, but I have successfully compiled some module (Sandbox, ImageIntegration ecc...) with Visual Studio Express 2013, then I loaded them in PixInsight and it worked perfectly.


So I used the "Sandbox" module and, just for experimenting, I have written some code that works...  but...


when I call the function:

IsoStringList icons = ProcessInstance::IconsByProcessId( "ProcessContainer" );


or the function:

IsoStringList icons = ProcessInstance::Icons();


PixInsight raise this error: "Internal Error: Invalid routine invoked: MetaProcessContainer::clonationRoutine"

And Microsoft Visual C++ Runtime Library pop up a window with this error description:

"HEAP CORRUPTION DETECTED: after Normal Block (#...) at ...... CRT detected that the application wrote to memory after end of heap buffer".

The problem arises equally if I compile the solution with "Debug x64" or "x64 Release".

What am I doing wrong? Or is this a bug?

Code: [Select]
         /*
          * Your magic comes here...
         */
   static IsoStringList icons;

   Console().WriteLn("<end><cbr> inizio");

   //this works OK
   Process abe = Process("AutomaticBackgroundExtractor");
   Process pc = Process("ProcessContainer");

   //this works OK
   ProcessInstance abeInst = ProcessInstance::FromIcon("abe");
   abeInst.ExecuteOn(view);

   //this call raise a PixInsight exeption "Internal Error: Invalid routine invoked: MetaProcessContainer::clonationRoutine" and
   //the Microsoft exception "HEAP CORRUPTION DETECTED: after Normal Block (#1511) at 0x000000002EAE260 ...
   //the application wrote to memory after end of heap buffer"

   icons = ProcessInstance::IconsByProcessId("ProcessContainer"); // <---

   //this call raise only the Microsoft exception: "HEAP CORRUPTION DETECTED: after Normal Block (#1511) at 0x000000002EAE260 ...
   //the application wrote to memory after end of heap buffer"

   icons = ProcessInstance::Icons(); // <---

   for (size_t i = 0; i < icons.Length(); i++)
   {
   IsoString id = icons[i];
   if (id == "process_target_001")
   {
   //do something
   Console().WriteLn("<end><cbr>Trovato " + id + " !!");
   }
   else
   {
   //do nothing
   Console().WriteLn("<end><cbr>Trovato altro " + id + " = niente di interessante.");
   };
   };

Thanks for the attention!
Enzo

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Hi Enzo,

This is both a bug and a limitation of the platform. Thank you for discovering it. The problem is that you have ProcessContainer icons in your workspace. ProcessContainer is an internal process. Internal processes are those defined by the PixInsight Core application. There are just two of them, the other one is Script.

ProcessContainer is a very special process. It represents one of the fundamental pillars of PixInsight: processing histories. Currently a ProcessContainer cannot be instantiated from a module using the Process, ProcessIntance and ProcessParameter classes, partly because some required API routines have not been implemented for this process, and mainly because there are no abstract resources in PCL to formalize a processing history and its associated functionality. These will be implemented in future versions of the PixInsight Core application and PCL, along with more powerful and flexible implementations of the Process, ProcessIntance, ProcessParameter and ProcessInterface classes.

Unfortunately, the current implementation of ProcessInstance::IconsByProcessId() needs to instantiate the processes encapsulated by the existing icons in order to gather required information about them. If you have ProcessContainer icons, a crash is guaranteed if you call this static member function. This should not happen, of course, so it is obviously a bug.

From the code you've posted, it seems you are trying to instantiate existing processes to perform some sort of automation. If this is what you want to do, I strongly recommend you implement your task in JavaScript. The PJSR does not have any of the limitations described above, and is the best way to execute and control automated processes in PixInsight.
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline enzosantin

  • Member
  • *
  • Posts: 59
    • http://www.enzosantin-astro.com
Hello Juan,
thank you very much for the detailed explanation. I will follow your advice to automate my processes in JavaScript. One of the reasons why I was trying to accomplish that with C ++ / PCL, is the convenience of having a debugger. Anyway, thanks again and ...
W PixInsight forever! :)
Enzo