[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [56905] trunk/blender/source/blender/ freestyle/intern: Fix for [#35245] Freestyle getting stuck on view map creation + memory leaks.

Tamito Kajiyama rd6t-kjym at asahi-net.or.jp
Sun May 19 02:56:41 CEST 2013


Revision: 56905
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=56905
Author:   kjym3
Date:     2013-05-19 00:56:40 +0000 (Sun, 19 May 2013)
Log Message:
-----------
Fix for [#35245] Freestyle getting stuck on view map creation + memory leaks.

There were two issues:

- Line visibility computations are very slow in the case of the provided .blend file, which gave
an impression that the rendering process got stuck.  The slowness can be explained by the present
data structures used for the line visibility computations, together with the specific mesh distribution
of the test scene.  At the moment Freestyle uses a regular grid in the 2D image coordinate system
to divide tris/quads into small groups in order to accelerate the line visibility computations.
On the other hand, the test scene is populated a big plane (made of one quad) and a moderately
detailed mesh object (22K tris).  The scale of the latter mesh is animated from nearly zero to
about 0.2 to make the object show up over time.  When the scale is nearly equal to zero, all the
tris concentrate in one grid cell, so essentially there is no performance gain from the grid data
structure optimized for speed.  It looks like a better grid data structure (possibly based on
adaptive grid refinement) is necessary to genuinely address the identified performance issue.  For now
the progress bar of Blender is employed to better inform users of the amount of work done in the line
visibility computations.

- A crash was caused by an excessive memory allocation request.  The X and Y dimensions of the grid
data structure are determined based on the average area of mesh faces in the given scene.  When the big
plane in the test scene is excluded from the rendering, the average area is almost zero (on the order
of 1e-5).  As a result of this extremely small average area, the X and Y dimensions were set to a very
large number, causing a fatal memory allocation error.  The present revision has introduced a hard
upper limit to the dimensions of the grid data structure to avoid this kind of numerical instability.

Modified Paths:
--------------
    trunk/blender/source/blender/freestyle/intern/system/RenderMonitor.h
    trunk/blender/source/blender/freestyle/intern/view_map/AverageAreaGridDensityProvider.cpp
    trunk/blender/source/blender/freestyle/intern/view_map/ViewMapBuilder.cpp

Modified: trunk/blender/source/blender/freestyle/intern/system/RenderMonitor.h
===================================================================
--- trunk/blender/source/blender/freestyle/intern/system/RenderMonitor.h	2013-05-18 22:40:21 UTC (rev 56904)
+++ trunk/blender/source/blender/freestyle/intern/system/RenderMonitor.h	2013-05-19 00:56:40 UTC (rev 56905)
@@ -48,6 +48,21 @@
 
 	virtual ~RenderMonitor() {}
 
+	inline void setInfo(string info)
+	{
+		if (_re && !info.empty()) {
+			_re->i.infostr = info.c_str();
+			_re->stats_draw(_re->sdh, &_re->i);
+			_re->i.infostr = NULL;
+		}
+	}
+
+	inline void progress(float i)
+	{
+		if (_re)
+			_re->progress(_re->prh, i);
+	}
+
 	inline bool testBreak()
 	{
 		return _re && _re->test_break(_re->tbh);

Modified: trunk/blender/source/blender/freestyle/intern/view_map/AverageAreaGridDensityProvider.cpp
===================================================================
--- trunk/blender/source/blender/freestyle/intern/view_map/AverageAreaGridDensityProvider.cpp	2013-05-18 22:40:21 UTC (rev 56904)
+++ trunk/blender/source/blender/freestyle/intern/view_map/AverageAreaGridDensityProvider.cpp	2013-05-19 00:56:40 UTC (rev 56905)
@@ -83,6 +83,13 @@
 	}
 
 	_cellSize = sqrt(cellArea);
+	unsigned maxCells = 931; // * 1.1 = 1024
+	if (std::max(prosceniumWidth, prosceniumHeight) / _cellSize > maxCells) {
+		if (G.debug & G_DEBUG_FREESTYLE) {
+			cout << "Scene-dependent cell size (" << _cellSize << " square) is too small." << endl;
+		}
+		_cellSize = std::max(prosceniumWidth, prosceniumHeight) / maxCells;
+	}
 	// Now we know how many cells make each side of our grid
 	_cellsX = ceil(prosceniumWidth / _cellSize);
 	_cellsY = ceil(prosceniumHeight / _cellSize);

Modified: trunk/blender/source/blender/freestyle/intern/view_map/ViewMapBuilder.cpp
===================================================================
--- trunk/blender/source/blender/freestyle/intern/view_map/ViewMapBuilder.cpp	2013-05-18 22:40:21 UTC (rev 56904)
+++ trunk/blender/source/blender/freestyle/intern/view_map/ViewMapBuilder.cpp	2013-05-19 00:56:40 UTC (rev 56905)
@@ -28,6 +28,7 @@
 #include <algorithm>
 #include <memory>
 #include <stdexcept>
+#include <sstream>
 
 #include "FRS_freestyle.h"
 
@@ -412,13 +413,24 @@
 	int nSamples = 0;
 	vector<WFace*> wFaces;
 	WFace *wFace = NULL;
+	unsigned cnt = 0;
+	unsigned cntStep = (unsigned)ceil(0.01f * vedges.size());
 	unsigned tmpQI = 0;
 	unsigned qiClasses[256];
 	unsigned maxIndex, maxCard;
 	unsigned qiMajority;
 	for (vector<ViewEdge*>::iterator ve = vedges.begin(), veend = vedges.end(); ve != veend; ve++) {
-		if (iRenderMonitor && iRenderMonitor->testBreak())
-			break;
+		if (iRenderMonitor) {
+			if (iRenderMonitor->testBreak())
+				break;
+			if (cnt % cntStep == 0) {
+				stringstream ss;
+				ss << "Freestyle: Visibility computations " << (100 * cnt / vedges.size()) << "%";
+				iRenderMonitor->setInfo(ss.str());
+				iRenderMonitor->progress((float)cnt / vedges.size());
+			}
+			cnt++;
+		}
 #if LOGGING
 		if (_global.debug & G_DEBUG_FREESTYLE) {
 			cout << "Processing ViewEdge " << (*ve)->getId() << endl;
@@ -583,6 +595,12 @@
 
 		wFaces.clear();
 	}
+	if (iRenderMonitor) {
+		stringstream ss;
+		ss << "Freestyle: Visibility computations " << (100 * cnt / vedges.size()) << "%";
+		iRenderMonitor->setInfo(ss.str());
+		iRenderMonitor->progress((float)cnt / vedges.size());
+	}
 }
 
 template <typename G, typename I>




More information about the Bf-blender-cvs mailing list