Maxscript Problem causing SEH exception on Deadline

Unfortunately I can’t post the full code here as I have a very complex tool I’m working on, and for some reason I’m getting SEH exception in RenderFrame() when rendering the job on deadline. The code works locally fine, and on a single execution sending to deadline works fine too. But if I use the code in a loop to send multiple passes to Deadline it’s causing issues. If I open the pass from the deadline repository and render it locally it works.

The issue appears to come from the process of adding rendering elements in my script… to massively overly simplify things the process is this… and seems to cause the same error… any ideas?

[code] setWaitCursor()
Holdmaxfile()
for i = 1 to 2 do
(

		makedir "Y:\\CGI_R&D\\_Scripts\\Helium_RP\\Test_Files" all:true
		rendSaveFile = true
		rendOutputFilename = "Y:\\CGI_R&D\\_Scripts\\Helium_RP\\Test_Files\\Render_15_.tga"
		--Making MME Render Element
		re = maxOps.GetCurRenderElementMgr()
		re.addrenderelement (MultiMatteElement elementname:"MME_1")
		theelement = re.getrenderelement (re.numrenderelements() - 1)
		theelement.R_gbufIDOn = true
		theelement.R_gbufID = 1
		theelement.G_gbufIDOn = true
		theelement.G_gbufID = 2
		theelement.B_gbufIDOn = true
		theelement.B_gbufID = 3
		theelement.MatID = true
		theelement.affect_matte_objects = true
		
		
		--temp variables
		tilesrendering = false
		RenderCam = "Camera001"
		thepassname = "rgb"
		
		
		(
			thetempfile = SMTDPaths.TempDir + maxfilename
			print "THE TEMP FILE"
			print thetempfile
			if (doesFileExist thetempFile) do deleteFile thetempFile
			SaveMaxFile thetempfile usenewfile:false
			rendSaveFile = true
			
			
			
		   global SMTDSettings  --this is the global variable that will contain the submission settings of SMTD
		   global SMTDFunctions --this is the global variable that will contain the submission functions of SMTD
			
		   local theNetworkRoot = "" --this variable will hold the network root path - the path to the Repository
		   local theHomeRoot = "" --this variable will hold the local home folder of Deadline
			
		   --------------------------------------
		   --MAIN SUBMISSION CODE
		   --------------------------------------
			 
			  theNetworkRoot = "\\\\xxx.xxxxxxxxxxxx.com\\DeadlineRepository" --repository location
			  format "Network Root is '%'\n" theNetworkRoot
					   
			  --First, we load the script file with the function definitions
			  local remoteScript = theNetworkRoot + "\\submission\\3dsmax\\SubmitMaxToDeadline_Functions.ms"  --this is the file name on the Repository
			  local localScript = getDir #userscripts + "\\SubmitMaxToDeadline_Functions.ms" --to speed things up, we will copy it locally first, then we will load it
			  if doesFileExist remoteScript then --if the remote file exists,
			  (
				deleteFile localScript --we delete the local file in case it exists already
				copyFile remoteScript localScript --then we copy the remote file over
				fileIn localScript quiet:true --and execute it (equivalent to Main Menu > MAXScript > Run Script...)
				 
				--At this point, SMTDFunctions should have been initialized to the latest version found on the Repository.
				--Now we have to make sure all defaults (both global and local) are loaded, otherwise the SMTDSettings struct would contain factory defaults
				SMTDFunctions.loadSettings()
											   
				--local TempMaxFile = maxfilepath + maxfilename
				f = maxfilepath + maxfilename
				  
				SMTDSettings.JobName = getFileNameFile f + ":" + thepassname + " [HydraGen Submission]" --we could for example set the job name to the name of the max file and any custom text we want
				SMTDSettings.Comment = "Submitted from HydraGen" --we could set the comment field
				SMTDSettings.Priority = 50 --we can override the priority, for example we could increment the priority based on the order of the files or something else
				--SMTDSettings.Group = tghgroup
				SMTDSettings.ChunkSize = 1
				SMTDSettings.restartrenderer = true
				SMTDSettings.ignoreMissingDLLs = true
				SMTDSettings.machinelimit = 0
				SMTDSettings.SubmitSceneMode = #reposave --changed to +Mode in Deadline 5.1
				
				
				--setIniSetting SMTDPaths.InIFile "Scripts"  "RunPreLoadScript" "true"
				--SMTD_MainRollout.Ui_report ("+Run Scripts: Run Pre-Load Script ENABLED automatically.")
				--setIniSetting SMTDPaths.InIFile "Scripts"  "PreLoadScriptFile" theFile
				
				--SMTDSettings.PostLoadScriptFile = thefile
				--SMTDSettings.RunPostLoadScript = true
				--SMTDSettings.PreFrameScriptFile = thefile
				--SMTDSettings.RunPreFrameScript = true
				
				
				--##todo 
				--n.usenodesettings
				SMTDSettings.regionrendering = false
				
				--if n.usenodesettings == true then
				(
					--##todo get from node somehow?
					SMTDSettings.regiontop = 0
					SMTDSettings.regionleft = 0
					SMTDSettings.regionbottom = 100
					SMTDSettings.regionright = 100
					
				)
				
				
				
				(
					--Note that the simple act of loading SMTDFunctions has also initialized a SMTDPaths struct with default paths - type 'show SMTDPaths' to see what paths are available
					local SubmitInfoFilename = SMTDPaths.tempdir + "\\max_submit_info.job"  --we define the submit info file name which will contain info about the submission settings
					local JobInfoFilename = SMTDPaths.tempdir  + "\\max_job_info.job" --and the job info file which will contain info about the job's settings (most of them can be changed in the job's Properties dialog of the Monitor
		
					SMTDFunctions.CreateSubmitInfoFile SubmitInfoFilename --we then call the function to create a submit info file based on the current SMTDSettings values
					
					--We also call the function to create a job info file. It will contain all info about the current scene like renderer settings, list of cameras etc.
					--This function accepts optional overrides for the render output filename, the tiles to render and the camera to render. 
					--We can specify these if we know them: renderOutputOverride:"" tileString:"" forceCamera:"" 
					SMTDFunctions.CreateJobInfoFile JobInfoFilename forceCamera:RenderCam --renderOutputOverride: could be set to a string that points at the network location to write the images from the scene being submitted instead of using the renderer's output settings!
						
					--Now that we have all the files we need for a submission (the scene file, the submit info and the job info file), we can call the submitter!
					--To do this, we will have to create an argument list to pass to DeadlineCommandBG
					--local initialArgs = "\"" + SubmitInfoFilename + "\" \"" + JobInfoFilename  + "\" \"" + f + "\" " 
					local initialArgs = "\"" + SubmitInfoFilename + "\" \"" + JobInfoFilename  + "\" \"" + thetempfile + "\" " 
					print "initialARgs"
					print initialArgs
					
					--We call the DeadlineCommandBG with our arguments and the timeout (which you can customize)
					local retcode = SMTDFunctions.waitForCommandToComplete initialArgs SMTDSettings.TimeoutSubmission
					
					--Once the command returns, we can try to get the message from the message file. Even if it failed, the file could contain userul error info...
					local renderMsg = SMTDFunctions.getRenderMessage() 
					SMTDFunctions.getJobIDFromMessage renderMsg --we can also extract the job ID from the render message - it will be stored in SMTDSettings.DeadlineSubmissionLastJobID
					
					if retCode == #success then --if the return code from the call was #success, we show a positive message
					(
						format "File % submitted successfully as Job %.\n\n%\n\n" (filenameFromPath f) SMTDSettings.DeadlineSubmissionLastJobID renderMsg
						SMTDFunctions.CopyExternalFilesToRepository() --copy files to main job
					)	
					else --if the code was anything else, we print the message as error message
						format "Remaining Frames Job Submission FAILED.\n\n%" renderMsg 
				)			
				
				 
		   )--end if root resolved
		   --deletefile thetempfile
		)--end script
		fetchmaxfile quiet:true
		


	)
	setArrowCursor()[/code]

The Render Elements aren’t listed in the deadline monitor, so something is going wrong in the submission process I guess?

Normally, when a new Render Element is added to Max, it updates its path according to the rendOutputFilename value.
It is possible that when running the script in a loop, this does not happen and you end up with render elements that have invalid (or at least “”) output file names.

I would suggest trying to debug print the file name of the render element before submission to see what it is set to.
You can also call
SMTDFunctions.RenderElementsUpdatePaths()
which is what SMTD does by default (but this will create sub-directories for the elements right now, something you might not want to do). But at least you can take a look at that function and implement your own that refreshes the paths.

There could be something else, but I would start debugging there if I were you…

Can someone else try the code for me and see if it causes the same issue?

So yeah it’s something to do with the inbuilt process of giving the renderelements their paths automatically, if you don’t have the RenderSceneDialog open then it won’t update automatically in the loop, and you even have to commit the RendOutputFilename change before you can get the auto-adding to work, or alternatively set it yourself manually seems to fix it.

re.setRenderElementFilename 0 (getfilenamepath rendOutputFilename + getfilenamefile RendOutputFilename + "_" + theelement.elementname + getFilenameType RendOutputFilename)

cheers bobo