diff --git a/intern/cycles/blender/blender_sync.cpp b/intern/cycles/blender/blender_sync.cpp
index 72ed1b84915b4ebf0289b2bc3e79891ad0e7d650..e9e39e485f5a46c7b07da819e8c884fa2f530ed6 100644
--- a/intern/cycles/blender/blender_sync.cpp
+++ b/intern/cycles/blender/blender_sync.cpp
@@ -392,7 +392,7 @@ SessionParams BlenderSync::get_session_params(BL::RenderEngine b_engine, BL::Use
 		else {
 			params.samples = get_int(cscene, "preview_aa_samples");
 			if(params.samples == 0)
-				params.samples = INT_MAX;
+				params.samples = 65536;
 		}
 	}
 	else {
@@ -402,7 +402,7 @@ SessionParams BlenderSync::get_session_params(BL::RenderEngine b_engine, BL::Use
 		else {
 			params.samples = get_int(cscene, "preview_samples");
 			if(params.samples == 0)
-				params.samples = INT_MAX;
+				params.samples = 65536;
 		}
 	}
 
diff --git a/intern/cycles/render/session.cpp b/intern/cycles/render/session.cpp
index d13e86429d6f2bf3878f3891239accb837ef2510..9ff2b91e25e4a9b7be538b4dcee155a3a0cc8bf7 100644
--- a/intern/cycles/render/session.cpp
+++ b/intern/cycles/render/session.cpp
@@ -786,7 +786,7 @@ void Session::update_status_time(bool show_pause, bool show_done)
 			substatus += string_printf(", Sample %d/%d", sample, num_samples);
 		}
 	}
-	else if(tile_manager.num_samples == INT_MAX)
+	else if(tile_manager.num_samples == 65536)
 		substatus = string_printf("Path Tracing Sample %d", sample+1);
 	else
 		substatus = string_printf("Path Tracing Sample %d/%d", sample+1, tile_manager.num_samples);
diff --git a/release/datafiles/splash.png b/release/datafiles/splash.png
index 3c05ba86cd32bbf6665678ecacb8e6e55c39952c..9551fad2fac3dc8888220ecd910dc0fed4b2540f 100644
Binary files a/release/datafiles/splash.png and b/release/datafiles/splash.png differ
diff --git a/source/blender/blenkernel/BKE_blender.h b/source/blender/blenkernel/BKE_blender.h
index e73b30ab98a49fe49fd9a50d958b81798778275c..cf677165f11a5f949e9a384ded7850048a37332d 100644
--- a/source/blender/blenkernel/BKE_blender.h
+++ b/source/blender/blenkernel/BKE_blender.h
@@ -50,7 +50,7 @@ extern "C" {
 
 /* used by packaging tools */
 /* can be left blank, otherwise a,b,c... etc with no quotes */
-#define BLENDER_VERSION_CHAR   
+#define BLENDER_VERSION_CHAR   a
 /* alpha/beta/rc/release, docs use this */
 #define BLENDER_VERSION_CYCLE   release
 
diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c
index a7311d5efc73bb0a77ed6eea4bd2c0b02150d11c..05ffd4a626571ea3abf1cac5ad0a0d479b05bf6c 100644
--- a/source/blender/blenkernel/intern/cloth.c
+++ b/source/blender/blenkernel/intern/cloth.c
@@ -476,7 +476,6 @@ void clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob, Derived
 		BKE_ptcache_validate(cache, 0);
 		cache->last_exact= 0;
 		cache->flag &= ~PTCACHE_REDO_NEEDED;
-		return;
 	}
 	
 	// unused in the moment, calculated separately in implicit.c
