Actor Framework Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Best way to get a reference to Actor Core.vi?

I got an answer on this from someone at NI the other day, but I'm only now trying to do it and want to make sure I recall correctly.

I have some AF actors that are subpanels in a user interface. I need to pass each one a reference to the main panel that loads them; how should I create that reference? I was using the "This VI" constant, but apparently that's a volatile reference, and it was causing the application to crash with random "Not a Refnum" errors. So should I drop an unwired Property Node of type VI and use the reference that comes out from it? Or should I drop a Static VI Refnum of the main Actor Core.vi and pass that into the subpanel actors? Which is best for a shared reentrant VI like Actor Core.vi? And do I need to close the reference from a Static VI Refnum constant when my main VI exits?

Edit: Added code to accompany a reply below.

0 Kudos
Message 1 of 21
(12,101 Views)

You didn't mention the crash to me, just the errors. If you're crashing LV, that's a R&D bug. Can you share your code?

0 Kudos
Message 2 of 21
(6,180 Views)

Blech, wrong word choice. It just errors out.

So do I use a Static VI Ref or a Property Node's output ref? And do I have to close a Static VI Ref manually?

0 Kudos
Message 3 of 21
(6,181 Views)

The static VI reference won't be for the same Actor Core.vi... you need a reference to the specific Clone VI as opposed to any other clone or to the real VI. The only options are the property node or the This VI ref.

Having said that -- both of those are problems if you expect the reference to refer to the same VI... Actor Core is reentrant, share clones, and if a clone goes back to the pool, you will have errors if you try to use it while it is in the pool.

0 Kudos
Message 4 of 21
(6,181 Views)

David_Staab wrote:

Blech, wrong word choice. It just errors out.

Phew. 🙂

0 Kudos
Message 5 of 21
(6,181 Views)

Honestly, I don't fully understand the "clone pool" stuff. Maybe you can give me a direct answer to my specific problem if I provide context: I have an Actor Core.vi with a subpanel that launches 6 other actors and, on a button press, instructs them to insert their Actor Core.vis into the subpanel in turn. When any subpanel is inserted, it needs align and size itself, so a reference to the subpanel Actor Core.vi is stored in the class data and used by Insert Panel Msg:Do.vi. How do I get that reference and make sure it stays valid when panel isn't visibile (because another panel is currently inserted, or because no panel has been inserted yet)?

0 Kudos
Message 6 of 21
(6,181 Views)

I did something similar and it worked but i'm not sure its a "best practice" and not 100% sure if i'm following what you are trying to do.  However, when your launcher spins up the 6 actors, couldn't you use the CloneName property within those spawned actors, to get a string defining the clone.  You could then message these string back to your launcher, obtain a reference in your launcher to the clone using this string and work on that reference, within your launcher, to resize based on your subpanel.

VICLone name.png

I may be way off on what your trying to do but i'm also curious on best practices here. 

0 Kudos
Message 7 of 21
(6,181 Views)

Let's ditch the resizing stuff and just go with the "Insert Panel" method. That method takes a ref to the subpanel VI as an argument. When an AF message called "Insert Panel Msg" is sent from the main UI actor to one of my UI subpanel actors, the message contains a reference to the subpanel, and the actor is responsible for calling that method on the subpanel ref with the actor's panel VI (Actor Core.vi) as the argument. I learned to do it this way from some discussion on LAVA years ago.

So each subpanel actor needs a way to get a reference to its actor core.vi instance. Some of these actor classes have multiple objects in memory at once; some only have one object during the entire run length of the application. Those that have multiple objects can also have their Actor Core VIs displayed simultaneously by inserting them into side-by-side subpanels on the main UI panel. And the subpanel actors are stateful and constantly updating the subpanel VI, so they need to stay associated with a specific actor, even when not loaded.

AQ, niACS, etc: How do I accomplish this safely and consistently? If my specific example is too arcane or too complex to explain without providing code, then let's take it back to the general case of two side-by-side subpanels that each load and unload the Actor Core.vi of an AF object asynchronously using an AF msg sent to the "owning" actor objects.

0 Kudos
Message 8 of 21
(6,181 Views)

Hmm...I wonder if I can circumvent this whole problem by creating a new, fully reentrant ("preallocate clones") VI to insert into the subpanel instead of Actor Core.vi. I should then be able to safely store a reference to a clone in each actor's private data, right? Actor Core.vi would then be boiled down to init/cleanup logic and launching the subpanel VI alongside the parent dispatch.

Update: I wrote a trivial example to test the idea of getting unique fully reentrant clones from shared clones running in parallel, and it looks like it works. (Code attached to original post.) Of course, because of clumping I can't be guaranteed that the shared reentrant VIs are really running in parallel, and I have no idea what caveats are lurking in dark corners of the compiler's mind. Can anyone verify that this approach is valid?

Update-er: Added a UID to the shared reentrant VI so I could know whether it was being shared or not....it's not. LV is creating a unique clone for every instance of the shared VI, probably because it can't exit (and return to the clone pool) until the reentrant subVI catches its event. Maybe I can use this to my advantage? Create a fully reentrant "brat" VI that stays running on the block diagram of Actor Core.vi until it's sent an occurrence that allows it to exit?

0 Kudos
Message 9 of 21
(6,181 Views)

I may not be understanding the use case, but it seems to me that it doesn't matter if "Actor Core" is shared clones, since it runs for the lifetime of the Actor, and only goes back into the pool after the Actor is stopped.  There should be no problem using "This VI" to get a reference to the various "Actor Core"s and use it elsewhere in the Actor.

0 Kudos
Message 10 of 21
(6,181 Views)