Render to texture making 3dsmax crash

Hi!

I’m writing a script to render lightmaps to texture and I’m running into crashes. I did my best to put together a simple crashing scenario. I have a script that will render 10 lightmaps for a selected object and save them to exr files.
After the script is finished running a 3ds max error will pop up closing down the application. I have noticed that all maxscript code gets executed properly. So even when crashing all textures will be saved correctly and the last print will have executed. I have not been able to make the code stable. Even though some variations will not run into the crash I found that adding more unrelated functionality to working variations will lead to a crash.

I’m using 3ds Max 2017 and VRay Adv 3.40.02.


macroScript LightMapsTest
category:"MyLightmapper"
buttonText:"Light Maps Test"
toolTip:"Light Maps Test"
(
	rollout LightMaps "LightMaps" width:512 height:216
	(
		button btn_bake_generate "Bake Lightmaps"

		on btn_bake_generate pressed do
		(
			print "*************** GENERATING LIGHTMAPS ********************"

			-- Check if the renderer is set to Vray
			current_renderer = Renderers.current as string
			found = findstring current_renderer "V_Ray_Adv"
			if found == undefined then ( return undefined )

			-- Set variables
			obj = selection[1];
			size = 16
			output_dir = "C:/Renders/";

			-- Check if the object selected is defined and if it is a a geometry
			if obj == undefined then( return undefined )
			found = false
			for obj2 in geometry do ( found = (found or ( obj2 == obj )) )
			if found == false then
			(
				print "Object sent to render is not a geometry"
				return undefined
			)

			object_name = selection[1].name;

			for i = 1 to 10 do
			(
				-- Create the bitmap in which the image will be saved
				file = output_dir + object_name + i as string + ".exr"
				deleteFile file
				tempBitmap = bitmap size size filename:file 
				save tempBitmap

				-- Define the bakemap
				bakeMap = vraylightingmap();
				bakeMap.enabled = true
				bakeMap.filterOn = true
				bakeMap.atmosphereOn = true
				bakeMap.shadowOn = true
				bakeMap.bitmap = tempBitmap
				bakeMap.vrayVFB = false
				bakeMap.color_mapping = false
				bakeMap.multiplier = 1.0f

				-- add the bakemap to the obj
				obj.iNodeBakeProperties.removeAllBakeElements() 
				obj.INodeBakeProperties.addBakeElement bakeMap 
				obj.INodeBakeProperties.bakeEnabled = on
				obj.INodeBakeProperties.flags = 1
				obj.INodeBakeProperties.bakeChannel = 2
				obj.INodeBakeProperties.nDilations = 1

				-- render to texture
				render rendertype:#bakeSelected vfb:off progressBar:true outputSize:[size,size] to:tempBitmap

				-- set OpenEXR settings
				fopenexr.SetCompression 0
				fopenexr.setSaveScanline true
				fopenexr.setLayerOutputType 0 0
				fopenexr.setLayerOutputFormat 0 0
				fopenexr.delAllAttributes

				--Save the texture
				save tempBitmap
				close tempBitmap
			)

			print "********** END OF GENERATING LIGHTMAPS *****************"
		)

	)
	createdialog LightMaps
)


crash_scene.zip (49.5 KB)

It’s reproducible here, one of our developers will look into it.

Thank you!

Do you guys know of any possible workarounds to avoid the crash? It would be nice to get working soon.

Hi, I couldn’t find workaround by the MaxScript code. Will look into it and write as soon as there is some info.

Best regards,
Alexander

Hi alexander,

Any updates regarding the progress of the fix? I was also wondering if the bug would be present in the C++ SDK?

Thanks,
Carlos.

Hi Carlos,

looks like we have an issue with the VFB. Funnily as workaround you can have an VFB opened before the script starts and this should be preventing the crashes. I’ve tried to add “macros.run “VRay” “vrayShowVFB”” in the beginning of the script and it seems to work around the problem. We still have to fix it, but I hope this will help you finish the bakings.

Best regards,
Alexander

Thanks, I’ll give that a try.

Hi Alexander,

Any updates on the fix? I added the “macros.run “VRay” “vrayShowVFB”” to my plugin and it did reduce the crashes but depending on the scene it might or might not crash. We are at a point where the plugin is completed and we are looking to deploy it to the art team so they can start using it but we would really appreciate if this was fix as it will slow them down.

All the best,

Carlos