fix Loader error reporting

This commit is contained in:
rdb 2015-01-23 13:20:14 +01:00
parent 7b18e5aa41
commit c5dd6c69dd
6 changed files with 88 additions and 42 deletions

View File

@ -286,15 +286,14 @@ try_load_file(const Filename &pathname, const LoaderOptions &options,
LoaderFileType *requested_type) const {
BamCache *cache = BamCache::get_global_ptr();
bool cache_only = (options.get_flags() & LoaderOptions::LF_cache_only) != 0;
bool allow_ram_cache = requested_type->get_allow_ram_cache(options);
if (requested_type->get_allow_ram_cache(options)) {
if (allow_ram_cache) {
// If we're allowing a RAM cache, use the ModelPool to load the
// file.
if (!cache_only || ModelPool::has_model(pathname)) {
PT(PandaNode) node = ModelPool::load_model(pathname, options);
if (node != (PandaNode *)NULL &&
(options.get_flags() & LoaderOptions::LF_allow_instance) == 0) {
PT(PandaNode) node = ModelPool::get_model(pathname, true);
if (node != (PandaNode *)NULL) {
if ((options.get_flags() & LoaderOptions::LF_allow_instance) == 0) {
if (loader_cat.is_debug()) {
loader_cat.debug()
<< "Model " << pathname << " found in ModelPool.\n";
@ -320,16 +319,22 @@ try_load_file(const Filename &pathname, const LoaderOptions &options,
<< "Model " << pathname << " found in disk cache.\n";
}
PT(PandaNode) result = DCAST(PandaNode, record->get_data());
if (result->is_of_type(ModelRoot::get_class_type())) {
ModelRoot *model_root = DCAST(ModelRoot, result.p());
model_root->set_fullpath(pathname);
model_root->set_timestamp(record->get_source_timestamp());
}
if (premunge_data) {
SceneGraphReducer sgr;
sgr.premunge(result, RenderState::make_empty());
}
if (result->is_of_type(ModelRoot::get_class_type())) {
ModelRoot *model_root = DCAST(ModelRoot, result.p());
model_root->set_fullpath(pathname);
model_root->set_timestamp(record->get_source_timestamp());
if (allow_ram_cache) {
// Store the loaded model in the RAM cache.
ModelPool::add_model(pathname, model_root);
}
}
return result;
}
}
@ -340,6 +345,7 @@ try_load_file(const Filename &pathname, const LoaderOptions &options,
<< "Model " << pathname << " not found in cache.\n";
}
bool cache_only = (options.get_flags() & LoaderOptions::LF_cache_only) != 0;
if (!cache_only) {
PT(PandaNode) result = requested_type->load_file(pathname, options, record);
if (result != (PandaNode *)NULL) {
@ -352,6 +358,11 @@ try_load_file(const Filename &pathname, const LoaderOptions &options,
SceneGraphReducer sgr;
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.
ModelPool::add_model(pathname, DCAST(ModelRoot, result.p()));
}
return result;
}
}

View File

@ -110,7 +110,7 @@ load_file(const Filename &path, const LoaderOptions &options,
time_t timestamp = bam_file.get_reader()->get_source()->get_timestamp();
PT(PandaNode) node = bam_file.read_node(report_errors);
if (node->is_of_type(ModelRoot::get_class_type())) {
if (node != (PandaNode *)NULL && node->is_of_type(ModelRoot::get_class_type())) {
ModelRoot *model_root = DCAST(ModelRoot, node.p());
model_root->set_fullpath(path);
model_root->set_timestamp(timestamp);

View File

@ -17,7 +17,8 @@
// Function: ModelPool::has_model
// Access: Public, Static
// Description: Returns true if the model has ever been loaded,
// false otherwise.
// false otherwise. Note that this does not guarantee
// that the model is still up-to-date.
////////////////////////////////////////////////////////////////////
INLINE bool ModelPool::
has_model(const Filename &filename) {
@ -45,6 +46,20 @@ verify_model(const Filename &filename) {
return load_model(filename) != (ModelRoot *)NULL;
}
////////////////////////////////////////////////////////////////////
// Function: ModelPool::get_model
// Access: Public, Static
// Description: Returns the model that has already been previously
// loaded, or NULL otherwise. If verify is true, it
// will check if the file is still up-to-date (and
// hasn't been modified in the meantime), and if not,
// will still return NULL.
////////////////////////////////////////////////////////////////////
INLINE ModelRoot *ModelPool::
get_model(const Filename &filename, bool verify) {
return get_ptr()->ns_get_model(filename, verify);
}
////////////////////////////////////////////////////////////////////
// Function: ModelPool::load_model
// Access: Public, Static

View File

@ -52,13 +52,12 @@ ns_has_model(const Filename &filename) {
}
////////////////////////////////////////////////////////////////////
// Function: ModelPool::ns_load_model
// Function: ModelPool::ns_get_model
// Access: Private
// Description: The nonstatic implementation of load_model().
// Description: The nonstatic implementation of get_model().
////////////////////////////////////////////////////////////////////
ModelRoot *ModelPool::
ns_load_model(const Filename &filename, const LoaderOptions &options) {
VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
ns_get_model(const Filename &filename, bool verify) {
PT(ModelRoot) cached_model;
bool got_cached_model = false;
@ -74,7 +73,7 @@ ns_load_model(const Filename &filename, const LoaderOptions &options) {
}
}
if (got_cached_model) {
if (got_cached_model && verify) {
if (pgraph_cat.is_debug()) {
pgraph_cat.debug()
<< "ModelPool found " << cached_model << " for " << filename << "\n";
@ -85,6 +84,7 @@ ns_load_model(const Filename &filename, const LoaderOptions &options) {
// exist (or the model could not be loaded for some reason).
if (cache_check_timestamps) {
// Check to see if there is a file there now.
VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
if (vfs->exists(filename)) {
// There is, so try to load it.
got_cached_model = false;
@ -96,6 +96,7 @@ ns_load_model(const Filename &filename, const LoaderOptions &options) {
if (cache_check_timestamps && cached_model->get_timestamp() != 0 &&
!cached_model->get_fullpath().empty()) {
// Compare the timestamp to the file on-disk.
VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
PT(VirtualFile) vfile = vfs->get_file(cached_model->get_fullpath());
if (vfile == NULL) {
// The file has disappeared! Look further along the model-path.
@ -116,12 +117,29 @@ ns_load_model(const Filename &filename, const LoaderOptions &options) {
<< "ModelPool returning " << cached_model << " for " << filename << "\n";
}
return cached_model;
} else {
return NULL;
}
}
////////////////////////////////////////////////////////////////////
// Function: ModelPool::ns_load_model
// Access: Private
// Description: The nonstatic implementation of load_model().
////////////////////////////////////////////////////////////////////
ModelRoot *ModelPool::
ns_load_model(const Filename &filename, const LoaderOptions &options) {
// First check if it has already been loaded and is still current.
PT(ModelRoot) cached_model = ns_get_model(filename, true);
if (cached_model != (ModelRoot *)NULL) {
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 | LoaderOptions::LF_report_errors));
~LoaderOptions::LF_search);
Loader *model_loader = Loader::get_global_ptr();
PT(PandaNode) panda_node = model_loader->load_sync(filename, new_options);
@ -154,10 +172,6 @@ ns_load_model(const Filename &filename, const LoaderOptions &options) {
return (*ti).second;
}
if (pgraph_cat.is_debug()) {
pgraph_cat.debug()
<< "ModelPool storing " << node << " for " << filename << "\n";
}
_models[filename] = node;
}
@ -172,6 +186,10 @@ ns_load_model(const Filename &filename, const LoaderOptions &options) {
void ModelPool::
ns_add_model(const Filename &filename, ModelRoot *model) {
LightMutexHolder holder(_lock);
if (pgraph_cat.is_debug()) {
pgraph_cat.debug()
<< "ModelPool storing " << model << " for " << filename << "\n";
}
// We blow away whatever model was there previously, if any.
_models[filename] = model;
}

View File

@ -49,6 +49,7 @@ class EXPCL_PANDA_PGRAPH ModelPool {
PUBLISHED:
INLINE static bool has_model(const Filename &filename);
INLINE static bool verify_model(const Filename &filename);
INLINE static ModelRoot *get_model(const Filename &filename, bool verify);
BLOCKING INLINE static ModelRoot *load_model(const Filename &filename,
const LoaderOptions &options = LoaderOptions());
@ -70,6 +71,7 @@ private:
INLINE ModelPool();
bool ns_has_model(const Filename &filename);
ModelRoot *ns_get_model(const Filename &filename, bool verify);
ModelRoot *ns_load_model(const Filename &filename,
const LoaderOptions &options);
void ns_add_model(const Filename &filename, ModelRoot *model);