Author Topic: PCL: Exception: <* Warning *> Possible hacking attempt: intermodule object detac  (Read 4831 times)

Offline georg.viehoever

  • PTeam Member
  • PixInsight Jedi Master
  • ******
  • Posts: 2132
Hi,

in a module I am writing I am trying to extract luminance from an ImageVariant, storing the result in an ImageVariant again. When I am running my code, I always get "Exception: <* Warning *> Possible hacking attempt: intermodule object detachment" when calling ExtractLuminance(). This happens both for code that I wrote myself, and some code that was inspired by what I see in PCL 2.0. Below is the code and the output I get.

Hints on how to resolve this are welcome.

Georg

Code: [Select]

template <class ImageType>
static ImageVariant extractLuminance(ImageType const & rImage_p,bool bLinear_p)
{
#if 0
// own attempt
ImageType *pResImage=new ImageType(NULL);
std::cout<<"pResImage created"<<std::endl;
rImage_p.ExtractLuminance(*pResImage,bLinear_p);
std::cout<<"pResImage extracted"<<std::endl;
ImageVariant res(pResImage);
std::cout<<"proxy created"<<std::endl;
res.SetOwnership(true);
std::cout<<"res ownership set. Returning"<<std::endl;
return res;
#else
// code inspired by PCL2.0
ImageVariant res;
std::cout<<"res created"<<std::endl;
res.CreateSharedFloatImage(( rImage_p.BitsPerSample() < 32 ) ? 32 : ( rImage_p.IsFloatSample() ? rImage_p.BitsPerSample() : 64 ));
std::cout<<"image created"<<std::endl;
switch(res.BitsPerSample())
{
case 32:
std::cout<<"image extract lum 32 bits"<<std::endl;
rImage_p.ExtractLuminance(*static_cast<FImage *>(res.AnyImage()),bLinear_p);
std::cout<<"image extract lum 32 bits done"<<std::endl;
break;
case 64:
std::cout<<"image extract lum 64 bits"<<std::endl;
rImage_p.ExtractLuminance(*static_cast<DImage *>(res.AnyImage()),bLinear_p);
std::cout<<"image extract lum 64 bits done"<<std::endl;
break;
default:
throw Error("Handling of this bitlength not implemented for extractLuminance");
break;
}
std::cout<<"image extract returning"<<std::endl;
return res;
#endif
}

Output:
Code: [Select]
res created
image created
image extract lum 32 bits
Exception: <* Warning *> Possible hacking attempt: intermodule object detachment
Georg (6 inch Newton, unmodified Canon EOS40D+80D, unguided EQ5 mount)

Offline Nocturnal

  • PixInsight Jedi Council Member
  • *******
  • Posts: 2727
    • http://www.carpephoton.com
I think I ran into that before but don't recall the details. Did you search the forums? Maybe it was discussed before.
Best,

    Sander
---
Edge HD 1100
QHY-8 for imaging, IMG0H mono for guiding, video cameras for occulations
ASI224, QHY5L-IIc
HyperStar3
WO-M110ED+FR-III/TRF-2008
Takahashi EM-400
PIxInsight, DeepSkyStacker, PHD, Nebulosity

Offline georg.viehoever

  • PTeam Member
  • PixInsight Jedi Master
  • ******
  • Posts: 2132
