Skip to content

Commit

Permalink
Hardened some functions which could throw exceptions
Browse files Browse the repository at this point in the history
drowaudio committed Jan 17, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 295e57b commit 597b227
Showing 11 changed files with 53 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -229,7 +229,7 @@ AudioProxyGenerator::GeneratorJob::GeneratorJob (const AudioFile& p)
AudioProxyGenerator::GeneratorJob::~GeneratorJob()
{
prepareForJobDeletion();
callBlocking ([this] { proxy.engine->getAudioFileManager().validateFile (proxy, false); });
callBlockingCatching ([this] { proxy.engine->getAudioFileManager().validateFile (proxy, false); });
}

juce::ThreadPoolJob::JobStatus AudioProxyGenerator::GeneratorJob::runJob()
Original file line number Diff line number Diff line change
@@ -37,6 +37,7 @@ AutomationRecordManager::AutomationRecordManager (Edit& ed)
}
else
{
// Exception will be caught by the Edit constructor
callBlocking ([this] { edit.getTransport().addChangeListener (this); });
}
}
Original file line number Diff line number Diff line change
@@ -233,6 +233,7 @@ ModifierList::ModifierList (Edit& e, const juce::ValueTree& parentTree)
edit (e), state (parent)
{
jassert (parent.hasType (IDs::MODIFIERS));
// Exception will be caught by Edit constructor
callBlocking ([this] { rebuildObjects(); });
}

Original file line number Diff line number Diff line change
@@ -299,6 +299,7 @@ void AudioClipBase::initialise()
setCurrentSourceFile (audioFile.getFile());
}

// Exception will be caught by Edit constructor
if (! edit.getUndoManager().isPerformingUndoRedo())
callBlocking ([this] { setLoopDefaults(); });
}
Original file line number Diff line number Diff line change
@@ -138,7 +138,7 @@ std::unique_ptr<AudioSegmentList> AudioSegmentList::create (AudioClipBase& acb,
wtm.getWarpEndMarkerTime());

juce::Array<TimeRange> warpTimeRegions;
callBlocking ([&] { warpTimeRegions = wtm.getWarpTimeRegions (region); });
callBlockingCatching ([&] { warpTimeRegions = wtm.getWarpTimeRegions (region); });
auto position = warpTimeRegions.size() > 0 ? warpTimeRegions.getUnchecked (0).getStart() : TimePosition();

for (auto warpRegion : warpTimeRegions)
30 changes: 20 additions & 10 deletions modules/tracktion_engine/model/clips/tracktion_ClipEffects.cpp
Original file line number Diff line number Diff line change
@@ -390,8 +390,17 @@ struct AudioNodeRenderJob : public ClipEffect::ClipEffectRenderJob
bool setUpRender() override
{
CRASH_TRACER
callBlocking ([this] { createAndPrepareRenderContext(); });
return true;
try
{
callBlocking ([this] { createAndPrepareRenderContext(); });
return true;
}
catch (std::runtime_error& err)
{
TRACKTION_LOG_ERROR (err.what());
}

return false;
}

bool renderNextBlock() override
@@ -1259,18 +1268,18 @@ struct PluginUnloadInhibitor : private juce::Timer

void load()
{
callBlocking ([this]() { plugin->setProcessingEnabled (true); callback(); });
callBlockingCatching ([this] { plugin->setProcessingEnabled (true); callback(); });
}

void unload()
{
callBlocking ([this]() { plugin->setProcessingEnabled (false); callback(); });
callBlockingCatching ([this] { plugin->setProcessingEnabled (false); callback(); });
}

int count = 0;
Plugin::Ptr plugin;
juce::ReferenceCountedArray<AudioNodeRenderJob> jobs;
std::function<void(void)> callback;
std::function<void()> callback;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PluginUnloadInhibitor)
};
@@ -1294,6 +1303,7 @@ PluginEffect::PluginEffect (const juce::ValueTree& v, ClipEffects& o)
if (pluginState.isValid())
{
pluginState.setProperty (IDs::process, false, nullptr); // always restore plugin to non-processing state on load
// Exception will be caught by Edit constructor
callBlocking ([this, pluginState]() { plugin = edit.getPluginCache().getOrCreatePluginFor (pluginState); });
}

