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

A user interface toolkit mainly for audio plug-ins (VST, AudioUnit, etc).
Post Reply
f.berti
Posts: 22
Joined: Thu Nov 02, 2017 5:50 pm

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

Post by f.berti » Mon Mar 04, 2019 8:51 am

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):

Code: Select all

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

ray
Posts: 97
Joined: Fri Sep 02, 2016 9:37 am

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

Post by ray » Tue Mar 05, 2019 8:57 am

f.berti wrote: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):

Code: Select all

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

f.berti
Posts: 22
Joined: Thu Nov 02, 2017 5:50 pm

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

Post by f.berti » Tue Mar 05, 2019 9:35 am

ray wrote: 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!

Post Reply