PDA

View Full Version : Preventing multiple instances of scene masters



Adrian Lopez
03-12-2007, 11:48 AM
I'm writing a scene-master plugin and would like it to work correctly when "load objects from scene" is used. Unfortunately, invoking this option on a scene that uses the plugin when the plugin is already loaded causes a second instance of the plugin to appear. What I want is to be able to load the plugin's data from the scene being read without ending up with multiple instances of the plugin.

I know MotionMixer somehow manages to keep a single instance running when "load objects from scene" is invoked, but I don't know how.

Sensei
03-12-2007, 03:39 PM
Nasty way: have global bool (or counter) variable and set it to true/increase in Master's Create() and false/decrease in Destroy().. In Create() check if it's not false/above 0 and if so set *errorPtr to message that second copy of master is not allowed or similar..

Neat way: use LWItemInfo->server() with class set to LWMASTER_HCLASS and search for existing copy of your Master plug-in.. The rest same as above..

Both ways works, I am using second in TrueHair..

Adrian Lopez
03-12-2007, 06:07 PM
Hello Sensei and thank you for your help,

The second way is definitely the best way to detect that another instance is already running, but I don't want to indicate an error to the user when Lightwave tries to create another instance of my plugin. What I really want is for the plugin to read the data from the imported scene without a second instance of the plugin remaining in memory after loading is done.

I think I've figured out a way to do it, but I haven't tested it:


Load first instance into global memory using LWGlobalPool.
When Lightwave creates a second instance of the plugin while loading objects from another scene, pass the new data to the original instance instead of the second instance.
Have the second instance remove itself using Layout's RemoveServer command.


I hope Lightwave won't crash when I try to have the handler remove its own instance from memory. I can't think of another way to do it.

Sensei
03-12-2007, 06:34 PM
I tried Items > Load > From Scene and it did not load any volumetrics, nor master handlers.. Even if I check-marked them they didn't want to load, which sounds like bug.. How do you do that it loads them?

If you want to have master that survives after loading scene, but does not load/save with scene file, consider using LWMAST_LAYOUT type plug-in..

"LAYOUT masters are like SCENE masters, but they survive scene clearing and can therefore be used to automate scene management."

Adrian Lopez
03-12-2007, 06:54 PM
I'm still using Lightwave 7.5 so it's possible that newer versions work differently, but in 7.5 master plugins load OK when I do File -> Load -> "Load Items From Scene...". I haven't tried it with volumentric plugins, but it probably works too.

My plugin needs to be able to load and save data to the scene, so I don't really have an option about the type of plugin. I think the method I described will work, except that the second instance must remove the first one instead of removing itself. I tried to have the second instance remove itself and it caused Lightwave to crash, but it doesn't happen when I have the second remove the first.

I wonder why the plugins aren't loading on your computer. What version of Lightwave do you have?

Adrian Lopez
03-12-2007, 07:36 PM
I think the method I described will work, except that the second instance must remove the first one instead of removing itself. I tried to have the second instance remove itself and it caused Lightwave to crash, but it doesn't happen when I have the second remove the first.I was wrong about this. I don't know what's causing it to crash, but it's not due to removing the second instance.

Back to the drawing board...