I have a component owning a viewport, and when I set the viewport's LookAndFeel to a custom one, XCode crashes on the following line:
void ScrollBar::lookAndFeelChanged()
{
setComponentEffect (getLookAndFeel().getScrollbarEffect()); // Crashes here (EXC_BAD_ACCESS)
if (isVisible())
resized();
}
The debugger reveals that indeed, the lookAndFeel of the ScrollBar object is indeed a NULL.
I've used the custom LookAndFeel class for several other components without problem and have yet to implement some scrollbar virtuals, so I'm not sure what's really going wrong.
Anyone have an idea? As usual, any help is much appreciated.
It should be impossible for getLookAndFeel to return a nullptr.. If that happens, something is very wrong! Maybe you've deleted your l+f object while it's still being used?
I'm quite sure I haven't. Other objects are using it as well (popupmenu's), etc.
Is lookAndFeelChanged() immediately (synchronously) called when a new lookandfeel is set, or does that go through a messaging system like the paint functionality?
-----
Could it be that viewport doesn't pass its new L&F along to its scrollbars? When I step into setLookAndFeel, it assigns the new L&F to its own internal variable and then calls sendLookAndFeelChange() recursively without telling the scrollbars what their new L&F is.
Ok, I still have no idea what the problem was, but stepping inside getLookAndFeel() made me realised components look for their lookandfeel in their parents, so setting it once in my top component solved the problem.
...really weird.
I'll get back at you when I figure out what the problem was.