[Bf-blender-cvs] [8bd90fb8a5] temp-sybren-alembic: Alembic import: replaced GHash * with std::map<>
Sybren A. Stüvel
noreply at git.blender.org
Tue Feb 28 16:58:36 CET 2017
Commit: 8bd90fb8a5c5aa5fbe21792edda202acbbe30ba9
Author: Sybren A. Stüvel
Date: Tue Feb 28 16:53:48 2017 +0100
Branches: temp-sybren-alembic
https://developer.blender.org/rB8bd90fb8a5c5aa5fbe21792edda202acbbe30ba9
Alembic import: replaced GHash * with std::map<>
The char* that were returned by Alembic were unstable, as they pointed to
Alembic-managed memory, which Alembic reuses for different strings. As a
result, the pointers were unsuitable for hash keys. Copying the strings
into std::string instances solves this.
===================================================================
M source/blender/alembic/intern/alembic_capi.cc
===================================================================
diff --git a/source/blender/alembic/intern/alembic_capi.cc b/source/blender/alembic/intern/alembic_capi.cc
index b139b42bbc..e663eb5ddd 100644
--- a/source/blender/alembic/intern/alembic_capi.cc
+++ b/source/blender/alembic/intern/alembic_capi.cc
@@ -376,12 +376,13 @@ void ABC_export(
/* ********************** Import file ********************** */
+typedef std::map<std::string, AbcObjectReader *> readers_map_type;
static int visit_object(const IObject &object,
std::vector<AbcObjectReader *> &readers,
- GHash *readers_map,
+ readers_map_type & readers_map,
ImportSettings &settings)
{
- const char *full_name = object.getFullName().c_str();
+ const std::string & full_name = object.getFullName();
if (!object.valid()) {
std::cerr << " - " << full_name << ": object is invalid, skipping it and all its children.\n";
@@ -521,10 +522,11 @@ static int visit_object(const IObject &object,
AlembicObjectPath *abc_path = static_cast<AlembicObjectPath *>(
MEM_callocN(sizeof(AlembicObjectPath), "AlembicObjectPath"));
- BLI_strncpy(abc_path->path, full_name, PATH_MAX);
+ BLI_strncpy(abc_path->path, full_name.c_str(), PATH_MAX);
BLI_addtail(&settings.cache_file->object_paths, abc_path);
- BLI_ghash_insert(readers_map, const_cast<char *>(full_name), reader);
+ BLI_assert(readers_map.find(full_name) == readers_map.end());
+ readers_map[full_name] = reader;
}
return parent_is_part_of_this_object;
@@ -542,7 +544,7 @@ struct ImportJobData {
char filename[1024];
ImportSettings settings;
- GHash *reader_map;
+ readers_map_type reader_map;
std::vector<AbcObjectReader *> readers;
short *stop;
@@ -617,7 +619,7 @@ static void import_startjob(void *user_data, short *stop, short *do_update, floa
*data->do_update = true;
*data->progress = 0.05f;
- data->reader_map = BLI_ghash_str_new("alembic parent ghash");
+ data->reader_map.clear();
/* Parse Alembic Archive. */
visit_object(archive->getTop(), data->readers, data->reader_map, data->settings);
@@ -690,9 +692,11 @@ static void import_startjob(void *user_data, short *stop, short *do_update, floa
IObject alembic_parent = iobject.getParent();
while (alembic_parent) {
- parent_reader = reinterpret_cast<AbcObjectReader *>(
- BLI_ghash_lookup(data->reader_map, alembic_parent.getFullName().c_str()));
- if (parent_reader != NULL) {
+ readers_map_type::iterator it;
+ it = data->reader_map.find(alembic_parent.getFullName());
+
+ if (it != data->reader_map.end()) {
+ parent_reader = it->second;
break; // found the parent reader.
}
@@ -777,9 +781,7 @@ static void import_endjob(void *user_data)
}
}
- if (data->reader_map) {
- BLI_ghash_free(data->reader_map, NULL, NULL);
- }
+ data->reader_map.clear();
switch (data->error_code) {
default:
@@ -814,7 +816,6 @@ void ABC_import(bContext *C, const char *filepath, float scale, bool is_sequence
job->settings.sequence_len = sequence_len;
job->settings.offset = offset;
job->settings.validate_meshes = validate_meshes;
- job->reader_map = NULL;
job->error_code = ABC_NO_ERROR;
job->was_cancelled = false;
More information about the Bf-blender-cvs
mailing list