AsyncLoading vs. Cache

Return to C++ coding using Panda3D

AsyncLoading vs. Cache

Postby heek_ » Thu Jun 21, 2012 2:17 pm

I basicaly want to load my models asyncronously.
If I load the model the first time, I can get the loading working like a charm with the code below. But from the second time (when the model is already cached), it hangs the do_frame.

I want it to be cached AND async loaded.

I guess there's some weird lock when using bamcache that there's not when using the egg. Ok, the cache loads much faster, but it hangs the screen for the secs (it hangs the movie in my case).

It's a bug? Am I doing something wrong?


Code: Select all
   NodePath box = window->load_model(render, "box");
   PT(Loader) loader = new Loader("My Async Loader");
   LoaderOptions options;
   PT(ModelLoadRequest) request = new ModelLoadRequest("MyPandaModel", "ModelWithHeavyTexture.egg", options, loader);
   loader->load_async(request);

   /* Until here is all instantly */
   bool loaded = false;
   NodePath my_model;
   while(!loaded){
      nout << "Before do_frame" << endl;
      /* Placeholder loader screen */
      box.set_x(box, 2 * ClockObject::get_global_clock()->get_dt());

      /* Here it hangs when reading from cache */
      framework.do_frame(current_thread);
      nout << "After do frame" << endl;

      if(request->is_ready()){
         my_model = NodePath(request->get_model());
         my_model.reparent_to(render);
         loaded = true;
      }
   }

   framework.main_loop();


http://pastebin.com/zJRvwHjp
heek_
 
Posts: 83
Joined: Sat May 03, 2008 7:21 pm
Location: Brazil

It's a Panda3D bug?

Postby heek_ » Fri Jun 29, 2012 12:56 pm

I think it can be a bug in Panda3d. I'm not completely sure, but I'll try to describe what I think and then you guys can tell what's wrong and what's right.

Two threads (at least) is running:
1. BamCache is loading a heavy model, and his ReMutexHolder "_lock" is being held for the multithreaded approach.
2. The main thread is trying to render the frame. When it comes in GraphicsEngine::render_frame(), the thread try to execute the line 641:
Code: Select all
BamCache *cache = BamCache::get_global_ptr();
cache->consider_flush_index();

BamCache::consider_flush_index() uses the ReMutexHolder "_lock" as well, making it wait 'till the model loading is complete to only then release the lock.

So that's what I think it's happening :).
Someone can check that for me, please? ;)

Edit: http://www.panda3d.org/forums/viewtopic.php?t=12710 seems to be the exactly same problem.
heek_
 
Posts: 83
Joined: Sat May 03, 2008 7:21 pm
Location: Brazil


Return to C++ coding using Panda3D

Who is online

Users browsing this forum: No registered users and 0 guests