diff --git a/source/blender/blenkernel/intern/sequencer.c b/source/blender/blenkernel/intern/sequencer.c
index e81afc7efb61d979f650d673a571eef455813310..b080cfcff2f63bdeb2d61f61e044bb303a62ed01 100644
--- a/source/blender/blenkernel/intern/sequencer.c
+++ b/source/blender/blenkernel/intern/sequencer.c
@@ -179,8 +179,10 @@ static void BKE_sequence_free_ex(Scene *scene, Sequence *seq, const int do_cache
 	if (seq->strip)
 		seq_free_strip(seq->strip);
 
-	if (seq->anim)
+	if (seq->anim) {
 		IMB_free_anim(seq->anim);
+		seq->anim = NULL;
+	}
 
 	if (seq->type & SEQ_TYPE_EFFECT) {
 		struct SeqEffectHandle sh = BKE_sequence_get_effect(seq);
diff --git a/source/blender/compositor/intern/COM_SocketReader.h b/source/blender/compositor/intern/COM_SocketReader.h
index 88b018ef8ba53688c593977e591680886f82f3e5..b7aae8b92f0b8bace1d9e3a4befc13d1fbecb15f 100644
--- a/source/blender/compositor/intern/COM_SocketReader.h
+++ b/source/blender/compositor/intern/COM_SocketReader.h
@@ -91,13 +91,13 @@ protected:
 	virtual void executePixel(float output[4], float x, float y, float dx, float dy, PixelSampler sampler) {}
 
 public:
-	inline void read(float *result, float x, float y, PixelSampler sampler) {
+	inline void read(float result[4], float x, float y, PixelSampler sampler) {
 		executePixel(result, x, y, sampler);
 	}
-	inline void read(float *result, int x, int y, void *chunkData) {
+	inline void read(float result[4], int x, int y, void *chunkData) {
 		executePixel(result, x, y, chunkData);
 	}
-	inline void read(float *result, float x, float y, float dx, float dy, PixelSampler sampler) {
+	inline void read(float result[4], float x, float y, float dx, float dy, PixelSampler sampler) {
 		executePixel(result, x, y, dx, dy, sampler);
 	}
 
diff --git a/source/blender/compositor/intern/COM_WorkScheduler.cpp b/source/blender/compositor/intern/COM_WorkScheduler.cpp
index e0ac767b6287e1201579f351f8db597a3bb198e0..1bac06fc4ab25b14e9cc048128c4e00921cd1540 100644
--- a/source/blender/compositor/intern/COM_WorkScheduler.cpp
+++ b/source/blender/compositor/intern/COM_WorkScheduler.cpp
@@ -81,6 +81,7 @@ int g_highlightIndex;
 void **g_highlightedNodes;
 void **g_highlightedNodesRead;
 
+#if COM_CURRENT_THREADING_MODEL == COM_TM_QUEUE
 #define HIGHLIGHT(wp) \
 { \
 	ExecutionGroup *group = wp->getExecutionGroup(); \
@@ -103,6 +104,7 @@ void **g_highlightedNodesRead;
 		} \
 	} \
 }
+#endif  /* COM_CURRENT_THREADING_MODEL == COM_TM_QUEUE */
 
 void COM_startReadHighlights()
 {
diff --git a/source/blender/compositor/operations/COM_ConvertColorToBWOperation.cpp b/source/blender/compositor/operations/COM_ConvertColorToBWOperation.cpp
index 9cff5e8eaa655fbdea3e3f656d44e207baa70bcc..3b5aa8cd7555e2f04f59e164f5e16cd5e17a717a 100644
--- a/source/blender/compositor/operations/COM_ConvertColorToBWOperation.cpp
+++ b/source/blender/compositor/operations/COM_ConvertColorToBWOperation.cpp
@@ -37,7 +37,7 @@ void ConvertColorToBWOperation::initExecution()
 void ConvertColorToBWOperation::executePixel(float output[4], float x, float y, PixelSampler sampler)
 {
 	float inputColor[4];
-	this->m_inputOperation->read(&inputColor[0], x, y, sampler);
+	this->m_inputOperation->read(inputColor, x, y, sampler);
 	output[0] = rgb_to_bw(inputColor);
 }
 
diff --git a/source/blender/compositor/operations/COM_ConvertColorToValueProg.cpp b/source/blender/compositor/operations/COM_ConvertColorToValueProg.cpp
index 3a65519864a18a2f126076fffe6a3014920845a6..44e751d1cae25fa4d7d33f72258c8ce04a7c88ca 100644
--- a/source/blender/compositor/operations/COM_ConvertColorToValueProg.cpp
+++ b/source/blender/compositor/operations/COM_ConvertColorToValueProg.cpp
@@ -37,7 +37,7 @@ void ConvertColorToValueProg::initExecution()
 void ConvertColorToValueProg::executePixel(float output[4], float x, float y, PixelSampler sampler)
 {
 	float inputColor[4];
-	this->m_inputOperation->read(&inputColor[0], x, y, sampler);
+	this->m_inputOperation->read(inputColor, x, y, sampler);
 	output[0] = (inputColor[0] + inputColor[1] + inputColor[2]) / 3.0f;
 }
 
diff --git a/source/blender/compositor/operations/COM_MathBaseOperation.cpp b/source/blender/compositor/operations/COM_MathBaseOperation.cpp
index 3749bcf42d8dabbafa7f5e5464efef7bc3299f0c..fa0c480eb700723c5fa8412dd250da8416d27d32 100644
--- a/source/blender/compositor/operations/COM_MathBaseOperation.cpp
+++ b/source/blender/compositor/operations/COM_MathBaseOperation.cpp
@@ -77,8 +77,8 @@ void MathAddOperation::executePixel(float output[4], float x, float y, PixelSamp
 	float inputValue1[4];
 	float inputValue2[4];
 	
-	this->m_inputValue1Operation->read(&inputValue1[0], x, y, sampler);
-	this->m_inputValue2Operation->read(&inputValue2[0], x, y, sampler);
+	this->m_inputValue1Operation->read(inputValue1, x, y, sampler);
+	this->m_inputValue2Operation->read(inputValue2, x, y, sampler);
 	
 	output[0] = inputValue1[0] + inputValue2[0];
 
@@ -90,8 +90,8 @@ void MathSubtractOperation::executePixel(float output[4], float x, float y, Pixe
 	float inputValue1[4];
 	float inputValue2[4];
 	
-	this->m_inputValue1Operation->read(&inputValue1[0], x, y, sampler);
-	this->m_inputValue2Operation->read(&inputValue2[0], x, y, sampler);
+	this->m_inputValue1Operation->read(inputValue1, x, y, sampler);
+	this->m_inputValue2Operation->read(inputValue2, x, y, sampler);
 	
 	output[0] = inputValue1[0] - inputValue2[0];
 
@@ -103,8 +103,8 @@ void MathMultiplyOperation::executePixel(float output[4], float x, float y, Pixe
 	float inputValue1[4];
 	float inputValue2[4];
 	
-	this->m_inputValue1Operation->read(&inputValue1[0], x, y, sampler);
-	this->m_inputValue2Operation->read(&inputValue2[0], x, y, sampler);
+	this->m_inputValue1Operation->read(inputValue1, x, y, sampler);
+	this->m_inputValue2Operation->read(inputValue2, x, y, sampler);
 	
 	output[0] = inputValue1[0] * inputValue2[0];
 
@@ -116,8 +116,8 @@ void MathDivideOperation::executePixel(float output[4], float x, float y, PixelS
 	float inputValue1[4];
 	float inputValue2[4];
 	
-	this->m_inputValue1Operation->read(&inputValue1[0], x, y, sampler);
-	this->m_inputValue2Operation->read(&inputValue2[0], x, y, sampler);
+	this->m_inputValue1Operation->read(inputValue1, x, y, sampler);
+	this->m_inputValue2Operation->read(inputValue2, x, y, sampler);
 	
 	if (inputValue2[0] == 0) /* We don't want to divide by zero. */
 		output[0] = 0.0;
@@ -132,8 +132,8 @@ void MathSineOperation::executePixel(float output[4], float x, float y, PixelSam
 	float inputValue1[4];
 	float inputValue2[4];
 	
-	this->m_inputValue1Operation->read(&inputValue1[0], x, y, sampler);
-	this->m_inputValue2Operation->read(&inputValue2[0], x, y, sampler);
+	this->m_inputValue1Operation->read(inputValue1, x, y, sampler);
+	this->m_inputValue2Operation->read(inputValue2, x, y, sampler);
 	
 	output[0] = sin(inputValue1[0]);
 
@@ -145,8 +145,8 @@ void MathCosineOperation::executePixel(float output[4], float x, float y, PixelS
 	float inputValue1[4];
 	float inputValue2[4];
 	
-	this->m_inputValue1Operation->read(&inputValue1[0], x, y, sampler);
-	this->m_inputValue2Operation->read(&inputValue2[0], x, y, sampler);
+	this->m_inputValue1Operation->read(inputValue1, x, y, sampler);
+	this->m_inputValue2Operation->read(inputValue2, x, y, sampler);
 	
 	output[0] = cos(inputValue1[0]);
 
@@ -158,8 +158,8 @@ void MathTangentOperation::executePixel(float output[4], float x, float y, Pixel
 	float inputValue1[4];
 	float inputValue2[4];
 	
-	this->m_inputValue1Operation->read(&inputValue1[0], x, y, sampler);
-	this->m_inputValue2Operation->read(&inputValue2[0], x, y, sampler);
+	this->m_inputValue1Operation->read(inputValue1, x, y, sampler);
+	this->m_inputValue2Operation->read(inputValue2, x, y, sampler);
 	
 	output[0] = tan(inputValue1[0]);
 
@@ -171,8 +171,8 @@ void MathArcSineOperation::executePixel(float output[4], float x, float y, Pixel
 	float inputValue1[4];
 	float inputValue2[4];
 	
-	this->m_inputValue1Operation->read(&inputValue1[0], x, y, sampler);
-	this->m_inputValue2Operation->read(&inputValue2[0], x, y, sampler);
+	this->m_inputValue1Operation->read(inputValue1, x, y, sampler);
+	this->m_inputValue2Operation->read(inputValue2, x, y, sampler);
 	
 	if (inputValue1[0] <= 1 && inputValue1[0] >= -1)
 		output[0] = asin(inputValue1[0]);
@@ -187,8 +187,8 @@ void MathArcCosineOperation::executePixel(float output[4], float x, float y, Pix
 	float inputValue1[4];
 	float inputValue2[4];
 	
-	this->m_inputValue1Operation->read(&inputValue1[0], x, y, sampler);
-	this->m_inputValue2Operation->read(&inputValue2[0], x, y, sampler);
+	this->m_inputValue1Operation->read(inputValue1, x, y, sampler);
+	this->m_inputValue2Operation->read(inputValue2, x, y, sampler);
 	
 	if (inputValue1[0] <= 1 && inputValue1[0] >= -1)
 		output[0] = acos(inputValue1[0]);
@@ -203,8 +203,8 @@ void MathArcTangentOperation::executePixel(float output[4], float x, float y, Pi
 	float inputValue1[4];
 	float inputValue2[4];
 	
-	this->m_inputValue1Operation->read(&inputValue1[0], x, y, sampler);
-	this->m_inputValue2Operation->read(&inputValue2[0], x, y, sampler);
+	this->m_inputValue1Operation->read(inputValue1, x, y, sampler);
+	this->m_inputValue2Operation->read(inputValue2, x, y, sampler);
 	
 	output[0] = atan(inputValue1[0]);
 
@@ -216,8 +216,8 @@ void MathPowerOperation::executePixel(float output[4], float x, float y, PixelSa
 	float inputValue1[4];
 	float inputValue2[4];
 	
-	this->m_inputValue1Operation->read(&inputValue1[0], x, y, sampler);
-	this->m_inputValue2Operation->read(&inputValue2[0], x, y, sampler);
+	this->m_inputValue1Operation->read(inputValue1, x, y, sampler);
+	this->m_inputValue2Operation->read(inputValue2, x, y, sampler);
 	
 	if (inputValue1[0] >= 0) {
 		output[0] = pow(inputValue1[0], inputValue2[0]);
@@ -241,8 +241,8 @@ void MathLogarithmOperation::executePixel(float output[4], float x, float y, Pix
 	float inputValue1[4];
 	float inputValue2[4];
 	
-	this->m_inputValue1Operation->read(&inputValue1[0], x, y, sampler);
-	this->m_inputValue2Operation->read(&inputValue2[0], x, y, sampler);
+	this->m_inputValue1Operation->read(inputValue1, x, y, sampler);
+	this->m_inputValue2Operation->read(inputValue2, x, y, sampler);
 	
 	if (inputValue1[0] > 0  && inputValue2[0] > 0)
 		output[0] = log(inputValue1[0]) / log(inputValue2[0]);
@@ -257,8 +257,8 @@ void MathMinimumOperation::executePixel(float output[4], float x, float y, Pixel
 	float inputValue1[4];
 	float inputValue2[4];
 	
-	this->m_inputValue1Operation->read(&inputValue1[0], x, y, sampler);
-	this->m_inputValue2Operation->read(&inputValue2[0], x, y, sampler);
+	this->m_inputValue1Operation->read(inputValue1, x, y, sampler);
+	this->m_inputValue2Operation->read(inputValue2, x, y, sampler);
 	
 	output[0] = min(inputValue1[0], inputValue2[0]);
 
@@ -270,8 +270,8 @@ void MathMaximumOperation::executePixel(float output[4], float x, float y, Pixel
 	float inputValue1[4];
 	float inputValue2[4];
 	
-	this->m_inputValue1Operation->read(&inputValue1[0], x, y, sampler);
-	this->m_inputValue2Operation->read(&inputValue2[0], x, y, sampler);
+	this->m_inputValue1Operation->read(inputValue1, x, y, sampler);
+	this->m_inputValue2Operation->read(inputValue2, x, y, sampler);
 	
 	output[0] = max(inputValue1[0], inputValue2[0]);
 
@@ -283,8 +283,8 @@ void MathRoundOperation::executePixel(float output[4], float x, float y, PixelSa
 	float inputValue1[4];
 	float inputValue2[4];
 	
-	this->m_inputValue1Operation->read(&inputValue1[0], x, y, sampler);
-	this->m_inputValue2Operation->read(&inputValue2[0], x, y, sampler);
+	this->m_inputValue1Operation->read(inputValue1, x, y, sampler);
+	this->m_inputValue2Operation->read(inputValue2, x, y, sampler);
 	
 	output[0] = round(inputValue1[0]);
 
@@ -296,8 +296,8 @@ void MathLessThanOperation::executePixel(float output[4], float x, float y, Pixe
 	float inputValue1[4];
 	float inputValue2[4];
 	
-	this->m_inputValue1Operation->read(&inputValue1[0], x, y, sampler);
-	this->m_inputValue2Operation->read(&inputValue2[0], x, y, sampler);
+	this->m_inputValue1Operation->read(inputValue1, x, y, sampler);
+	this->m_inputValue2Operation->read(inputValue2, x, y, sampler);
 	
 	output[0] = inputValue1[0] < inputValue2[0] ? 1.0f : 0.0f;
 
@@ -309,8 +309,8 @@ void MathGreaterThanOperation::executePixel(float output[4], float x, float y, P
 	float inputValue1[4];
 	float inputValue2[4];
 	
-	this->m_inputValue1Operation->read(&inputValue1[0], x, y, sampler);
-	this->m_inputValue2Operation->read(&inputValue2[0], x, y, sampler);
+	this->m_inputValue1Operation->read(inputValue1, x, y, sampler);
+	this->m_inputValue2Operation->read(inputValue2, x, y, sampler);
 	
 	output[0] = inputValue1[0] > inputValue2[0] ? 1.0f : 0.0f;
 
@@ -322,8 +322,8 @@ void MathModuloOperation::executePixel(float output[4], float x, float y, PixelS
 	float inputValue1[4];
 	float inputValue2[4];
 	
-	this->m_inputValue1Operation->read(&inputValue1[0], x, y, sampler);
-	this->m_inputValue2Operation->read(&inputValue2[0], x, y, sampler);
+	this->m_inputValue1Operation->read(inputValue1, x, y, sampler);
+	this->m_inputValue2Operation->read(inputValue2, x, y, sampler);
 	
 	if (inputValue2[0] == 0)
 		output[0] = 0.0;
diff --git a/source/blender/compositor/operations/COM_MixAddOperation.cpp b/source/blender/compositor/operations/COM_MixAddOperation.cpp
index be737f222809a1f38fa23486d3a8924e92426399..4e0876439c09a179da71f0cd2ed4e673a3fea995 100644
--- a/source/blender/compositor/operations/COM_MixAddOperation.cpp
+++ b/source/blender/compositor/operations/COM_MixAddOperation.cpp
@@ -37,7 +37,6 @@ void MixAddOperation::executePixel(float output[4], float x, float y, PixelSampl
 	this->m_inputColor1Operation->read(inputColor1, x, y, sampler);
 	this->m_inputColor2Operation->read(inputColor2, x, y, sampler);
 
-
 	float value = inputValue[0];
 	if (this->useValueAlphaMultiply()) {
 		value *= inputColor2[3];
diff --git a/source/blender/compositor/operations/COM_MixBurnOperation.cpp b/source/blender/compositor/operations/COM_MixBurnOperation.cpp
index 5cfe38766bcf45eae464e1f12de7adfccf829503..d4422c6cc6aa070792b641699ba11cea5f85ac1c 100644
--- a/source/blender/compositor/operations/COM_MixBurnOperation.cpp
+++ b/source/blender/compositor/operations/COM_MixBurnOperation.cpp
@@ -31,13 +31,14 @@ void MixBurnOperation::executePixel(float output[4], float x, float y, PixelSamp
 {
 	float inputColor1[4];
 	float inputColor2[4];
-	float value;
+	float inputValue[4];
 	float tmp;
 	
-	this->m_inputValueOperation->read(&value, x, y, sampler);
-	this->m_inputColor1Operation->read(&inputColor1[0], x, y, sampler);
-	this->m_inputColor2Operation->read(&inputColor2[0], x, y, sampler);
+	this->m_inputValueOperation->read(inputValue, x, y, sampler);
+	this->m_inputColor1Operation->read(inputColor1, x, y, sampler);
+	this->m_inputColor2Operation->read(inputColor2, x, y, sampler);
 	
+	float value = inputValue[0];
 	if (this->useValueAlphaMultiply()) {
 		value *= inputColor2[3];
 	}
diff --git a/source/blender/compositor/operations/COM_MixColorOperation.cpp b/source/blender/compositor/operations/COM_MixColorOperation.cpp
index 56aca27eaef0d75596b1b83436991f1ecbea0e8b..6919a636aeb40713aa424ec979f82ecc35564be5 100644
--- a/source/blender/compositor/operations/COM_MixColorOperation.cpp
+++ b/source/blender/compositor/operations/COM_MixColorOperation.cpp
@@ -35,12 +35,13 @@ void MixColorOperation::executePixel(float output[4], float x, float y, PixelSam
 {
 	float inputColor1[4];
 	float inputColor2[4];
-	float value;
+	float inputValue[4];
 
-	this->m_inputValueOperation->read(&value, x, y, sampler);
-	this->m_inputColor1Operation->read(&inputColor1[0], x, y, sampler);
-	this->m_inputColor2Operation->read(&inputColor2[0], x, y, sampler);
+	this->m_inputValueOperation->read(inputValue, x, y, sampler);
+	this->m_inputColor1Operation->read(inputColor1, x, y, sampler);
+	this->m_inputColor2Operation->read(inputColor2, x, y, sampler);
 
+	float value = inputValue[0];
 	if (this->useValueAlphaMultiply()) {
 		value *= inputColor2[3];
 	}
diff --git a/source/blender/compositor/operations/COM_MixDarkenOperation.cpp b/source/blender/compositor/operations/COM_MixDarkenOperation.cpp
index 5b79f4c95ac7d5e16d35089a8b7445a73311fa9b..d56d9fdf122a7b88dfae90621210298755d7cff9 100644
--- a/source/blender/compositor/operations/COM_MixDarkenOperation.cpp
+++ b/source/blender/compositor/operations/COM_MixDarkenOperation.cpp
@@ -31,12 +31,13 @@ void MixDarkenOperation::executePixel(float output[4], float x, float y, PixelSa
 {
 	float inputColor1[4];
 	float inputColor2[4];
-	float value;
+	float inputValue[4];
 	
-	this->m_inputValueOperation->read(&value, x, y, sampler);
-	this->m_inputColor1Operation->read(&inputColor1[0], x, y, sampler);
-	this->m_inputColor2Operation->read(&inputColor2[0], x, y, sampler);
+	this->m_inputValueOperation->read(inputValue, x, y, sampler);
+	this->m_inputColor1Operation->read(inputColor1, x, y, sampler);
+	this->m_inputColor2Operation->read(inputColor2, x, y, sampler);
 	
+	float value = inputValue[0];
 	if (this->useValueAlphaMultiply()) {
 		value *= inputColor2[3];
 	}
diff --git a/source/blender/compositor/operations/COM_MixDifferenceOperation.cpp b/source/blender/compositor/operations/COM_MixDifferenceOperation.cpp
index d2c1e5e428fb66b07c15c65f1748e6bca469b335..13494401c60158c189ea11c0a5531140a78bf5ff 100644
--- a/source/blender/compositor/operations/COM_MixDifferenceOperation.cpp
+++ b/source/blender/compositor/operations/COM_MixDifferenceOperation.cpp
@@ -32,12 +32,13 @@ void MixDifferenceOperation::executePixel(float output[4], float x, float y, Pix
 {
 	float inputColor1[4];
 	float inputColor2[4];
-	float value;
-	
-	this->m_inputValueOperation->read(&value, x, y, sampler);
-	this->m_inputColor1Operation->read(&inputColor1[0], x, y, sampler);
-	this->m_inputColor2Operation->read(&inputColor2[0], x, y, sampler);
+	float inputValue[4];
 	
+	this->m_inputValueOperation->read(inputValue, x, y, sampler);
+	this->m_inputColor1Operation->read(inputColor1, x, y, sampler);
+	this->m_inputColor2Operation->read(inputColor2, x, y, sampler);
+
+	float value = inputValue[0];
 	if (this->useValueAlphaMultiply()) {
 		value *= inputColor2[3];
 	}
diff --git a/source/blender/compositor/operations/COM_MixDivideOperation.cpp b/source/blender/compositor/operations/COM_MixDivideOperation.cpp
index fdb1618b6e62457de2a5a7f2fe161a00c9a74883..3e0eb66565cb4655bce45555ef40adf69f0858dc 100644
--- a/source/blender/compositor/operations/COM_MixDivideOperation.cpp
+++ b/source/blender/compositor/operations/COM_MixDivideOperation.cpp
@@ -31,12 +31,13 @@ void MixDivideOperation::executePixel(float output[4], float x, float y, PixelSa
 {
 	float inputColor1[4];
 	float inputColor2[4];
-	float value;
-	
-	this->m_inputValueOperation->read(&value, x, y, sampler);
-	this->m_inputColor1Operation->read(&inputColor1[0], x, y, sampler);
-	this->m_inputColor2Operation->read(&inputColor2[0], x, y, sampler);
+	float inputValue[4];
 	
+	this->m_inputValueOperation->read(inputValue, x, y, sampler);
+	this->m_inputColor1Operation->read(inputColor1, x, y, sampler);
+	this->m_inputColor2Operation->read(inputColor2, x, y, sampler);
+
+	float value = inputValue[0];
 	if (this->useValueAlphaMultiply()) {
 		value *= inputColor2[3];
 	}
diff --git a/source/blender/compositor/operations/COM_MixDodgeOperation.cpp b/source/blender/compositor/operations/COM_MixDodgeOperation.cpp
index 87f60df8e1b71102eaca9e6bab6882280924de43..acb39f665ff803c8b0161c02dd3c3529f5c4bd74 100644
--- a/source/blender/compositor/operations/COM_MixDodgeOperation.cpp
+++ b/source/blender/compositor/operations/COM_MixDodgeOperation.cpp
@@ -31,13 +31,14 @@ void MixDodgeOperation::executePixel(float output[4], float x, float y, PixelSam
 {
 	float inputColor1[4];
 	float inputColor2[4];
-	float value;
+	float inputValue[4];
 	float tmp;
 
-	this->m_inputValueOperation->read(&value, x, y, sampler);
-	this->m_inputColor1Operation->read(&inputColor1[0], x, y, sampler);
-	this->m_inputColor2Operation->read(&inputColor2[0], x, y, sampler);
+	this->m_inputValueOperation->read(inputValue, x, y, sampler);
+	this->m_inputColor1Operation->read(inputColor1, x, y, sampler);
+	this->m_inputColor2Operation->read(inputColor2, x, y, sampler);
 
+	float value = inputValue[0];
 	if (this->useValueAlphaMultiply()) {
 		value *= inputColor2[3];
 	}
diff --git a/source/blender/compositor/operations/COM_MixHueOperation.cpp b/source/blender/compositor/operations/COM_MixHueOperation.cpp
index 12cd16bb73b419a01303b9695968dbb1f73c6895..64c88592b93653a209f3614853187a06ce457410 100644
--- a/source/blender/compositor/operations/COM_MixHueOperation.cpp
+++ b/source/blender/compositor/operations/COM_MixHueOperation.cpp
@@ -35,12 +35,13 @@ void MixHueOperation::executePixel(float output[4], float x, float y, PixelSampl
 {
 	float inputColor1[4];
 	float inputColor2[4];
-	float value;
+	float inputValue[4];
 
-	this->m_inputValueOperation->read(&value, x, y, sampler);
-	this->m_inputColor1Operation->read(&inputColor1[0], x, y, sampler);
-	this->m_inputColor2Operation->read(&inputColor2[0], x, y, sampler);
+	this->m_inputValueOperation->read(inputValue, x, y, sampler);
+	this->m_inputColor1Operation->read(inputColor1, x, y, sampler);
+	this->m_inputColor2Operation->read(inputColor2, x, y, sampler);
 
+	float value = inputValue[0];
 	if (this->useValueAlphaMultiply()) {
 		value *= inputColor2[3];
 	}
diff --git a/source/blender/compositor/operations/COM_MixLightenOperation.cpp b/source/blender/compositor/operations/COM_MixLightenOperation.cpp
index 9eb45a783f807489decf102ba1850b2701472ce8..a468fb39442b4608e31ccf26f16db368002cfd00 100644
--- a/source/blender/compositor/operations/COM_MixLightenOperation.cpp
+++ b/source/blender/compositor/operations/COM_MixLightenOperation.cpp
@@ -31,12 +31,13 @@ void MixLightenOperation::executePixel(float output[4], float x, float y, PixelS
 {
 	float inputColor1[4];
 	float inputColor2[4];
-	float value;
-	
-	this->m_inputValueOperation->read(&value, x, y, sampler);
-	this->m_inputColor1Operation->read(&inputColor1[0], x, y, sampler);
-	this->m_inputColor2Operation->read(&inputColor2[0], x, y, sampler);
+	float inputValue[4];
 	
+	this->m_inputValueOperation->read(inputValue, x, y, sampler);
+	this->m_inputColor1Operation->read(inputColor1, x, y, sampler);
+	this->m_inputColor2Operation->read(inputColor2, x, y, sampler);
+
+	float value = inputValue[0];
 	if (this->useValueAlphaMultiply()) {
 		value *= inputColor2[3];
 	}
diff --git a/source/blender/compositor/operations/COM_MixLinearLightOperation.cpp b/source/blender/compositor/operations/COM_MixLinearLightOperation.cpp
index ee7dcc9fe2846d4fd9ba353c0a485fa8da64a157..e1b5e040f0ffc21560e9a42f82a27052f6aca406 100644
--- a/source/blender/compositor/operations/COM_MixLinearLightOperation.cpp
+++ b/source/blender/compositor/operations/COM_MixLinearLightOperation.cpp
@@ -31,12 +31,13 @@ void MixLinearLightOperation::executePixel(float output[4], float x, float y, Pi
 {
 	float inputColor1[4];
 	float inputColor2[4];
-	float value;
-	
-	this->m_inputValueOperation->read(&value, x, y, sampler);
-	this->m_inputColor1Operation->read(&inputColor1[0], x, y, sampler);
-	this->m_inputColor2Operation->read(&inputColor2[0], x, y, sampler);
-	
+	float inputValue[4];
+
+	this->m_inputValueOperation->read(inputValue, x, y, sampler);
+	this->m_inputColor1Operation->read(inputColor1, x, y, sampler);
+	this->m_inputColor2Operation->read(inputColor2, x, y, sampler);
+
+	float value = inputValue[0];
 	if (this->useValueAlphaMultiply()) {
 		value *= inputColor2[3];
 	}
diff --git a/source/blender/compositor/operations/COM_MixOverlayOperation.cpp b/source/blender/compositor/operations/COM_MixOverlayOperation.cpp
index 09a9d3cbc4f4348e91cbeb47d185f4fe5141eb68..d5e1c6d11679f0961d36a08a2249d6741fda09f0 100644
--- a/source/blender/compositor/operations/COM_MixOverlayOperation.cpp
+++ b/source/blender/compositor/operations/COM_MixOverlayOperation.cpp
@@ -31,12 +31,13 @@ void MixOverlayOperation::executePixel(float output[4], float x, float y, PixelS
 {
 	float inputColor1[4];
 	float inputColor2[4];
-	float value;
+	float inputValue[4];
 	
-	this->m_inputValueOperation->read(&value, x, y, sampler);
-	this->m_inputColor1Operation->read(&inputColor1[0], x, y, sampler);
-	this->m_inputColor2Operation->read(&inputColor2[0], x, y, sampler);
+	this->m_inputValueOperation->read(inputValue, x, y, sampler);
+	this->m_inputColor1Operation->read(inputColor1, x, y, sampler);
+	this->m_inputColor2Operation->read(inputColor2, x, y, sampler);
 	
+	float value = inputValue[0];
 	if (this->useValueAlphaMultiply()) {
 		value *= inputColor2[3];
 	}
diff --git a/source/blender/compositor/operations/COM_MixSaturationOperation.cpp b/source/blender/compositor/operations/COM_MixSaturationOperation.cpp
index 3ab19748458e07bccf14422135ad34d391d77023..ca45a1c703a81cc127a7851fbe8b54d937d4a7a2 100644
--- a/source/blender/compositor/operations/COM_MixSaturationOperation.cpp
+++ b/source/blender/compositor/operations/COM_MixSaturationOperation.cpp
@@ -35,12 +35,13 @@ void MixSaturationOperation::executePixel(float output[4], float x, float y, Pix
 {
 	float inputColor1[4];
 	float inputColor2[4];
-	float value;
+	float inputValue[4];
 
-	this->m_inputValueOperation->read(&value, x, y, sampler);
-	this->m_inputColor1Operation->read(&inputColor1[0], x, y, sampler);
-	this->m_inputColor2Operation->read(&inputColor2[0], x, y, sampler);
+	this->m_inputValueOperation->read(inputValue, x, y, sampler);
+	this->m_inputColor1Operation->read(inputColor1, x, y, sampler);
+	this->m_inputColor2Operation->read(inputColor2, x, y, sampler);
 
+	float value = inputValue[0];
 	if (this->useValueAlphaMultiply()) {
 		value *= inputColor2[3];
 	}
diff --git a/source/blender/compositor/operations/COM_MixScreenOperation.cpp b/source/blender/compositor/operations/COM_MixScreenOperation.cpp
index 671ffd3303cae66463410ef3e921afdd82fca556..511768a49adf44e798a7e179744e3b0e83664a58 100644
--- a/source/blender/compositor/operations/COM_MixScreenOperation.cpp
+++ b/source/blender/compositor/operations/COM_MixScreenOperation.cpp
@@ -31,13 +31,13 @@ void MixScreenOperation::executePixel(float output[4], float x, float y, PixelSa
 {
 	float inputColor1[4];
 	float inputColor2[4];
-	float valuev[4];
+	float inputValue[4];
 
-	this->m_inputValueOperation->read(valuev, x, y, sampler);
-	this->m_inputColor1Operation->read(&inputColor1[0], x, y, sampler);
-	this->m_inputColor2Operation->read(&inputColor2[0], x, y, sampler);
+	this->m_inputValueOperation->read(inputValue, x, y, sampler);
+	this->m_inputColor1Operation->read(inputColor1, x, y, sampler);
+	this->m_inputColor2Operation->read(inputColor2, x, y, sampler);
 
-	float value = valuev[0];
+	float value = inputValue[0];
 	if (this->useValueAlphaMultiply()) {
 		value *= inputColor2[3];
 	}
diff --git a/source/blender/compositor/operations/COM_MixSoftLightOperation.cpp b/source/blender/compositor/operations/COM_MixSoftLightOperation.cpp
index 604881ae47fd354784d0da00cdc8612da85c0c6d..71d83ce54ea1709982f6c315beda4e2662693716 100644
--- a/source/blender/compositor/operations/COM_MixSoftLightOperation.cpp
+++ b/source/blender/compositor/operations/COM_MixSoftLightOperation.cpp
@@ -31,12 +31,13 @@ void MixSoftLightOperation::executePixel(float output[4], float x, float y, Pixe
 {
 	float inputColor1[4];
 	float inputColor2[4];
-	float value;
+	float inputValue[4];
 	
-	this->m_inputValueOperation->read(&value, x, y, sampler);
-	this->m_inputColor1Operation->read(&inputColor1[0], x, y, sampler);
-	this->m_inputColor2Operation->read(&inputColor2[0], x, y, sampler);
+	this->m_inputValueOperation->read(inputValue, x, y, sampler);
+	this->m_inputColor1Operation->read(inputColor1, x, y, sampler);
+	this->m_inputColor2Operation->read(inputColor2, x, y, sampler);
 	
+	float value = inputValue[0];
 	if (this->useValueAlphaMultiply()) {
 		value *= inputColor2[3];
 	}
diff --git a/source/blender/compositor/operations/COM_MixSubtractOperation.cpp b/source/blender/compositor/operations/COM_MixSubtractOperation.cpp
index a446dfe4e542d4785998c10420862a2cc38ad0e5..e6efe0f62f3d014d283046cbfaf3a73ede376051 100644
--- a/source/blender/compositor/operations/COM_MixSubtractOperation.cpp
+++ b/source/blender/compositor/operations/COM_MixSubtractOperation.cpp
@@ -31,12 +31,13 @@ void MixSubtractOperation::executePixel(float output[4], float x, float y, Pixel
 {
 	float inputColor1[4];
 	float inputColor2[4];
-	float value;
+	float inputValue[4];
 	
-	this->m_inputValueOperation->read(&value,   x, y, sampler);
-	this->m_inputColor1Operation->read(&inputColor1[0],   x, y, sampler);
-	this->m_inputColor2Operation->read(&inputColor2[0],   x, y, sampler);
+	this->m_inputValueOperation->read(inputValue,   x, y, sampler);
+	this->m_inputColor1Operation->read(inputColor1,   x, y, sampler);
+	this->m_inputColor2Operation->read(inputColor2,   x, y, sampler);
 	
+	float value = inputValue[0];
 	if (this->useValueAlphaMultiply()) {
 		value *= inputColor2[3];
 	}
diff --git a/source/blender/compositor/operations/COM_MixValueOperation.cpp b/source/blender/compositor/operations/COM_MixValueOperation.cpp
index caefdf024ccdf979d3b585fc864c7a255a125a5f..553041e39bf53d88903827a1447cb24890315bcf 100644
--- a/source/blender/compositor/operations/COM_MixValueOperation.cpp
+++ b/source/blender/compositor/operations/COM_MixValueOperation.cpp
@@ -35,12 +35,13 @@ void MixValueOperation::executePixel(float output[4], float x, float y, PixelSam
 {
 	float inputColor1[4];
 	float inputColor2[4];
-	float value;
+	float inputValue[4];
 
-	this->m_inputValueOperation->read(&value, x, y, sampler);
-	this->m_inputColor1Operation->read(&inputColor1[0], x, y, sampler);
-	this->m_inputColor2Operation->read(&inputColor2[0], x, y, sampler);
+	this->m_inputValueOperation->read(inputValue, x, y, sampler);
+	this->m_inputColor1Operation->read(inputColor1, x, y, sampler);
+	this->m_inputColor2Operation->read(inputColor2, x, y, sampler);
 
+	float value = inputValue[0];
 	if (this->useValueAlphaMultiply()) {
 		value *= inputColor2[3];
 	}
diff --git a/source/blender/editors/mesh/mesh_data.c b/source/blender/editors/mesh/mesh_data.c
index b825de58678f84f7bbf1e59a06b63cf5dca4b589..4cbb5f303f0d7c009ed786f09443d4472f0fcc3c 100644
--- a/source/blender/editors/mesh/mesh_data.c
+++ b/source/blender/editors/mesh/mesh_data.c
@@ -138,7 +138,7 @@ static void delete_customdata_layer(Mesh *me, CustomDataLayer *layer)
 		BM_data_layer_free_n(me->edit_btmesh->bm, data, type, n);
 	}
 	else {
-		CustomData_free_layer(data, type, tot, n);
+		CustomData_free_layer(data, type, tot, layer_index + n);
 		BKE_mesh_update_customdata_pointers(me, true);
 	}
 }
diff --git a/source/blender/editors/render/render_opengl.c b/source/blender/editors/render/render_opengl.c
index 93ae913cee0481f11fa53c279a96c86695ec60af..6b55518552ae7837ad068fb14691e220fb55571b 100644
--- a/source/blender/editors/render/render_opengl.c
+++ b/source/blender/editors/render/render_opengl.c
@@ -728,6 +728,9 @@ static int screen_opengl_render_invoke(bContext *C, wmOperator *op, const wmEven
 	oglrender = op->customdata;
 	render_view_open(C, event->x, event->y);
 	
+	/* view may be changed above (R_OUTPUT_WINDOW) */
+	oglrender->win = CTX_wm_window(C);
+
 	WM_event_add_modal_handler(C, op);
 	oglrender->timer = WM_event_add_timer(oglrender->wm, oglrender->win, TIMER, 0.01f);
 	
diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c
index 017232d18569421674f76839780fbd95937a3115..db55dc271f1f8d6a64d8e3a6c81b84b4d92dbfce 100644
--- a/source/blender/editors/sculpt_paint/paint_image_proj.c
+++ b/source/blender/editors/sculpt_paint/paint_image_proj.c
@@ -2816,7 +2816,11 @@ static void project_paint_begin(ProjPaintState *ps)
 
 	int a, i; /* generic looping vars */
 	int image_index = -1, face_index;
-	int *mpoly_origindex;
+
+	/* double lookup */
+	const int *index_mf_to_mpoly = NULL;
+	const int *index_mp_to_orig  = NULL;
+
 	MVert *mv;
 
 	MemArena *arena; /* at the moment this is just ps->arena_mt[0], but use this to show were not multithreading */
@@ -2871,12 +2875,17 @@ static void project_paint_begin(ProjPaintState *ps)
 	ps->dm_totface = ps->dm->getNumTessFaces(ps->dm);
 
 	if (ps->do_face_sel) {
-		mpoly_orig = ((Mesh *)ps->ob->data)->mpoly;
-		mpoly_origindex = ps->dm->getPolyDataArray(ps->dm, CD_ORIGINDEX);
+		index_mf_to_mpoly = ps->dm->getTessFaceDataArray(ps->dm, CD_ORIGINDEX);
+		index_mp_to_orig  = ps->dm->getPolyDataArray(ps->dm, CD_ORIGINDEX);
+		if (index_mf_to_mpoly == NULL) {
+			index_mp_to_orig = NULL;
+		}
+		else {
+			mpoly_orig = ((Mesh *)ps->ob->data)->mpoly;
+		}
 	}
 	else {
 		mpoly_orig = NULL;
-		mpoly_origindex = NULL;
 	}
 
 	/* use clone mtface? */
@@ -3166,8 +3175,10 @@ static void project_paint_begin(ProjPaintState *ps)
 
 		if (ps->do_face_sel) {
 			int orig_index;
-			if (mpoly_origindex && ((orig_index = mpoly_origindex[face_index])) != ORIGINDEX_NONE) {
-				MPoly *mp = mpoly_orig + orig_index;
+			if (index_mp_to_orig && ((orig_index = DM_origindex_mface_mpoly(index_mf_to_mpoly, index_mp_to_orig,
+			                                                                face_index))) != ORIGINDEX_NONE)
+			{
+				MPoly *mp = &mpoly_orig[orig_index];
 				is_face_sel = ((mp->flag & ME_FACE_SEL) != 0);
 			}
 			else {
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index c7f8161c7edb206709b439407448d9f8e6940eb2..f67cc0359a2e439446b8919ab12775d87adedc54 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -4652,13 +4652,18 @@ void sculpt_dynamic_topology_disable(bContext *C,
 		sculptsession_bm_to_me(ob, TRUE);
 	}
 
-	BM_mesh_free(ss->bm);
-
 	/* Clear data */
 	me->flag &= ~ME_SCULPT_DYNAMIC_TOPOLOGY;
-	ss->bm = NULL;
-	BM_log_free(ss->bm_log);
-	ss->bm_log = NULL;
+
+	/* typically valid but with global-undo they can be NULL, [#36234] */
+	if (ss->bm) {
+		BM_mesh_free(ss->bm);
+		ss->bm = NULL;
+	}
+	if (ss->bm_log) {
+		BM_log_free(ss->bm_log);
+		ss->bm_log = NULL;
+	}
 
 	/* Refresh */
 	sculpt_update_after_dynamic_topology_toggle(C);
diff --git a/source/blender/gpu/intern/gpu_material.c b/source/blender/gpu/intern/gpu_material.c
index 044b699a042414ceaeac559c5ee97f7f9e45267c..0ca929da65de901aff13f7383f78d5247e4983e6 100644
--- a/source/blender/gpu/intern/gpu_material.c
+++ b/source/blender/gpu/intern/gpu_material.c
@@ -742,12 +742,16 @@ static void shade_one_light(GPUShadeInput *shi, GPUShadeResult *shr, GPULamp *la
 			}
 			
 			if (lamp->mode & LA_ONLYSHADOW) {
+				GPUNodeLink *rgb;
 				GPU_link(mat, "shade_only_shadow", i, shadfac,
 					GPU_dynamic_uniform(&lamp->dynenergy, GPU_DYNAMIC_LAMP_DYNENERGY, lamp->ob), &shadfac);
+
+				GPU_link(mat, "shade_mul", shi->rgb, GPU_uniform(lamp->shadow_color), &rgb);
+				GPU_link(mat, "mtex_rgb_invert", rgb, &rgb);
 				
 				if (!(lamp->mode & LA_NO_DIFF)) {
-					GPU_link(mat, "mix_mult", shadfac, shr->diff,
-						GPU_uniform(lamp->shadow_color), &shr->diff);
+					GPU_link(mat, "shade_only_shadow_diffuse", shadfac, rgb,
+						shr->diff, &shr->diff);
 				}
 
 				if (!(lamp->mode & LA_NO_SPEC))
diff --git a/source/blender/modifiers/intern/MOD_ocean.c b/source/blender/modifiers/intern/MOD_ocean.c
index 7c9a88622ed7bf1f4f4b3fba29ff115600650825..5fdd17b5167368ea79d28894e581cfb091035947 100644
--- a/source/blender/modifiers/intern/MOD_ocean.c
+++ b/source/blender/modifiers/intern/MOD_ocean.c
@@ -426,6 +426,11 @@ static DerivedMesh *doOcean(ModifierData *md, Object *ob,
 
 	const float size_co_inv = 1.0f / (omd->size * omd->spatial_size);
 
+	/* can happen in when size is small, avoid bad array lookups later and quit now */
+	if (!finite(size_co_inv)) {
+		return derivedData;
+	}
+
 	/* update modifier */
 	if (omd->refresh & MOD_OCEAN_REFRESH_ADD)
 		omd->ocean = BKE_add_ocean();
@@ -531,7 +536,7 @@ static DerivedMesh *doOcean(ModifierData *md, Object *ob,
 		}
 	}
 
-	#undef OCEAN_CO
+#undef OCEAN_CO
 
 	return dm;
 }
@@ -552,8 +557,6 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
 {
 	DerivedMesh *result;
 
-	CDDM_calc_normals(derivedData);
-
 	result = doOcean(md, ob, derivedData, 0);
 
 	if (result != derivedData)
diff --git a/source/gameengine/Expressions/FloatValue.cpp b/source/gameengine/Expressions/FloatValue.cpp
index b7d7f52815516dc9cadc856b19790faa61939734..0f468e328edc4d5a191465943b16e71993444fa1 100644
--- a/source/gameengine/Expressions/FloatValue.cpp
+++ b/source/gameengine/Expressions/FloatValue.cpp
@@ -97,7 +97,7 @@ ret: a new object containing the result of applying operator op to this
 		return new CFloatValue (-m_float);
 		break;
 	case VALUE_NOT_OPERATOR:
-		return new CErrorValue (op2str(op) + "only allowed on booleans");
+		return new CBoolValue (m_float == 0.f);
 		break;
 	case VALUE_AND_OPERATOR:
 	case VALUE_OR_OPERATOR:
@@ -160,6 +160,9 @@ ret: a new object containing the result of applying operator op to val and
 				case VALUE_LEQ_OPERATOR:
 					ret = new CBoolValue(((CIntValue *) val)->GetInt() <= m_float);
 					break;
+				case VALUE_NOT_OPERATOR:
+					ret = new CBoolValue(m_float == 0);
+					break;
 				default:
 					ret = new CErrorValue("illegal operator. please send a bug report.");
 					break;
@@ -212,7 +215,9 @@ ret: a new object containing the result of applying operator op to val and
 				case VALUE_POS_OPERATOR:
 					ret = new CFloatValue (m_float);
 					break;
-
+				case VALUE_NOT_OPERATOR:
+					ret = new CBoolValue(m_float == 0);
+					break;
 				default:
 					ret = new CErrorValue("illegal operator. please send a bug report.");
 					break;
diff --git a/source/gameengine/Expressions/IntValue.cpp b/source/gameengine/Expressions/IntValue.cpp
index 2cacea984674b68a4b4ac088bab38a1ede751508..fa4c9ad8ac991e759639ab616707052ef9db1b88 100644
--- a/source/gameengine/Expressions/IntValue.cpp
+++ b/source/gameengine/Expressions/IntValue.cpp
@@ -96,7 +96,7 @@ object and val
 		return new CIntValue (-m_int);
 		break;
 	case VALUE_NOT_OPERATOR:
-		return new CErrorValue (op2str(op) + "only allowed on booleans");
+		return new CBoolValue (m_int == 0);
 		break;
 	case VALUE_AND_OPERATOR:
 	case VALUE_OR_OPERATOR:
@@ -170,7 +170,11 @@ CValue* CIntValue::CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *v
 				case VALUE_POS_OPERATOR:
 					ret = new CIntValue (m_int);
 					break;
+				case VALUE_NOT_OPERATOR:
+					ret = new CBoolValue(m_int == 0);
+					break;
 				default:
+					printf("Found op: %d\n", op);
 					ret = new CErrorValue("illegal operator. please send a bug report.");
 					break;
 			}
@@ -215,6 +219,9 @@ CValue* CIntValue::CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *v
 				case VALUE_LEQ_OPERATOR:
 					ret = new CBoolValue(((CFloatValue *) val)->GetFloat() <= m_int);
 					break;
+				case VALUE_NOT_OPERATOR:
+					ret = new CBoolValue(m_int == 0);
+					break;
 				default:
 					ret = new CErrorValue("illegal operator. please send a bug report.");
 					break;
diff --git a/source/gameengine/GameLogic/SCA_JoystickSensor.cpp b/source/gameengine/GameLogic/SCA_JoystickSensor.cpp
index c7e31f75306ba5780e4f61df1a7d28c1c9bf3a24..3cae3bcf160af26a5bf3f035f5ca8857bd86f9bf 100644
--- a/source/gameengine/GameLogic/SCA_JoystickSensor.cpp
+++ b/source/gameengine/GameLogic/SCA_JoystickSensor.cpp
@@ -367,7 +367,7 @@ PyObject *SCA_JoystickSensor::pyattr_get_axis_single(void *self_v, const KX_PYAT
 	SCA_Joystick *joy = ((SCA_JoystickManager *)self->m_eventmgr)->GetJoystickDevice(self->m_joyindex);
 	
 	if (self->m_joymode != KX_JOYSENSORMODE_AXIS_SINGLE) {
-		PyErr_SetString(PyExc_TypeError, "val = sensor.axisSingle: Joystick Sensor, not 'Single Axis' type");
+		PyErr_SetString(PyExc_AttributeError, "val = sensor.axisSingle: Joystick Sensor, not 'Single Axis' type");
 		return NULL;
 	}
 	
diff --git a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp
index 2c642d4bd0484ba849182de950e553412fbdddd1..f1edb71f4fedf5ca904712c87a062aeab47f45b2 100644
--- a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp
+++ b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp
@@ -1031,10 +1031,9 @@ int main(int argc, char** argv)
 						 * removal is needed else the system will free an already freed value */
 						system->removeEventConsumer(&app);
 
-						/* nodesystem relies on blendfile data, free it first */
-						free_nodesystem();
-
 						BLO_blendfiledata_free(bfd);
+						/* G.main == bfd->main, it gets referenced in free_nodesystem so we can't have a dangling pointer */
+						G.main = NULL;
 						if (python_main) MEM_freeN(python_main);
 					}
 				} while (exitcode == KX_EXIT_REQUEST_RESTART_GAME || exitcode == KX_EXIT_REQUEST_START_OTHER_GAME);
@@ -1052,6 +1051,13 @@ int main(int argc, char** argv)
 		}
 	}
 
+	/* refer to WM_exit_ext() and free_blender(),
+	 * these are not called in the player but we need to match some of there behavior here,
+	 * if the order of function calls or blenders state isn't matching that of blender proper,
+	 * we may get troubles later on */
+
+	free_nodesystem();
+
 	// Cleanup
 	RNA_exit();
 	BLF_exit();
diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
index b389347cdb074addf554a0d20eddd234f6322f93..0604157a420d5dc1f226f5165af302bec07ab7f9 100644
--- a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
+++ b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
@@ -1587,6 +1587,21 @@ bool CcdShapeConstructionInfo::SetMesh(RAS_MeshObject* meshobj, DerivedMesh* dm,
 				if (mf->v4 && vert_tag_array[mf->v4] == false) {vert_tag_array[mf->v4] = true; tot_bt_verts++;}
 			}
 		}
+		
+		/* Can happen with ngons */
+		if (!tot_bt_verts) {
+			m_shapeType = PHY_SHAPE_NONE;
+			m_meshObject = NULL;
+			m_vertexArray.clear();
+			m_polygonIndexArray.clear();
+			m_triFaceArray.clear();
+			m_triFaceUVcoArray.clear();
+			if (free_dm) {
+				dm->release(dm);
+				dm = NULL;
+			}
+			return false;
+		}
 
 		m_vertexArray.resize(tot_bt_verts*3);
 
@@ -1662,6 +1677,21 @@ bool CcdShapeConstructionInfo::SetMesh(RAS_MeshObject* meshobj, DerivedMesh* dm,
 			}
 		}
 
+		/* Can happen with ngons */
+		if (!tot_bt_verts) {
+			m_shapeType = PHY_SHAPE_NONE;
+			m_meshObject = NULL;
+			m_vertexArray.clear();
+			m_polygonIndexArray.clear();
+			m_triFaceArray.clear();
+			m_triFaceUVcoArray.clear();
+			if (free_dm) {
+				dm->release(dm);
+				dm = NULL;
+			}
+			return false;
+		}
+
 		m_vertexArray.resize(tot_bt_verts*3);
 		m_polygonIndexArray.resize(tot_bt_tris);
 		m_triFaceArray.resize(tot_bt_tris*3);