[Bf-blender-cvs] [74afc56] alembic_pointcache: Better error handling support for point cache functions.

Lukas Tönne noreply at git.blender.org
Wed Nov 12 18:02:14 CET 2014


Commit: 74afc561206edc224a47c40ce78e7943fe3c6ae2
Author: Lukas Tönne
Date:   Wed Nov 12 18:00:59 2014 +0100
Branches: alembic_pointcache
https://developer.blender.org/rB74afc561206edc224a47c40ce78e7943fe3c6ae2

Better error handling support for point cache functions.

This defines wrapper macros which catch exceptions from Alembic and
provide ways of reporting these in different ways, depending on the
context.

===================================================================

M	source/blender/ikplugin/intern/itasc_plugin.cpp
M	source/blender/modifiers/intern/MOD_pointcache.c
M	source/blender/pointcache/CMakeLists.txt
M	source/blender/pointcache/PTC_api.cpp
M	source/blender/pointcache/PTC_api.h
M	source/blender/pointcache/intern/mesh.cpp
M	source/blender/pointcache/intern/reader.cpp
A	source/blender/pointcache/util/util_error_handler.cpp
A	source/blender/pointcache/util/util_error_handler.h
M	source/blender/pointcache/util/util_types.h

===================================================================

diff --git a/source/blender/ikplugin/intern/itasc_plugin.cpp b/source/blender/ikplugin/intern/itasc_plugin.cpp
index afff97a..2648c66 100644
--- a/source/blender/ikplugin/intern/itasc_plugin.cpp
+++ b/source/blender/ikplugin/intern/itasc_plugin.cpp
@@ -86,7 +86,7 @@ struct IK_Data {
 typedef float Vector3[3];
 typedef float Vector4[4];
 struct IK_Target;
-typedef void (*ErrorCallback)(const iTaSC::ConstraintValues *values, unsigned int nvalues, IK_Target *iktarget);
+typedef void (*PTCErrorCallback)(const iTaSC::ConstraintValues *values, unsigned int nvalues, IK_Target *iktarget);
 
 // one structure for each target in the scene
 struct IK_Target
@@ -97,7 +97,7 @@ struct IK_Target
 	struct bConstraint*		blenderConstraint;
 	struct bPoseChannel*    rootChannel;
 	Object*					owner;			//for auto IK
-	ErrorCallback			errorCallback;
+	PTCErrorCallback			errorCallback;
 	std::string				targetName;
 	std::string				constraintName;
 	unsigned short			controlType;
diff --git a/source/blender/modifiers/intern/MOD_pointcache.c b/source/blender/modifiers/intern/MOD_pointcache.c
index 1b7ba00..7137455 100644
--- a/source/blender/modifiers/intern/MOD_pointcache.c
+++ b/source/blender/modifiers/intern/MOD_pointcache.c
@@ -100,6 +100,8 @@ static DerivedMesh *pointcache_do(PointCacheModifierData *pcmd, Object *ob, Deri
 	
 	DerivedMesh *finaldm = dm;
 	
+	PTC_error_handler_modifier(&pcmd->modifier);
+	
 	if (mode == MOD_POINTCACHE_MODE_NONE) {
 		mode = PTC_mod_point_cache_set_mode(scene, ob, pcmd, MOD_POINTCACHE_MODE_READ);
 	}
@@ -120,6 +122,8 @@ static DerivedMesh *pointcache_do(PointCacheModifierData *pcmd, Object *ob, Deri
 		}
 	}
 	
+	PTC_error_handler_std();
+	
 	return finaldm;
 }
 
diff --git a/source/blender/pointcache/CMakeLists.txt b/source/blender/pointcache/CMakeLists.txt
index 076be46..eb03e26 100644
--- a/source/blender/pointcache/CMakeLists.txt
+++ b/source/blender/pointcache/CMakeLists.txt
@@ -37,6 +37,8 @@ set(INC_SYS
 )
 
 set(SRC
+	util/util_error_handler.h
+	util/util_error_handler.cpp
 	util/util_frame_mapper.h
 	util/util_frame_mapper.cpp
 	util/util_path.h
diff --git a/source/blender/pointcache/PTC_api.cpp b/source/blender/pointcache/PTC_api.cpp
index 29a0522..6709d6f 100644
--- a/source/blender/pointcache/PTC_api.cpp
+++ b/source/blender/pointcache/PTC_api.cpp
@@ -20,6 +20,8 @@
 
 #ifdef WITH_ALEMBIC
 
+#include "util/util_error_handler.h"
+
 #include "reader.h"
 #include "writer.h"
 #include "export.h"
@@ -27,13 +29,62 @@
 extern "C" {
 #include "BLI_math.h"
 
+#include "DNA_modifier_types.h"
 #include "DNA_pointcache_types.h"
 
+#include "BKE_modifier.h"
+#include "BKE_report.h"
+
 #include "RNA_access.h"
 }
 
 using namespace PTC;
 
+void PTC_error_handler_std(void)
+{
+	ErrorHandler::clear_default_handler();
+}
+
+void PTC_error_handler_callback(PTCErrorCallback cb, void *userdata)
+{
+	ErrorHandler::set_default_handler(new CallbackErrorHandler(cb, userdata));
+}
+
+static ReportType report_type_from_error_level(PTCErrorLevel level)
+{
+	switch (level) {
+		case PTC_ERROR_INFO:        return RPT_INFO;
+		case PTC_ERROR_WARNING:     return RPT_WARNING;
+		case PTC_ERROR_CRITICAL:    return RPT_ERROR;
+	}
+	return RPT_ERROR;
+}
+
+static void error_handler_reports_cb(void *vreports, PTCErrorLevel level, const char *message)
+{
+	ReportList *reports = (ReportList *)vreports;
+	
+	BKE_report(reports, report_type_from_error_level(level), message);
+}
+
+void PTC_error_handler_reports(struct ReportList *reports)
+{
+	ErrorHandler::set_default_handler(new CallbackErrorHandler(error_handler_reports_cb, reports));
+}
+
+static void error_handler_modifier_cb(void *vmd, PTCErrorLevel UNUSED(level), const char *message)
+{
+	ModifierData *md = (ModifierData *)vmd;
+	
+	modifier_setError(md, "%s", message);
+}
+
+void PTC_error_handler_modifier(struct ModifierData *md)
+{
+	ErrorHandler::set_default_handler(new CallbackErrorHandler(error_handler_modifier_cb, md));
+}
+
+
 void PTC_validate(PointCache *cache, int framenr)
 {
 	if (cache) {
diff --git a/source/blender/pointcache/PTC_api.h b/source/blender/pointcache/PTC_api.h
index 21848d2..5ea7cd8 100644
--- a/source/blender/pointcache/PTC_api.h
+++ b/source/blender/pointcache/PTC_api.h
@@ -30,10 +30,12 @@ struct Scene;
 struct EvaluationContext;
 struct PointCache;
 struct PointerRNA;
+struct ReportList;
 
 struct ClothModifierData;
 struct DerivedMesh;
 struct DynamicPaintSurface;
+struct ModifierData;
 struct Object;
 struct ParticleSystem;
 struct PointCacheModifierData;
@@ -44,6 +46,12 @@ struct SoftBody;
 struct PTCWriter;
 struct PTCReader;
 
+/*** Error Handling ***/
+void PTC_error_handler_std(void);
+void PTC_error_handler_callback(PTCErrorCallback cb, void *userdata);
+void PTC_error_handler_reports(struct ReportList *reports);
+void PTC_error_handler_modifier(struct ModifierData *md);
+
 void PTC_validate(struct PointCache *cache, int framenr);
 void PTC_invalidate(struct PointCache *cache);
 
diff --git a/source/blender/pointcache/intern/mesh.cpp b/source/blender/pointcache/intern/mesh.cpp
index b9264aa..e623616 100644
--- a/source/blender/pointcache/intern/mesh.cpp
+++ b/source/blender/pointcache/intern/mesh.cpp
@@ -382,6 +382,8 @@ ePointCacheModifierMode PTC_mod_point_cache_get_mode(PointCacheModifierData *pcm
 
 ePointCacheModifierMode PTC_mod_point_cache_set_mode(Scene *scene, Object *ob, PointCacheModifierData *pcmd, ePointCacheModifierMode mode)
 {
+	PTC_error_handler_modifier(&pcmd->modifier);
+	
 	switch (mode) {
 		case MOD_POINTCACHE_MODE_READ:
 			if (pcmd->writer) {
@@ -414,4 +416,6 @@ ePointCacheModifierMode PTC_mod_point_cache_set_mode(Scene *scene, Object *ob, P
 			}
 			return MOD_POINTCACHE_MODE_NONE;
 	}
+	
+	PTC_error_handler_std();
 }
diff --git a/source/blender/pointcache/intern/reader.cpp b/source/blender/pointcache/intern/reader.cpp
index e54926a..21f4447 100644
--- a/source/blender/pointcache/intern/reader.cpp
+++ b/source/blender/pointcache/intern/reader.cpp
@@ -21,6 +21,7 @@
 
 #include "reader.h"
 #include "util_path.h"
+#include "util_error_handler.h"
 
 extern "C" {
 #include "BLI_fileops.h"
@@ -37,7 +38,9 @@ Reader::Reader(Scene *scene, ID *id, PointCache *cache) :
     m_scene(scene)
 {
 	std::string filename = ptc_archive_path(cache, id);
-	m_archive = IArchive(AbcCoreHDF5::ReadArchive(), filename, ErrorHandler::kNoisyNoopPolicy);
+	PTC_SAFE_CALL_BEGIN
+	m_archive = IArchive(AbcCoreHDF5::ReadArchive(), filename, Abc::ErrorHandler::kThrowPolicy);
+	PTC_SAFE_CALL_END
 }
 
 Reader::~Reader()
diff --git a/source/blender/pointcache/util/util_error_handler.cpp b/source/blender/pointcache/util/util_error_handler.cpp
new file mode 100644
index 0000000..62db5d8
--- /dev/null
+++ b/source/blender/pointcache/util/util_error_handler.cpp
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2013, Blender Foundation.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "util_error_handler.h"
+
+namespace PTC {
+
+ErrorHandler *ErrorHandler::m_default_handler = new StdErrorHandler(PTC_ERROR_INFO);
+
+ErrorHandler::~ErrorHandler()
+{
+}
+
+void ErrorHandler::set_default_handler(ErrorHandler *handler)
+{
+	if (m_default_handler)
+		delete m_default_handler;
+	
+	if (handler)
+		m_default_handler = handler;
+	else
+		m_default_handler = new StdErrorHandler(PTC_ERROR_INFO);
+}
+
+void ErrorHandler::clear_default_handler()
+{
+	if (m_default_handler)
+		delete m_default_handler;
+	
+	m_default_handler = new StdErrorHandler(PTC_ERROR_INFO);
+}
+
+
+StdErrorHandler::StdErrorHandler(PTCErrorLevel level) :
+    m_verbosity(level)
+{
+}
+
+void StdErrorHandler::handle(PTCErrorLevel level, const char *message)
+{
+	/* ignore levels below the verbosity setting */
+	if (level >= m_verbosity) {
+		std::cerr << message << std::endl;
+	}
+}
+
+
+CallbackErrorHandler::CallbackErrorHandler(PTCErrorCallback cb, void *userdata) :
+    m_callback(cb),
+    m_userdata(userdata)
+{
+}
+
+void CallbackErrorHandler::handle(PTCErrorLevel level, const char *message)
+{
+	m_callback(m_userdata, level, message);
+}
+
+} /* namespace PTC */
diff --git a/source/blender/pointcache/util/util_error_handler.h b/source/blender/pointcache/util/util_error_handler.h
new file mode 100644
index 0000000..c535bac
--- /dev/null
+++ b/source/blender/pointcache/util/util_error_handler.h
@@ -0,0 +1,150 @@
+/*
+ * Copyright 2013, Blender Foundation.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef PTC_UTIL_ERROR_HANDLER_H
+#define PTC_UTIL_ERROR_HANDLER_H
+
+#include <stdio.h>
+
+#include <Alembic/Abc/ErrorHandler.h>
+
+extern "C" {
+#include "BLI_utildefines.h"
+#include "BLI_string.h"
+}
+
+#include "util/util_types.h"
+
+struct ReportList;
+
+namespace PTC {
+
+class ErrorHandler
+{
+public:
+	virtual ~ErrorHandler();
+	
+	virtual void handle(PTCErrorLevel level, const char *message) = 0;
+	
+	static ErrorHandler *get_default_handler() { return m_defau

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list