Hi there !
My program exhibits a really strange behaviour !
I got this code
Track::Track( int /*numIns*/, int /*numOuts*/, double /*sampleRate*/, int /*blockSize*/, sb::controller::TimeFactory& timeFactory ) :
_timeFactory(timeFactory),
_playbackMode(ARRANGEMENT),
_currentTime(timeFactory.createTimeFromSamplesNumber(0))
_curentTime type is juce::ScopedPointersb::core::time .
and that’s how timeFactory.createTimeFromSamplesNumber is defined :
juce::ScopedPointer<sb::core::Time> sb::controller::TimeFactory::createTimeFromSamplesNumber( sb::core::SamplesNumber iSamplesNumber )
{
juce::ScopedPointer<sb::core::Time> newTime(new sb::core::Time(_synchronizer));
newTime->setSampleTime(iSamplesNumber);
return newTime;
}
Here, we have only ScopedPointers in action right ?
Now when _currentTime is initialised, I expect that
will be called, to my surprise, it’s not the case !!!
Instead, by tracing through the program, those methods of ScopedPointer are called :
inline operator ObjectType*() const throw() { return object; }
then
inline ScopedPointer (ObjectType* const objectToTakePossessionOf) throw()
: object (objectToTakePossessionOf)
{
}
Which causes double deletion of the object wrapped by the ScopedPointer.
Of course, I can easily solve the problem by replacing
by
but I would really like to understand why the copy constructor isn’t called. If someone could shed light on this …
EDIT : I’m fully aware that this is probably something I overlooked in C++ rather than a Juce problem. However, as there are some people here who know the inner workings of juce::ScopedPointer they might understand the problem and point me to the right track more efficently than, say, StackOverflow people …