@@ -1753,11 +1763,11 @@ struct AggregateJob : public RenderManager::Job
afm.releaseFile (currentJob->destination);

if (! currentJob->destination.isNull())
callBlocking ([&afm, fileToValidate = currentJob->destination]
{
afm.validateFile (fileToValidate, true);
jassert (fileToValidate.isValid());
});
callBlockingCatching ([&afm, fileToValidate = currentJob->destination]
{
afm.validateFile (fileToValidate, true);
jassert (fileToValidate.isValid());
});

lastFile = currentJob->destination.getFile();
currentJob = nullptr;
Original file line number Diff line number Diff line change
@@ -163,10 +163,17 @@ NodeRenderContext::~NodeRenderContext()
if (writer != nullptr)
writer->closeForWriting();

callBlocking ([this] { nodePlayer.reset(); });
try
{
callBlocking ([this] { nodePlayer.reset(); });

if (needsToNormaliseAndTrim)
owner.performNormalisingAndTrimming (originalParams, r);
if (needsToNormaliseAndTrim)
owner.performNormalisingAndTrimming (originalParams, r);
}
catch (std::runtime_error& err)
{
TRACKTION_LOG_ERROR (err.what());
}
}

bool NodeRenderContext::renderNextBlock (std::atomic<float>& progressToUpdate)
Original file line number Diff line number Diff line change
@@ -1089,7 +1089,7 @@ void ExternalPlugin::restorePluginStateFromValueTree (const juce::ValueTree& v)
chunk.fromBase64Encoding (s);

if (chunk.getSize() > 0)
callBlocking ([&pi, &chunk] { pi->setStateInformation (chunk.getData(), (int) chunk.getSize()); });
callBlockingCatching ([&pi, &chunk] { pi->setStateInformation (chunk.getData(), (int) chunk.getSize()); });
}
}

Original file line number Diff line number Diff line change
@@ -46,6 +46,7 @@ struct RackType::RackPluginList : public ValueTreeObjectList<RackType::PluginIn
: ValueTreeObjectList<PluginInfo> (parentTree), type (t)
{
CRASH_TRACER
// Exception will be caught by the Edit constructor
callBlocking ([this] { this->rebuildObjects(); });
}

@@ -151,6 +152,7 @@ struct RackType::WindowStateList : public ValueTreeObjectList<WindowState>
: ValueTreeObjectList<WindowState> (t.state), type (t)
{
CRASH_TRACER
// Exception will be caught by the Edit constructor
callBlocking ([this] { this->rebuildObjects(); });
}

1 change: 1 addition & 0 deletions modules/tracktion_engine/plugins/tracktion_PluginList.cpp
Original file line number Diff line number Diff line change
@@ -94,6 +94,7 @@ void PluginList::initialise (const juce::ValueTree& v)

state = v;
list = std::make_unique<ObjectList> (*this, state);
// Exception will be caught by the Edit constructor
callBlocking ([this] { list->rebuildObjects(); });
}

14 changes: 14 additions & 0 deletions modules/tracktion_engine/utilities/tracktion_AsyncFunctionUtils.h
Original file line number Diff line number Diff line change
@@ -288,5 +288,19 @@ inline bool callBlocking (std::function<void()> f)
return true;
}

/** The same as callBlocking expect the exception is caught and ignored.
Use this when failue is ok.
*/
inline bool callBlockingCatching (std::function<void()> f) noexcept
{
try
{
return callBlocking (std::move (f));
}
catch (std::runtime_error&)
{
return false;
}
}

}} // namespace tracktion { inline namespace engine

0 comments on commit 597b227

Please sign in to comment.