-
Hello, first of all thank you for developing this framework. I'm really happy with my solution for video mapping and live shader coding and it has been used several times at events now for up to ten hours without a single crash on low budget hardware. Started out as a hobby for music events but now I already have two commissions lined up for this summer! Before these events take place I wanted to restructure how I'm handling video rendering as well as implementing video transitions. (star wipes!) I already wrote some code for spawning an entity and adding components to it inside my modules service which works as expected but when a reload is triggered by a file change, a new scene is created which does make sense I guess, but I am having trouble understanding how and when the old scene is deleted and its resources released, or how to properly access the new one. Either way I seem to be doing something wrong, since when changing for instance a fragment shader or adding a VideoPlayer the scene isn't populated with my dynamically created entities but it is when starting the program for the first time. This is my code for creating an entity:
And here's how I get the last scene in the SceneSet from SceneService::getScenes() and how I spawn the entity:
Here's the repository if you want to build and test it yourself, there's some log outputs set up. The code is inside the modules foglioservice.cpp, some of it is really ugly, kindly ignore those parts. https://github.com/jkukatzki/foglio Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments 3 replies
-
Hi @jkukatzki , thanks for the kind words and great to hear you're getting gigs using NAP. Have you considered spawning the entity from a scene that you dynamically create (and retain) outside of the resource manager ? So instead of letting the scene loaded from the resource manager spawn the entity, create your own scene (for example in your FoglioService) and spawn all your dynamic entities in that scene, keeping stuff that can get destroyed or initialized by the ResourceManager seperate from objects that you spawned // created with code. You can take a look at the RenderAdvancedService that does something along those lines, creating a LightScene thats used to spawn dynamic instances of entities.
|
Beta Was this translation helpful? Give feedback.
-
Hey, I managed to compile your project on Linux. Something I needed to change was a lot of initialization functions where missing return statements, on windows this defaults to true, and GNU default to false. Anyhow, it seems you're struggling a little bit with stuff that is initialized by the resource manager and stuff that you instantiate dynamically. I don't have time to go over all your code, but lets take First you create a videoRenderEntity using the resource manager. using
This will mean this object gets managed by the resource manager. If you want to work outside the resource manager, instantiate it yourself using
The same goes for the components
to
you get the gist... You can then move the created objects using std::move to member variables of the service and they will be retained as long as the unique ptr is on the stack. Also, later you do the following:
The spawnedentityinstance you don't need to wrap it in a unique_ptr, it is retained/managed by the scene so you can change this line into:
and change the type in the header accordingly. I'm not going over all your code, but it seems like a lot of problems arise due to mixing stuff that you spawned dynamically with objects that are managed by the resourcemanager. |
Beta Was this translation helpful? Give feedback.
-
In addition to what @TimGroeneboom already covered in his answers, I would strongly recommend following the dynamic pattern used in the Example from
Make sure to destroy the entity when the resource manager destroys your resource:
When you are iterating over your scenes or using Another thing to be aware of is that the resource manager only destroys objects on shutdown, never before. If you delete an object in Napkin it isn't destroyed. This is something we are aware of but have no solution for atm because it interferes with the way we handle null (invalid) ptrs, ie: do we accept objects to be removed if they're referenced? But that's not of interest here. Try to find a pattern whare you declare a resource in Napkin that spawns the required dynamic resources and components using the pattern above and try to avoid using I will try and write a FAQ that answers some of these more common questions regarding programming patterns in NAP. But the demos are your friend here. If you run into problems try to reproduce them in a simpler project and when it's a bug report it with a repro case. Regarding video mixing: you should only have X amount of players for the amount of videos that you want to mix. You should use 1 |
Beta Was this translation helpful? Give feedback.
-
Hello, thank you for such thorough answers. Very useful to know about the compile errors, I've been putting off trying to compile on linux for a while but will try building on debian and implementing those fixes once I can make some time for it, maybe I'll even go through the article you have on building for raspberry pis while I'm at it.
Glad to know I'm not going insane at least. I really want to avoid having to author every RenderVideoComponent myself though, I'd rather have an overview of every VideoPlayer with a preview automatically. And then, like with images, set the texture of any sampler declarations that start with "v_" inside the passes that my RenderCanvasComponents own, which basically just take the texture of the last pass and put an effect on it described by a fragment shader (like the alpha mask pass cutting out the fractal shader in the video I posted, by using an image with an alpha channel). Sorry for asking so many questions. Also my understanding was, since the entities can be unique every file load, that I might as well only define entity and component resources inside the scope of the postResourcesLoaded call, so I dismissed putting any resource initialization in the init function. The sampler texture not being set sometimes is probably a different issue, hope I can resolve that one. Also I just noticed I described my approach for video blending wrong. |
Beta Was this translation helpful? Give feedback.
-
Are you saying this isn't possible with hot reloading because they are only destroyed on shutdown? No, that's why you need to use unique pointers if you dynamically want to spawn entities at runtime. Just make sure to delete them on destroy of your resource. If you look at the example above we don't author every camera ourself, the system does that on initialization of a light. You can do something similar, where a resource defines how many objects to dynamically spawn. It is also fine to link to resources in dynamically created objects, If the resource you link to is changed in Napkin the object that links to it will be re-initialized - thus creating new instances and destroying old ones. (local - not global!). Note that items that change (in Napkin) are destroyed, ensuring the init pattern works as expected. Only when you delete an object that is linked Napkin doesn't destroy it immediately because it could leave the app in an undefined state (dangling references). From what I gather this is not a system issue but more of a general architectural issue: You don't seem to have a good grasp on what it is you actually need and thus have to create. I recommend going back to the drawing board and figuring out what resources are required (x amount of players, thus x amount of render video components etc.) and design the system from there. Also my understanding was, since the entities can be unique every file load, that I might as well only define entity and component resources inside the scope of the postResourcesLoaded call, so I dismissed putting any resource initialization in the init function. Don't do this, I explained why above. I think I'd just create something like a "HandleFoglioResourcesComponent" This is a better approach, let resources handle spawning of dynamic objects, not any global object including services. For blending a video with the one that is next up in the VideoPlayers video files list I'd have to create a copy of the VideoPlayer and start playback of the video that is up next on the copied VideoPlayer once the last one nears it's end and then blend between those two textures, and then do the same the other way around once the new video nears it's end. Just wanted to be clear there. A video player plays back a video and stores the result in 3 textures that you render to 1 RGB texture using a render video component. Your system should have only 2 video players if you want to blend between 2 videos, which you can define in Napkin. Other than that I can't help you here. I'm going to close this discussion, feel free to open a new one but try to be more specific. Your questions are currently a bit out of scope and hard to answer. Try to break down your problems in smaller projects and take it from there. Similar to previous discussions we had on the old message board. |
Beta Was this translation helpful? Give feedback.
-
I think we're talking past each other sadly, my problem was that
there's not any ground truth of objects that reside in the json file, like
VideoPlayers, that I can get from the ResourceManager, which was what I
expected when I call getObjects in the postResourcesLoaded call. I don't
even need dynamically created VideoPlayers at this point.
I'm quite confident in my design, even more so because it works perfectly,
I just wanted hot reloading to work as well.
Anyways, thanks for your help.
…On Wed, 19 Jun 2024 at 10:17, Coen Klosters ***@***.***> wrote:
Closed #27 <#27> as
resolved.
—
Reply to this email directly, view it on GitHub
<#27>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ASMHJBX5H6TQT4VTJQUCS6DZIE5BNAVCNFSM6AAAAABJC2RFXCVHI2DSMVQWIX3LMV45UABFIRUXGY3VONZWS33OIV3GK3TUHI5E433UNFTGSY3BORUW63R3GEZTINRRHA3Q>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Don't use |
Beta Was this translation helpful? Give feedback.
-
If you could just answer one more thing I'm curious about then I'll be off
your back:
In the RenderBloomComponent in the flocking demo a render target and
texture is created using the createObject function, if this happens on
every init wouldn't these add up after some time?
Thanks.
|
Beta Was this translation helpful? Give feedback.
Don't use
getObjects
in thepostResourcesLoaded
call, explicitly create and link to objects on init, that's all. If you do that and follow general init() guidelines hot reloading should work as expexted. Globbing is always a bad idea and should be avoided, as explained. I am going to remove thegetObjects
call in a future version of NAP because of this.