[Closed] Render plugin – Unresponsive while rendering mat preview
I finished pushing all of my rendering code to its own thread so I can quickly return from Renderer::Render() while still holding on to the tobm pointer.
This seems to still work, but still causes the UI to hitch up.
Before the flow for rendering a material was:
Renderer::Open() – Does very little, returns quickly
Renderer::Render() – Render happens here, this function waits until the render is complete to return
Renderer::Close() – Frees some resources, returns quickly
Now it is:
Renderer::Open() – Does very little, returns quickly
Renderer::Render() – Translates the scene, then kicks off the rendering process in a separate thread. Returns quickly.
Renderer::Close() – Waits until render thread has completed, then frees resources and returns
As Max will just call Open, Render, Close for every preview render, the UI now just blocks inside Renderer::Close() instead of Renderer::Render(). The documentation specifically says that the renderer should retain no state about the scene after Close() returns, so i definitely have to wait until the render completes before returning.
As long as you run the render as a different thread, can’t you set its priority less than 3dsMax’s? Or run it as a background task?
The foreground application would take the most cycles so make sure you don’t force the render in foreground mode.
The problem here isn’t about the amount of resources the render is taking up. It is that it appears the Max UI thread is responsible for calling renderer functions for material previews, so the ui cannot update while those functions are running.
I would assume that any renderer which overrides this limitation is also calling Close() immediately, after making its own copy of the scene, for use in a new render.
Kind of like:
- 3dsmax calls Open().
- You grab a pointer to the target Bitmap.
- You make a copy of the scene (which is usually just a sphere, box or cylinder and 1 or 2 lights).
- You spin off your renderer in its own thread.
- You return from Open().
- When 3dsmax calls Render() and Close(), you immediately return, maybe setting the bitmap to some “rendering…” message.
- When you render finishes, you update the Bitmap you stored a pointer to.
This is all theoretical, I have no idea if this will work.
Just tried that as well to make sure.
I’m not sure where exactly, but max crashed like that. I believe it was from accessing the bitmap but I’ll have to dig a little deeper to double-check that. There is a chance I am accidentally holding on to some other pointer as well.
Anyways, I’ll probably keep poking at it every once in a while and I’ll update this thread if I find anything.