diff --git a/panda/src/pgraph/loader.cxx b/panda/src/pgraph/loader.cxx index 15b130592d..a051aeaf35 100644 --- a/panda/src/pgraph/loader.cxx +++ b/panda/src/pgraph/loader.cxx @@ -392,13 +392,17 @@ try_load_file(const Filename &pathname, const LoaderOptions &options, sgr.premunge(result, RenderState::make_empty()); } - if (allow_ram_cache && result->is_of_type(ModelRoot::get_class_type())) { - // Store the loaded model in the RAM cache, and make sure we return a - // copy so that this node can be modified independently from the RAM - // cached version. - ModelPool::add_model(pathname, DCAST(ModelRoot, result.p())); - if ((options.get_flags() & LoaderOptions::LF_allow_instance) == 0) { - result = NodePath(result).copy_to(NodePath()).node(); + if (result->is_of_type(ModelRoot::get_class_type())) { + ((ModelRoot *)result.p())->set_fullpath(pathname); + + if (allow_ram_cache) { + // Store the loaded model in the RAM cache, and make sure we return a + // copy so that this node can be modified independently from the RAM + // cached version. + ModelPool::add_model(pathname, DCAST(ModelRoot, result.p())); + if ((options.get_flags() & LoaderOptions::LF_allow_instance) == 0) { + result = NodePath(result).copy_to(NodePath()).node(); + } } } diff --git a/panda/src/pgraph/modelPool.cxx b/panda/src/pgraph/modelPool.cxx index c53e2b867f..4985cd2b65 100644 --- a/panda/src/pgraph/modelPool.cxx +++ b/panda/src/pgraph/modelPool.cxx @@ -118,52 +118,29 @@ ns_get_model(const Filename &filename, bool verify) { */ ModelRoot *ModelPool:: ns_load_model(const Filename &filename, const LoaderOptions &options) { - - // First check if it has already been loaded and is still current. + // First check if it's been cached under the given filename (for backward + // compatibility reasons) PT(ModelRoot) cached_model = ns_get_model(filename, true); if (cached_model != nullptr) { return cached_model; } - // Look on disk for the current file. LoaderOptions new_options(options); - new_options.set_flags((new_options.get_flags() | LoaderOptions::LF_no_ram_cache) & - ~LoaderOptions::LF_search); + new_options.set_flags(new_options.get_flags() & ~LoaderOptions::LF_no_ram_cache); Loader *model_loader = Loader::get_global_ptr(); PT(PandaNode) panda_node = model_loader->load_sync(filename, new_options); PT(ModelRoot) node; - if (panda_node.is_null()) { - // This model was not found. - - } else { + if (!panda_node.is_null()) { if (panda_node->is_of_type(ModelRoot::get_class_type())) { node = DCAST(ModelRoot, panda_node); - } else { // We have to construct a ModelRoot node to put it under. node = new ModelRoot(filename); node->add_child(panda_node); } - node->set_fullpath(filename); } - - { - LightMutexHolder holder(_lock); - - // Look again, in case someone has just loaded the model in another - // thread. - Models::const_iterator ti; - ti = _models.find(filename); - if (ti != _models.end() && (*ti).second != cached_model) { - // This model was previously loaded. - return (*ti).second; - } - - _models[filename] = node; - } - return node; }