By static I meant 'non pointer' variables. Okay so this doesn't seem to be the problem causing the crash. Gdb ends up showing the same heap error I started this thread with. Can you spot an error as to why that keeps happening ?
On Aug 28, 2013 2:25 AM, "Krzysztof Kosiński" <tweenk.pl@...400...> wrote:2013/8/27 Arshdeep Singh <moduli16@...400...>:
> I added:
> new (&(priv->nodes)) std::map<std::string,RecolorWheelNode>();
> to recolor_wheel_init (RecolorWheel *wheel) .
>
> Honestly I have never seen this style of code, so I really don't understand
> what it does. The good news is it does get to run the dialog box of 'Recolor
> Artwork' i.e. no error while the dialog is loaded, but the moment I draw a
> shape (active selection) the application crashes.
This 'style of code' is known as 'placement new' and it calls the
constructor of an object with an explicit 'this' pointer. It needs to
be used when memory for an object is allocated from a different source
than operator new.
In normal C++, placement new is rarely used, because objects are
typically allocated and constructed at the same time with operator
new. However, if you allocate memory from a different source (in this
case from GObject), you need to call the constructor yourself.
http://en.wikipedia.org/wiki/Placement_syntax
> Also my init function looks like this (for a quick browse, if needed):
>
> static void
> recolor_wheel_init (RecolorWheel *wheel)
> {
>
> RecolorWheelPrivate *priv;
>
> priv = G_TYPE_INSTANCE_GET_PRIVATE (wheel, RECOLOR_TYPE_COLOR_WHEEL,
> RecolorWheelPrivate);
>
> wheel->priv = (RecolorWheelPrivate*)priv;
> priv = (RecolorWheelPrivate*)wheel->priv ;
What is the point of the last line? Why the casts? They are unnecessary.
> What I don't undersytnd is how to initilaize a static object.
> RecolorWheelPrivate has other static members like :
What exactly do you mean by "static members"? The structure you
provided does not define any static members.
> gdouble h,s,v don't need explicit initializers. Why so ? Is it that the only
> map object requires an explicit initilization. If so, why ?
'gdouble' is a primitive type (a typedef of 'double') which doesn't
have any constructors. GObject zeroes memory by default, so if you
don't assign to h, s, v they are left as all zeroes, which corresponds
to the double value of 0.0.
Regards, Krzysztof