Jump to content

AsyncQueue for nodes


photo

Recommended Posts

Hello, 

I am using AsynQueue to load nodes (loadNode(fileName)), and I have some questions:

- For the CALLBACK_NODE_LOADED callbacks, the help tells me:

Quote

Do not call take-methods inside a callback function unless you are absolutely sure, that the resource is yours, otherwise internal engine managers will be forced to load it again and again every time. In such cases it is recommended to use get-methods.

I am not really sure what "unless you are absolutely sure that the resource is yours"? If I am using getNode in the callback, the resource seems to remain there and the engine asserts at exit. If I use takeNode everything is fine, but want to make sure I am using it right. I do take the node, only that part of the code supposed to manage it and I put it in my own NodePtr and keep it around. I have other locks in place, so if any other code need that node, I return the same NodePtr that I already take from queue.

- What about the case when I receive the callback and my system discovered that the node is no longer to be used? Can I just call AsyncQueue::takeNode and don't keep any reference to it and it will just be removed from the queue?

 

Another question:

- By default I believe Unigine nodes are enabled (visible). But the help tells me: 

Quote

In order to display such asynchronously loaded node, the updateEnabled() method should be called for it from the main thread.

So, what I understand is: the internal state of the node tells it it is enabled, but the background thread (loading it) cannot actually enable it (it is not thread safe to insert it in the visibility trees). So you need to call updateEnabled just to make that non-thread-safe part in the main thread? 

And if I want the node to NOT be visible by default? Should I just call setEnable(false) on the main thread after I take it out of queue?

 

Regards,
Adrian

Edited by adrian.licuriceanu
Link to comment

Hello Adrian,

Quote

I am not really sure what "unless you are absolutely sure that the resource is yours"?

loadNode method returns you id. If you use this id to take the node than resource is yours. That warning just warns you against taking some unknown nodes which can be scheduled to load by the engine.

Quote

Can I just call AsyncQueue::takeNode and don't keep any reference to it and it will just be removed from the queue?

In case of nodes you should delete them explicitly as they are not deleted by refcounting

Quote

And if I want the node to NOT be visible by default? Should I just call setEnable(false) on the main thread after I take it out of queue?

Yes, you can call setEnable(false) on the main thread and setEnable(true) when you need them. 

  • Like 1
Link to comment
×
×
  • Create New...