File selector crash on OSX 32bit app (Bad Access)

Hello,

I’ve been reported that one of my plug-ins crashes as soon as the user tries to open a file selector.
This only happens on 32 bit plug-ins and the issue happens systematically, as I’ve just installed Reaper 32bit on my Mac and experienced the same issue.
The 64 bit version works perfectly (I compile my plug-ins as universal binaries), so I don’t know if this is some kind of bridging problem.
I’ve only tried it in Reaper, but the user told me it’s happening on other 32 bit hosts too.

The error is Bad Access and happens here (see the line comment):

bool CocoaFileSelector::runInternal (CBaseObject* _delegate)
{
	CBaseObjectGuard lifeGuard (this);

	NSWindow* parentWindow = nil;
	if (_delegate)
	{
		#if MAC_COCOA
		if (frame && frame->getPlatformFrame ())
		{
			NSViewFrame* nsViewFrame = static_cast<NSViewFrame*> (frame->getPlatformFrame ());
			parentWindow = nsViewFrame ? [(nsViewFrame->getNSView ()) window] : nullptr; //*** BAD ACCESS ***
		}
		#endif
		delegate = _delegate;
	}
...

Is this a bug?
Can someone confirm the issue?

Regards,
Federico

Hi Federico,

This probably happens due to the fact that 32 bit VST2 is hosted using Carbon instead of Cocoa, so statically casting frame->getPlatformFrame () to a NSViewFrame* pointer yields an invalid pointer. Maybe try using a dynamic cast here and assume it’s a HIViewFrame if you obtain a nullptr. You can also simply use IPlatformFrame::getPlatformRepresentation() instead to retrieve an abstract representation of the container window.

Best,
Ray

Yeah, that’s one of the things that came to my mind!
In fact I’ve tried to compile the plug-in enabling Carbon instead of Cocoa and it was working.
Thanks for the tips, I’ll give them a try!