Nothing found  via search, and not via Google.  :-[
Georg (6 inch Newton, unmodified Canon EOS40D+80D, unguided EQ5 mount)

Offline Juan Conejero

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

In PCL 1.x, Generic2DImage does not support implicit data sharing. ImageVariant implements a special data sharing mechanism, but it does not support shared images (i.e. images living in the PI Core application). This means that you cannot return an ImageVariant object by value if it transports a shared image. With a local image it should work, though. These limitations don't exist in PCL 2.0.

For now, try this code:

Code: [Select]
template <class ImageType>
static void extractLuminance( ImageVariant& L, const ImageType& image, bool linear )
{
   if ( !L.IsImage() )
      L.CreateSharedFloatImage( (image.BitsPerSample() < 32) ? 32 : (image.IsFloatSample() ? image.BitsPerSample() : 64) );
   switch ( L.BitsPerSample() )
   {
   case 32:
      std::cout << "image extract lum 32 bits" << std::endl;
      image.ExtractLuminance( *static_cast<FImage*>( L.AnyImage() ), linear );
      std::cout << "image extract lum 32 bits done" << std::endl;
      break;
   case 64:
      std::cout << "image extract lum 64 bits" << std::endl;
      image.ExtractLuminance( *static_cast<DImage*>( L.AnyImage() ), linear );
      std::cout << "image extract lum 64 bits done" << std::endl;
      break;
   default:
      throw Error( "Handling of this bitlength not implemented for extractLuminance" );
      break;
   }
}

By the way, in PCL 2.0 this task is already implemented in GenericImage and ImageVariant. The above code is equivalent to this in PCL 2.0:

Code: [Select]
ImageVariant L;
if ( linear )
   image.GetLuminance( L );
else
   image.GetLightness( L );

Note that the ExtractLuminance() member function does not exist in PCL 2.0 (it was a design error). Let me know if this helps.
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline georg.viehoever

  • PTeam Member
  • PixInsight Jedi Master
  • ******
  • Posts: 2132
Juan,

thanks for the answer. I guess I'll wait for PCL2.0 which appears to make things so much easier for what I have in mind.

One remark though: It would be important to document this reference counting model that PCL has somewhere. I seem to remember a few remarks in the doxygen, but I never saw a consistent explanation.

Georg
Georg (6 inch Newton, unmodified Canon EOS40D+80D, unguided EQ5 mount)

Offline georg.viehoever

  • PTeam Member
  • PixInsight Jedi Master
  • ******
  • Posts: 2132
Hi Juan,
I am afraid I still get the error message (with the currently release PCL, not 2.0). I followed your source proposal (see below), but I still get this output:

Code: [Select]
Before ExtractLuminance
Traceback (most recent call last):
  File "python3DPlot.py", line 25, in execute_on
    lumImage=image.get_luminance()
Exception: <* Warning *> Possible hacking attempt: intermodule object detachment
*** Error: Problem while executing execute_on() (see console for details)

The problem happens inside the call to image.ExtractLuminance() (see print statements there). Source code below (or in https://bitbucket.org/georgviehoever/pixinsight in src/modules/processes/Python/PythonBindings.cpp)

Any proposals on how to proceed? Should I wait for PCL 2.0 or try to resolve it with the current version?

Georg

Code: [Select]
// using dispatch method "borrowed" from PCL2.0:
/// dispatch depending on type of ImageVariant in self. F is expected to be a macro that
/// expects the concrete GenericImage2D<> type as argument.
#define PYTHON_SOLVE_TEMPLATE( F )         \
if ( self.IsComplexSample() )                   \
switch ( self.BitsPerSample() )             \
{                                      \
case 32: F( ComplexImage ); break; \
case 64: F( DComplexImage ); break;\
    }                                      \
else if ( self.IsFloatSample() )                \
    switch ( self.BitsPerSample() )             \
    {                                      \
        case 32: F( Image ); break;        \
        case 64: F( DImage ); break;       \
    }                                      \
else                                       \
    switch ( self.BitsPerSample() )             \
   {                                       \
        case  8: F( UInt8Image ); break;   \
        case 16: F( UInt16Image ); break;  \
        case 32: F( UInt32Image ); break;  \
   }


/// sets resImage to luminance of rImage_p
// FIXME this still fails while calling ExtractLuminance
template <class ImageType>
static void imagevariant_getLuminance(ImageType const & rImage_p, FImage &resImage_p)
{
std::cout<<"Before ExtractLuminance"<<std::endl;
rImage_p.ExtractLuminance( resImage_p,1);
std::cout<<"After ExtractLuminance"<<std::endl;
}

/// get the luminance of self. Note that ownership of the returned reference is with the caller
ImageVariant * imagevariant_get_luminance(ImageVariant const & self)
{

ImageVariant &res= *new ImageVariant();
// FIXME supporting more image depths requires more complex dispatch
// res.CreateSharedFloatImage(32);
res.CreateFloatImage(32);
#define _EXTRACT_LUMINANCE(I) \
imagevariant_getLuminance(static_cast<const pcl::I&>( *self ),static_cast<FImage &>( *res ))
PYTHON_SOLVE_TEMPLATE(_EXTRACT_LUMINANCE)
res.SetOwnership(true);
return &res;
#undef _EXTRACT_LUMINANCE
}
Georg (6 inch Newton, unmodified Canon EOS40D+80D, unguided EQ5 mount)