Access Violation Using Custom Look and Feel


#1

I’m trying to implement a custom look and feel for a rotary slider using MS Visual Studio 2015 and Projucer Version 4.3.1. This slider appears to function properly but I get the following exception upon closing my application:

Exception thrown: read access violation.
juce::Component::getLookAndFeel(…). was 0xDDDDDDDD

I’m attempting to override only the “drawRotarySlider()” method the same way it’s done in the “LookAndFeelDemp.cpp” demo as follows:

//---------------------------------------------------------------------------------------------
struct CustomLookAndFeel : public LookAndFeel_V3
{
void drawRotarySlider (Graphics& g, int x, int y, int width, int height, float sliderPos,
float rotaryStartAngle, float rotaryEndAngle, Slider& slider) override
{

’ (same as in demo)

}
}
//---------------------------------------------------------------------------------------------

In my main component I’m adding my custom look & feel in the same way the demo does it:

//---------------------------------------------------------------------------------------------
CustomLookAndFeel* claf = new CustomLookAndFeel();
lookAndFeels.add (claf);
setLookAndFeel(claf) ;
//---------------------------------------------------------------------------------------------

and defining

//---------------------------------------------------------------------------------------------
OwnedArray lookAndFeels;
//---------------------------------------------------------------------------------------------

Apparently, I’m missing something.


#2

IIRC the 0xDDDDDDD is placed by the debugger to hint that the pointee (i.e. the look and feel instance) was already deleted.

When the OwnedArray goes out of scope, there is at least one component still alive, that references it. Probably the MainComponent.
Setting setLookAndFeel (nullptr); in the destructor should help you out…

HTH


#3

Thank you very much - that solved the problem!


#4

Daniel,

Thank you very much - that solved the problem!

Chuck