Font.export() inside function causes crash

I have a bit of a weird issue, when I run the following script

fontCopy = Font.copy()
fontCopy.export(Format=VARIABLE)
fontCopy.close()

It works fine. But if I run the same code wrapped in a function:

def exportFont():
    fontCopy = Font.copy()
	fontCopy.export(Format=VARIABLE)
	fontCopy.close()
exportFont()

It crashes Glyphs with the following message:

Application Specific Information:
objc_msgSend() selector name: familyName

Do you know why this could be happening?

I suppose someting is not right with the availability of the Font object. Try:

def exportFont(f):
	fontCopy = f.copy()
	fontCopy.export(Format=VARIABLE)
	fontCopy.close()
exportFont(Font)

But why make that copy in the first place?

I should have specified, the same happens with this code as well! Using a reference doesn’t seem to change anything.

I’m making a copy in order to make production changes to the font before export, which I don’t want in the source file.