From 3d9eb3eba0acad74d8c16dfca3732fb4b3405ae2 Mon Sep 17 00:00:00 2001
From: Niels Martin Hansen <nielsm@aegisub.org>
Date: Wed, 23 Jan 2008 23:02:26 +0000
Subject: [PATCH] Fix #558, very fail fix. Unwrap function call from assert()
 and it's suddenly called a lot more often in release builds.

Originally committed to SVN as r1825.
---
 aegisub/auto4_lua.cpp | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/aegisub/auto4_lua.cpp b/aegisub/auto4_lua.cpp
index 78cd5fc0f..b70ed32ab 100644
--- a/aegisub/auto4_lua.cpp
+++ b/aegisub/auto4_lua.cpp
@@ -641,24 +641,32 @@ namespace Automation4 {
 
 	void LuaFeatureFilter::ProcessSubs(AssFile *subs, wxWindow *export_dialog)
 	{
+		LuaStackcheck stackcheck(L);
+
 		GetFeatureFunction(1); // 1 = processing function
 		assert(lua_isfunction(L, -1));
+		stackcheck.check(1);
 
 		// prepare function call
 		// subtitles (undo doesn't make sense in exported subs, in fact it'll totally break the undo system)
 		LuaAssFile *subsobj = new LuaAssFile(L, subs, true/*allow modifications*/, false/*disallow undo*/);
-		(void) subsobj;
+		assert(lua_isuserdata(L, -1));
+		stackcheck.check(2);
 		// config
 		if (has_config && config_dialog) {
-			assert(config_dialog->LuaReadBack(L) == 1);
+			int results_produced = config_dialog->LuaReadBack(L);
+			assert(results_produced == 1);
 			// TODO, write back stored options here
 		} else {
 			// no config so put an empty table instead
 			lua_newtable(L);
 		}
+		assert(lua_istable(L, -1));
+		stackcheck.check(3);
 
 		LuaProgressSink *ps = new LuaProgressSink(L, export_dialog, false);
 		ps->SetTitle(GetName());
+		stackcheck.check(3);
 
 		// do call
 		LuaThreadedCall call(L, 2, 0);
@@ -668,6 +676,11 @@ namespace Automation4 {
 		(void) code;
 		//if (code) ThrowError();
 
+		stackcheck.check(0);
+
+		// Just ensure that subsobj survives until here
+		(void) subsobj;
+
 		delete ps;
 	}
 
-- 
GitLab