[Qgis-developer] Cannot inherit from QgsVectorLayer in plugin on Windows

Mateusz Loskot mateusz at loskot.net
Sun Aug 27 23:22:33 EDT 2006


Tim Sutton wrote:
> Hi
> 
> I wonder if its anything to do with the win dll boundary issue :
> 
> http://msdn2.microsoft.com/en-us/library/ms235460.aspx
> 

I assume Tim is right, however the article above does not
mention similar situation that likely occurs in QGIS/plugins on Windows.

Generally, inheriting from class in external DLL is a bad idea
on Windows, unless developer will promise that the base class
does not allocate anything and return it outside.
For example

// a.dll
struct B {};

struct A
{
   // Ownership transfered to the caller
   B* getB()
   {
      B* p = new B();
      return p;
   }
};

// c.dll
struct C : public A
{
   void foo()
   {
      B* p = getB();
      //...
      delete p; // BOOM!!! DLL boundaries crossed
   }
};

Although, I'm not sure if QgsVectorLayer does apply to this situation.
May be there are some resources allocated in constructor of the base
class, and then they cross DLL boundaries. That would be likely unsafe
too, on Windows.

But I think it may be necessary to track where the crash
occurs, to know what's the exact reason.

Cheers
-- 
Mateusz Loskot
http://mateusz.loskot.net



More information about the Qgis-developer mailing list