[Bf-blender-cvs] [8b9d181] cycles_memory_experiments: Smoke: Fix crash when auto-sim happens outside of the backed frame range

Sergey Sharybin noreply at git.blender.org
Thu Apr 23 11:53:12 CEST 2015


Commit: 8b9d1818a57f538ec1c629ce94871351601ffa4c
Author: Sergey Sharybin
Date:   Thu Apr 23 14:51:21 2015 +0500
Branches: cycles_memory_experiments
https://developer.blender.org/rB8b9d1818a57f538ec1c629ce94871351601ffa4c

Smoke: Fix crash when auto-sim happens outside of the backed frame range

Apparently, even if the smoke is backed to an external files it still could be
tried to be simulated at the frames outside of the baked range.

Kinda weird feature which isn't really safe, but better not to crash here.

Not totally happy with the code yet, will check with Lukas or Daniel how it
could be improved further.

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

M	intern/smoke/extern/smoke_API.h
M	intern/smoke/intern/WTURBULENCE.cpp
M	intern/smoke/intern/WTURBULENCE.h
M	intern/smoke/intern/smoke_API.cpp
M	source/blender/blenkernel/intern/smoke.c

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

diff --git a/intern/smoke/extern/smoke_API.h b/intern/smoke/extern/smoke_API.h
index 3c86bc9..8fa7daa 100644
--- a/intern/smoke/extern/smoke_API.h
+++ b/intern/smoke/extern/smoke_API.h
@@ -109,6 +109,7 @@ int smoke_has_colors(struct FLUID_3D *fluid);
 int smoke_turbulence_has_fuel(struct WTURBULENCE *wt);
 int smoke_turbulence_has_colors(struct WTURBULENCE *wt);
 
+void smoke_ensure_simulation(struct FLUID_3D *fluid, struct WTURBULENCE *wt);
 void smoke_ensure_heat(struct FLUID_3D *fluid);
 void smoke_ensure_fire(struct FLUID_3D *fluid, struct WTURBULENCE *wt);
 void smoke_ensure_colors(struct FLUID_3D *fluid, struct WTURBULENCE *wt, float init_r, float init_g, float init_b);
diff --git a/intern/smoke/intern/WTURBULENCE.cpp b/intern/smoke/intern/WTURBULENCE.cpp
index 8a070ab..2260057 100644
--- a/intern/smoke/intern/WTURBULENCE.cpp
+++ b/intern/smoke/intern/WTURBULENCE.cpp
@@ -91,7 +91,7 @@ WTURBULENCE::WTURBULENCE(int xResSm, int yResSm, int zResSm, int amplify, int no
 	_densityBig = new float[_totalCellsBig];
 	memset(_densityBig, 0, sizeof(*_densityBig) * _totalCellsBig);
 
-	if (init_sim) {
+	if (_need_sim_data) {
 		_densityBigOld = new float[_totalCellsBig];
 		memset(_densityBigOld, 0, sizeof(*_densityBigOld) * _totalCellsBig);
 	}
@@ -132,7 +132,7 @@ WTURBULENCE::WTURBULENCE(int xResSm, int yResSm, int zResSm, int amplify, int no
 		_tcW[index] = z*dz;
 		}
 	
-	if (init_sim) {
+	if (_need_sim_data) {
 		_tcTemp = new float[_totalCellsSm];
 		memset(_tcTemp, 0, sizeof(*_tcTemp) * _totalCellsSm);
 	}
@@ -145,6 +145,43 @@ WTURBULENCE::WTURBULENCE(int xResSm, int yResSm, int zResSm, int amplify, int no
 	setNoise(noisetype, noisefile_path);
 }
 
+void WTURBULENCE::initSimulation()
+{
+	if (_need_sim_data) {
+		return;
+	}
+
+	if(_densityBigOld == NULL) {
+		_densityBigOld = new float[_totalCellsBig];
+		memset(_densityBigOld, 0, sizeof(*_densityBigOld) * _totalCellsBig);
+	}
+
+	if (_tcTemp == NULL) {
+		_tcTemp = new float[_totalCellsSm];
+		memset(_tcTemp, 0, sizeof(*_tcTemp) * _totalCellsSm);
+	}
+
+	if (_fuelBig != NULL) {
+		if (_fuelBigOld == NULL) {
+			_fuelBigOld = new float[_totalCellsBig];
+			_reactBigOld = new float[_totalCellsBig];
+			memset(_fuelBigOld, 0, sizeof(*_fuelBigOld) * _totalCellsBig);
+			memset(_reactBigOld, 0, sizeof(*_reactBigOld) * _totalCellsBig);
+		}
+	}
+
+	if (_color_rBig != NULL) {
+		if (_color_rBigOld == NULL) {
+			_color_rBigOld = new float[_totalCellsBig];
+			_color_gBigOld = new float[_totalCellsBig];
+			_color_bBigOld = new float[_totalCellsBig];
+			memset(_color_rBigOld, 0, sizeof(*_color_rBigOld) * _totalCellsBig);
+			memset(_color_gBigOld, 0, sizeof(*_color_gBigOld) * _totalCellsBig);
+			memset(_color_bBigOld, 0, sizeof(*_color_bBigOld) * _totalCellsBig);
+		}
+	}
+}
+
 void WTURBULENCE::initFire()
 {
 	if (!_fuelBig) {
diff --git a/intern/smoke/intern/WTURBULENCE.h b/intern/smoke/intern/WTURBULENCE.h
index 206a278..fbc3e9e 100644
--- a/intern/smoke/intern/WTURBULENCE.h
+++ b/intern/smoke/intern/WTURBULENCE.h
@@ -41,6 +41,9 @@ struct WTURBULENCE
 		/// destructor
 		virtual ~WTURBULENCE();
 
+		// Ensure data needed for simulation is allocated
+		void initSimulation();
+
 		void initFire();
 		void initColors(float init_r, float init_g, float init_b);
 		
diff --git a/intern/smoke/intern/smoke_API.cpp b/intern/smoke/intern/smoke_API.cpp
index 829ece8..28b3953 100644
--- a/intern/smoke/intern/smoke_API.cpp
+++ b/intern/smoke/intern/smoke_API.cpp
@@ -480,6 +480,13 @@ extern "C" int smoke_turbulence_has_colors(WTURBULENCE *wt)
 }
 
 /* additional field initialization */
+extern "C" void smoke_ensure_simulation(FLUID_3D * /*fluid*/, WTURBULENCE *wt)
+{
+	if (wt) {
+		wt->initSimulation();
+	}
+}
+
 extern "C" void smoke_ensure_heat(FLUID_3D *fluid)
 {
 	if (fluid) {
diff --git a/source/blender/blenkernel/intern/smoke.c b/source/blender/blenkernel/intern/smoke.c
index ad5f898..069f913 100644
--- a/source/blender/blenkernel/intern/smoke.c
+++ b/source/blender/blenkernel/intern/smoke.c
@@ -2754,6 +2754,7 @@ static void smokeModifier_process(SmokeModifierData *smd, Scene *scene, Object *
 
 		if (sds->wt)
 		{
+			smoke_ensure_simulation(sds->fluid, sds->wt);
 			smoke_turbulence_step(sds->wt, sds->fluid);
 		}




More information about the Bf-blender-cvs mailing list