AsyncLoading vs. Cache

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?

	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

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:
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 :slight_smile:.
Someone can check that for me, please? :wink:

Edit: [Lag with asynchronous model loading) seems to be the exactly same problem.

For anyone coming upon this thread via a search, this issue has been fixed, and the fix will be available in the upcoming 1.9.3 release of Panda.

bugs.launchpad.net/panda3d/+bug/1019599