Application crashes when new lookandfeel is applied

In my application if I delete the old lookandfeel object and set new lookandfeel object, it crashes in Component’s paintContents() code

    if (effect_ != 0)
        delete g;

        effect_->applyEffect (*effectImage, originalG);
        delete effectImage;

The reason I suppose is,
In scrollbar’s resized function the following code is written

 setComponentEffect (getLookAndFeel().getScrollbarEffect());

so when I delete the old lookandfeel object the ImageEffectFilter object is also deleted, but scrollbar is still holding old ImageEffectFilter’s pointer…

So to solve this crash… I override lookAndFeelChanged() function and there ,I again call

 setComponentEffect (getLookAndFeel().getScrollbarEffect());

It works fine then on.

But is this the right solution…
And one more doubt I have is why is that call being called in resized function.

Thanks in advance

…yes. I have to admit I don’t know why that was done in resized()… The correct thing to do is to set the effect in the lookAndFeelChanged method, so that’s what I’ll change it to. Thanks for the bug!