--- source/backend/parser/parse.cpp.orig
+++ source/backend/parser/parse.cpp
@@ -8438,6 +8438,8 @@
 	PIGMENT *Local_Density;
 	Interior *Local_Interior;
 	MATERIAL *Local_Material;
+	FUNCTION Local_Function;
+	int Local_Function_Number;
 	void *Temp_Data;
 	POV_PARAM *New_Par;
 	int Found=true;
@@ -8518,6 +8520,13 @@
 			function_identifier = (Token.Token_Id==FUNCT_ID_TOKEN) || (Token.Token_Id==VECTFUNCT_ID_TOKEN);
 			callable_identifier = (Token.Token_Id==FUNCT_ID_TOKEN) || (Token.Token_Id==VECTFUNCT_ID_TOKEN) || (Token.Token_Id==SPLINE_ID_TOKEN);
 
+			// hold on to function for passing to Copy_Identifier, in case it goes out of scope while we are parsing
+			if (function_identifier) {
+			    Local_Function = *(FUNCTION_PTR)*Token.DataPtr;
+			    Local_Function_Number = *Token.NumberPtr;
+			    sceneData->functionVM->GetFunctionAndReference(Local_Function);
+			}
+			
 			// don't allow #declares from here
 			Ok_To_Declare = false;
 
@@ -8558,8 +8567,14 @@
 				if(!(ParFlag) || (ParFlag && function_identifier))
 				{
 					// pass by value
+					if (function_identifier) {
+						// *Token.DataPtr and *Token.NumberPtr might have been destroyed
+						Temp_Data = (void*)Copy_Function(&Local_Function);
+						*NumberPtr = Local_Function_Number;
+					} else {
 					Temp_Data  = (void *) Copy_Identifier((void *)*Token.DataPtr,*Token.NumberPtr);
 					*NumberPtr = *Token.NumberPtr;
+					}
 					Test_Redefine(Previous,NumberPtr,*DataPtr, allow_redefine);
 					*DataPtr   = Temp_Data;
 				}
@@ -8616,6 +8631,10 @@
 				}
 			}
 
+			// release function reference
+			if (function_identifier)
+			    sceneData->functionVM->RemoveFunction(Local_Function);
+
 			// allow #declares again
 			Ok_To_Declare = true;
 			EXIT
