Author Topic: 1.7 low-level API function error ?  (Read 6732 times)

Offline Ioannis Ioannou

  • PixInsight Addict
  • ***
  • Posts: 202
1.7 low-level API function error ?
« on: 2011 May 31 01:21:34 »
OK, I need some help here.
Just upgraded PI to 1.7 (uninstalled previous, installed new) and I'm getting this error (tried with star alignment but happens with ImageIntegration also).
Win7 64bit.
« Last Edit: 2011 May 31 03:20:11 by Ioannis Ioannou »
Clear Skies
John (Ioannis)

FSQ106N+Robofocus+QHY-22+SX USB wheel+Baader filters
SX OAG+DSI Pro guiding a NEQ6
PI for the rest :)

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Re: 1.7 low-level API function error ?
« Reply #1 on: 2011 May 31 01:52:58 »
Hi John,

OK, I can reproduce this problem. It seems a small bug that I'm fixing right now. I'll publish an update as soon as it is resolved.

Sorry for the inconvenience!
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Re: 1.7 low-level API function error ?
« Reply #2 on: 2011 May 31 02:31:51 »
Update: I've found the bug, but it is not my bug. It is a bug in the Visual C++ 2010 64-bit compiler. Maybe Visual Studio 2010 isn't as good as it seemed to be at first...  will these guys write a decent compiler some day? ::)

I'm trying to find a workaround (that is, to destroy my code so it works with VC++ 2010) as soon as possible.
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline Ioannis Ioannou

  • PixInsight Addict
  • ***
  • Posts: 202
Re: 1.7 low-level API function error ?
« Reply #3 on: 2011 May 31 03:12:29 »
Thank you Juan,

I guess I can use the 32bit for the moment (and I always have my Linux machine at home - no problem).
Clear Skies
John (Ioannis)

FSQ106N+Robofocus+QHY-22+SX USB wheel+Baader filters
SX OAG+DSI Pro guiding a NEQ6
PI for the rest :)

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Re: 1.7 low-level API function error ?
« Reply #4 on: 2011 May 31 08:18:15 »
Good news: this bug is now fixed. PI version 1.7.0.696 for Windows will be released as a regular update this evening.

Information for developers

Just for the fun of it, here is a description of this bug. Although it seems an easy one (and it's easy to fix actually), finding it has been quite difficult.

Code excerpted from pcl/ImageVariant.h:

Code: [Select]
137: class PCL_CLASS ImageVariant
138: {
139: public:
140:
141:    typedef AbstractImage::color_space  color_space;
142:
143:    /*!
144:       Constructs an %ImageVariant instance that does not transport an image.
145:    */
146:    ImageVariant() : data( new Data )
147: #ifdef __PCL_BUILDING_PIXINSIGHT_APPLICATION
148:       , shared( 0 )
149: #endif
150:    {
151:    }
152:
   // ...

There's nothing fancy here: just a default constructor for class pcl::ImageVariant. The __PCL_BUILDING_PIXINSIGHT_APPLICATION macro is defined, as its name clearly says, only when we are building the PixInsight Core application. Hence, the shared data member (a pointer) only exists within the core application, and is initialized to zero by the constructor in line #148. Again, nothing too complex; just a data pointer correctly initialized.

The problem is that Visual C++ 2010 x64 ignores the code in line 148 completely. There is no way to convince it that this line must be compiled, including all sorts of permutations of punctuators and whitespace characters. Nothing is generated for 'shared( 0 )'. Putting a sentence like 'shared = 0;' in the constructor's body does not help either; VC++ 2010 x64 ignores it for some exotic reason. So the shared data member is never initialized on Windows x64 when an ImageVariant instance is constructed. This has no practical consequences within the core application, but a few modules that load images dynamically lead to access violation errors when they try to use PCL's shared image mechanisms.

The solution to this bug is relatively straightforward. I have added this declaration to the ImageVariant class:

Code: [Select]
1020: #ifdef __PCL_BUILDING_PIXINSIGHT_APPLICATION

   // ...

1035:    /*
1036:     * Workaround to Visual C++ compiler error ('shared' member not initialized)
1037:     */
1038: #  ifdef __PCL_WINDOWS
1039:    static ImageVariant* NewImageVariant();
1040: #  endif
1041:
1042: #endif

whose implementation is as simple as:

Code: [Select]
34: #ifdef __PCL_WINDOWS
35: ImageVariant* ImageVariant::NewImageVariant()
36: {
37:    ImageVariant* v = new ImageVariant;
38:    v->shared = 0;
39:    return v;
40: }
41: #endif

This forces initialization of the shared data member to zero (and luckily VC++ compiles it!). Then, each time a new ImageVariant is dynamically created in the PI Core application we have:

#ifdef __PCL_WINDOWS
      ImageVariant* img = ImageVariant::NewImageVariant();
#else
      ImageVariant* img = new ImageVariant;
#endif

I want to stress the fact that this problem does not happen on any platform except Windows x64. This includes 32-bit Windows, where the original code works perfectly. I have made no distinctions between Win64 and Win32 however, just to stay on the safe side.

There is another bug that I have also fixed, and it is also a VC++ compiler bug. I'll describe it later.

End of the story :)
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline georg.viehoever

  • PTeam Member
  • PixInsight Jedi Master
  • ******
  • Posts: 2132
Re: 1.7 low-level API function error ?
« Reply #5 on: 2011 May 31 10:39:02 »
Hi Juan,

I am not sure, but an issue may be the fact that this constructor is not only declared, but also defined in the header. So external modules and your core module see different definitions of the constructor, which may be a problem. I am not sure how the M$ linker resolves such a situation. Maybe it tries to be clever: which definition of ImageVariant() is it supposed to use: the one in the core application, or the one in the module?

I would recommend to keep headers indentical in structure and contents, no matter where they are used. This could easily be done by initialising shared in an if-statement that calls some function that decides on the desired behaviour.

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

Offline budguinn

  • PixInsight Addict
  • ***
  • Posts: 106
Re: 1.7 low-level API function error ?
« Reply #6 on: 2011 May 31 18:23:59 »
Hi Juan,

Will I just be able to use the 'check for updates' function?

best,

bud


Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Re: 1.7 low-level API function error ?
« Reply #7 on: 2011 June 01 00:21:53 »
Hi,

This bug has been fixed in PixInsight Core 1.7.0.696. The new version is now available as a regular update for Windows x86 and x64.

Thanks for your patience!
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline Ioannis Ioannou

  • PixInsight Addict
  • ***
  • Posts: 202
Re: 1.7 low-level API function error ?
« Reply #8 on: 2011 June 01 02:08:48 »
Yap, working like a charm.
We thank you Juan for the fast response.

Clear Skies
John (Ioannis)

FSQ106N+Robofocus+QHY-22+SX USB wheel+Baader filters
SX OAG+DSI Pro guiding a NEQ6
PI for the rest :)

Offline budguinn

  • PixInsight Addict
  • ***
  • Posts: 106
Re: 1.7 low-level API function error ?
« Reply #9 on: 2011 June 01 06:51:52 »
fixed for me, also.....thanks

Offline LEMBADION

  • Newcomer
  • Posts: 2
Re: 1.7 low-level API function error ?
« Reply #10 on: 2011 June 01 17:35:50 »
I was having the same error

Now corrected

Thank Juan.