mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
AU Host: Avoid using wrong BundleResourceMap when opening plugin from file
Previously it was possible to have a dangling resource map. In that case opening an AU from a file that did not have a resource map would lead to using the previously unclosed map and attempting to load the previous plugin again.
This commit is contained in:
parent
55b00fc846
commit
5343f70d02
1 changed files with 30 additions and 5 deletions
|
|
@ -216,13 +216,40 @@ namespace AudioUnitFormatHelpers
|
|||
if (manuString != nullptr && CFGetTypeID (manuString) == CFStringGetTypeID())
|
||||
manufacturer = String::fromCFString ((CFStringRef) manuString);
|
||||
|
||||
const ResFileRefNum resFileId = CFBundleOpenBundleResourceMap (bundleRef.get());
|
||||
UseResFile (resFileId);
|
||||
class ScopedBundleResourceMap final
|
||||
{
|
||||
public:
|
||||
explicit ScopedBundleResourceMap (CFBundleRef refIn) : ref (refIn),
|
||||
resFileId (CFBundleOpenBundleResourceMap (ref)),
|
||||
valid (resFileId != -1)
|
||||
{
|
||||
if (valid)
|
||||
UseResFile (resFileId);
|
||||
}
|
||||
|
||||
~ScopedBundleResourceMap()
|
||||
{
|
||||
if (valid)
|
||||
CFBundleCloseBundleResourceMap (ref, resFileId);
|
||||
}
|
||||
|
||||
bool isValid() const noexcept
|
||||
{
|
||||
return valid;
|
||||
}
|
||||
|
||||
private:
|
||||
const CFBundleRef ref;
|
||||
const ResFileRefNum resFileId;
|
||||
const bool valid;
|
||||
};
|
||||
|
||||
const ScopedBundleResourceMap resourceMap { bundleRef.get() };
|
||||
|
||||
const OSType thngType = stringToOSType ("thng");
|
||||
auto numResources = Count1Resources (thngType);
|
||||
|
||||
if (numResources > 0)
|
||||
if (resourceMap.isValid() && numResources > 0)
|
||||
{
|
||||
for (ResourceIndex i = 1; i <= numResources; ++i)
|
||||
{
|
||||
|
|
@ -268,8 +295,6 @@ namespace AudioUnitFormatHelpers
|
|||
|
||||
[bundle release];
|
||||
}
|
||||
|
||||
CFBundleCloseBundleResourceMap (bundleRef.get(), resFileId);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue