Fix T57890: freestyle rendering crash.
authorBrecht Van Lommel <brechtvanlommel@gmail.com>
Fri, 4 Jan 2019 16:35:07 +0000 (17:35 +0100)
committerBrecht Van Lommel <brechtvanlommel@gmail.com>
Fri, 4 Jan 2019 16:58:55 +0000 (17:58 +0100)
Depsgraph objects are deleted after conversion to Freestyle data structures,
so don't keep a pointer to their name strings.

source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp
source/blender/freestyle/intern/python/BPy_SShape.cpp
source/blender/freestyle/intern/python/BPy_ViewShape.cpp
source/blender/freestyle/intern/scene_graph/Rep.h
source/blender/freestyle/intern/view_map/Silhouette.h
source/blender/freestyle/intern/view_map/ViewMap.h
source/blender/freestyle/intern/winged_edge/WEdge.h

index a42e59ddb2a7cecd1f3f95192bcd35089675ead8..176193bc65ae0602b458056158000608d4475856 100644 (file)
@@ -733,7 +733,7 @@ void BlenderFileLoader::insertShapeNode(Object *ob, Mesh *me, int id)
        // sets the id of the rep
        rep->setId(Id(id, 0));
        rep->setName(ob->id.name + 2);
-       rep->setLibraryPath(ob->id.lib ? ob->id.lib->name : NULL);
+       rep->setLibraryPath(ob->id.lib ? ob->id.lib->name : "");
 
        const BBox<Vec3r> bbox = BBox<Vec3r>(Vec3r(ls.minBBox[0], ls.minBBox[1], ls.minBBox[2]),
                                             Vec3r(ls.maxBBox[0], ls.maxBBox[1], ls.maxBBox[2]));
index 28c9e815196629ef953c23045231e914af7004b8..00a1f5ce34dd1fb5d418a60c4a52b251e5d91d2a 100644 (file)
@@ -185,7 +185,7 @@ PyDoc_STRVAR(SShape_name_doc,
 
 static PyObject *SShape_name_get(BPy_SShape *self, void *UNUSED(closure))
 {
-       return PyUnicode_FromString(self->ss->getName());
+       return PyUnicode_FromString(self->ss->getName().c_str());
 }
 
 static int SShape_name_set(BPy_SShape *self, PyObject *value, void *UNUSED(closure))
index 33c18c3ce8014b563bdd900fabe01c4719a5d26f..f3f8fc616fdc8dbf528cf8c310c4f4efe4a0c4d6 100644 (file)
@@ -293,7 +293,7 @@ PyDoc_STRVAR(ViewShape_name_doc,
 
 static PyObject *ViewShape_name_get(BPy_ViewShape *self, void *UNUSED(closure))
 {
-       return PyUnicode_FromString(self->vs->getName());
+       return PyUnicode_FromString(self->vs->getName().c_str());
 }
 
 PyDoc_STRVAR(ViewShape_library_path_doc,
@@ -303,10 +303,7 @@ PyDoc_STRVAR(ViewShape_library_path_doc,
 
 static PyObject *ViewShape_library_path_get(BPy_ViewShape *self, void *UNUSED(closure))
 {
-       const char *name = self->vs->getLibraryPath();
-       if (!name)
-               Py_RETURN_NONE;
-       return PyUnicode_FromString(name);
+       return PyUnicode_FromString(self->vs->getLibraryPath().c_str());
 }
 
 PyDoc_STRVAR(ViewShape_id_doc,
index 4c8017e162d22df659e40f32c72dcdcb97e74224..222653b24330eaa54eced2f563b89ae75b3de59f 100644 (file)
@@ -28,6 +28,8 @@
  *  \date 25/01/2002
  */
 
+#include <string>
+
 #include "FrsMaterial.h"
 #include "SceneVisitor.h"
 
@@ -38,6 +40,8 @@
 #include "../system/Id.h"
 #include "../system/Precision.h"
 
+using namespace std;
+
 namespace Freestyle {
 
 using namespace Geometry;
@@ -48,8 +52,6 @@ public:
        inline Rep() : BaseObject()
        {
                _Id = 0;
-               _Name = 0;
-               _LibraryPath = 0;
                _FrsMaterial = 0;
        }
 
@@ -132,12 +134,12 @@ public:
                return _Id;
        }
 
-       inline const char *getName() const
+       inline const string& getName() const
        {
                return _Name;
        }
 
-       inline const char *getLibraryPath() const
+       inline const string& getLibraryPath() const
        {
                return _LibraryPath;
        }
@@ -158,12 +160,12 @@ public:
                _Id = id;
        }
 
-       inline void setName(const char *name)
+       inline void setName(const string& name)
        {
                _Name = name;
        }
 
-       inline void setLibraryPath(const char *path)
+       inline void setLibraryPath(const string& path)
        {
                _LibraryPath = path;
        }
@@ -176,8 +178,8 @@ public:
 private:
        BBox<Vec3f> _BBox;
        Id _Id;
-       const char *_Name;
-       const char *_LibraryPath;
+       string _Name;
+       string _LibraryPath;
        FrsMaterial *_FrsMaterial;
 };
 
index a18cf41797b27c53bfbca794431a7f8dead72f45..4276409190eadc01a30ccefea4e602ddbac822bc 100644 (file)
@@ -1415,8 +1415,8 @@ private:
        vector<SVertex*> _verticesList;  // list of all vertices
        vector<FEdge*> _edgesList;       // list of all edges
        Id _Id;
-       const char *_Name;
-       const char *_LibraryPath;
+       string _Name;
+       string _LibraryPath;
        BBox<Vec3r> _BBox;
        vector<FrsMaterial> _FrsMaterials;
 
@@ -1436,8 +1436,6 @@ public:
                userdata = NULL;
                _importance = 0.0f;
                _ViewShape = NULL;
-               _Name = NULL;
-               _LibraryPath = NULL;
        }
 
        /*! Copy constructor */
@@ -1891,13 +1889,13 @@ public:
        }
 
        /*! Returns the name of the Shape. */
-       inline const char *getName() const
+       inline const string& getName() const
        {
                return _Name;
        }
 
        /*! Returns the library path of the Shape. */
-       inline const char *getLibraryPath() const
+       inline const string& getLibraryPath() const
        {
                return _LibraryPath;
        }
@@ -1910,13 +1908,13 @@ public:
        }
 
        /*! Sets the name of the shape.*/
-       inline void setName(const char *name)
+       inline void setName(const string& name)
        {
                _Name = name;
        }
 
        /*! Sets the library path of the shape.*/
-       inline void setLibraryPath(const char *path)
+       inline void setLibraryPath(const string& path)
        {
                _LibraryPath = path;
        }
index 0acc6ca39d8d5543cc9c2b81ca93445e42bba0ed..87b59dc1b54463af0a8324ab9d9a37e06e998ed7 100644 (file)
@@ -1566,13 +1566,13 @@ public:
        }
 
        /*! Returns the ViewShape name. */
-       inline const char *getName() const
+       inline const string& getName() const
        {
                return _SShape->getName();
        }
 
        /*! Returns the ViewShape library path. */
-       inline const char *getLibraryPath() const
+       inline const string& getLibraryPath() const
        {
                return _SShape->getLibraryPath();
        }
index 30f55ff7e73046e4e2809a9e55fb3ebf74251ccd..7efed908d73ead84a29d9778c78a144382a62ef4 100644 (file)
@@ -1024,8 +1024,8 @@ protected:
        vector<WEdge *> _EdgeList;
        vector<WFace *> _FaceList;
        int _Id;
-       const char *_Name;
-       const char *_LibraryPath;
+       string _Name;
+       string _LibraryPath;
        static unsigned _SceneCurrentId;
 #if 0
        Vec3f _min;
@@ -1044,8 +1044,6 @@ public:
 #endif
                _Id = _SceneCurrentId;
                _SceneCurrentId++;
-               _Name = 0;
-               _LibraryPath = 0;
        }
 
        /*! copy constructor */
@@ -1125,12 +1123,12 @@ public:
        }
 #endif
 
-       inline const char *getName() const
+       inline const string& getName() const
        {
                return _Name;
        }
 
-       inline const char *getLibraryPath() const
+       inline const string& getLibraryPath() const
        {
                return _LibraryPath;
        }
@@ -1179,12 +1177,12 @@ public:
                _FrsMaterials = iMaterials;
        }
 
-       inline void setName(const char *name)
+       inline void setName(const string& name)
        {
                _Name = name;
        }
 
-       inline void setLibraryPath(const char *path)
+       inline void setLibraryPath(const string& path)
        {
                _LibraryPath = path;
        }