Author
Topic: Exiting WM & Device IDs (Read 2457 times)

2 questions:1) How can I tell when my devices are being destroyed due to the app closing down? Is there something I can check on the core interface? I'm registering/unregistering devices as part of the communication between my application and World machine, and I need to know when a device is actually being deleted from a world machine graph vs. being destroyed because the application is closing.

2) I've noticed that when loading a device, the device id in the constructor will differ from the device id after loading - specifically it seems the id gets loaded by my super class' load function. This is somewhat annoying because I am doing the register/unregister of my devices in the constructor/destructor of my device - could I solve this by moving the register to my activate function? Is Activate guaranteed to be called whenever a new device is created, and upon load of an existing device?

These are assigned on construction and then again on load as you noticed; the reason they are assigned on load as well is because files can be merged into the current world as well as simply loaded, and in the merging case unique IDs need to be given to each incoming device to prevent ID collisions.

Activate is called when a device is initially placed into the world, and then every time the world changes or a dependency changes. Setting a flag and registering on first activate sounds like the best place to do your registration.

There is unfortunately no notice currently available about a world being closed -- your only notice will be the tear-down of the devices. Also, there is also no flag available to check for current rebuilding -- again since WM's processing model is synchronous.

I can definitely see that a notification/threadsafe interaction interface would be very useful for your use case and probably for others too when doing integrations. It's something I'll consider for the next update!

FYI: Activate is not always called when devices are first placed into the world - I noticed this when placing the device I created inside a macro that someone had created for WM. Is this a bug, and will it be fixed soon?

Sorry -- this is correct, but its not exactly a bug -- I'm assuming that the macro was not yet connected, yes?

A macro only activates its internal devices when all required ports (those not flagged optional) are connected. So you won't get an activate until the macro has been connected to something else if it has required inputs.

The problem here isn't in activate, but just that we're sort of overloading it into a notifyAdded() call. Properly of course we would just add those notify methods directly to the device class.

Drop me an email at [email protected] with your notification wishlist, and I'll see if its possible for me to get you an advance out-of-band core+pdk version that has this interface added.

The macro is connected to a graph at the top level - when I add my device in, it's that parameter device, so it only has parameter outputs. The macro in particular was a cracks and dots macro from this tutorial: http://www.world-machine.com/tutorials/craters/craters.html - in fact its parameter node is a similar idea to what I'm trying to do - where did that node come from?

Anyways, I have yet another question (sorry for consistently peppering you with them) - how can I tell if a parameter port is already connected to something else? Looking at the port, its target is null. I'm dynamically sizing my device as I connect to parameter ports, but I have a bug right now where if I try to connect my empty port to a parameter port an existing port on my device is already connected to, I end up just overriding that link, and end up with an empty port where I don't want one - I only get a MakeLink notification on the output port doing the new connection, and no break link notification on the port whose link is getting overridden.

A note for others who may stumble upon this: I was able to figure out whether or not the device destruction was caused by shutdown vs. deleting the device by checking GetWorld() of the device - if it's null, then the device is being destroyed as part of shutdown (from what I could tell).