summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-02-03 22:42:42 +0000
committerrubidium <rubidium@openttd.org>2009-02-03 22:42:42 +0000
commit1c30c8c801d2b4ecc6901069dcdfa8d0411aa1fd (patch)
tree4f0ff072e810fbda1bd6a01083ab7be1081bfdf3
parent101f55e65cd43daea211b26b5fe5666968a507f4 (diff)
downloadopenttd-1c30c8c801d2b4ecc6901069dcdfa8d0411aa1fd.tar.xz
(svn r15330) -Fix [FS#2597]: leaking of Squirrel when using circular references (by enabling the GC).
-rw-r--r--config.lib1
-rw-r--r--projects/openttd_vs80.vcproj8
-rw-r--r--projects/openttd_vs80.vcproj.in8
-rw-r--r--projects/openttd_vs90.vcproj8
-rw-r--r--projects/openttd_vs90.vcproj.in8
-rw-r--r--src/ai/ai_core.cpp8
-rw-r--r--src/ai/ai_instance.cpp5
-rw-r--r--src/ai/ai_instance.hpp5
-rw-r--r--src/script/squirrel.cpp5
-rw-r--r--src/script/squirrel.hpp5
10 files changed, 44 insertions, 17 deletions
diff --git a/config.lib b/config.lib
index 943f5a6f1..547c47c3a 100644
--- a/config.lib
+++ b/config.lib
@@ -1243,7 +1243,6 @@ make_cflags_and_ldflags() {
CFLAGS="$CFLAGS -D_SQ64"
fi
CFLAGS="$CFLAGS -I$SCRIPT_SRC_DIR"
- CFLAGS="$CFLAGS -DNO_GARBAGE_COLLECTOR"
if [ -n "$png_config" ]; then
CFLAGS="$CFLAGS -DWITH_PNG"
diff --git a/projects/openttd_vs80.vcproj b/projects/openttd_vs80.vcproj
index b46f50ebc..09ada5e9c 100644
--- a/projects/openttd_vs80.vcproj
+++ b/projects/openttd_vs80.vcproj
@@ -60,7 +60,7 @@
FavorSizeOrSpeed="2"
OmitFramePointers="true"
AdditionalIncludeDirectories="..\objs\langs;..\src\3rdparty\squirrel\include"
- PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\&quot;OpenTTD\&quot;;NO_GARBAGE_COLLECTOR;WITH_ASSERT"
+ PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\&quot;OpenTTD\&quot;;WITH_ASSERT"
StringPooling="true"
ExceptionHandling="1"
RuntimeLibrary="0"
@@ -167,7 +167,7 @@
AdditionalOptions="/MP"
Optimization="0"
AdditionalIncludeDirectories="..\objs\langs;..\src\3rdparty\squirrel\include"
- PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\&quot;OpenTTD\&quot;;NO_GARBAGE_COLLECTOR"
+ PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\&quot;OpenTTD\&quot;;"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
UsePrecompiledHeader="0"
@@ -269,7 +269,7 @@
FavorSizeOrSpeed="2"
OmitFramePointers="true"
AdditionalIncludeDirectories="..\objs\langs;..\src\3rdparty\squirrel\include"
- PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\&quot;OpenTTD\&quot;;NO_GARBAGE_COLLECTOR;_SQ64;WITH_ASSERT"
+ PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\&quot;OpenTTD\&quot;;_SQ64;WITH_ASSERT"
StringPooling="true"
ExceptionHandling="1"
RuntimeLibrary="0"
@@ -377,7 +377,7 @@
AdditionalOptions="/MP"
Optimization="0"
AdditionalIncludeDirectories="..\objs\langs;..\src\3rdparty\squirrel\include"
- PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\&quot;OpenTTD\&quot;;NO_GARBAGE_COLLECTOR;_SQ64"
+ PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\&quot;OpenTTD\&quot;;_SQ64"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
UsePrecompiledHeader="0"
diff --git a/projects/openttd_vs80.vcproj.in b/projects/openttd_vs80.vcproj.in
index e55933621..48842cf98 100644
--- a/projects/openttd_vs80.vcproj.in
+++ b/projects/openttd_vs80.vcproj.in
@@ -60,7 +60,7 @@
FavorSizeOrSpeed="2"
OmitFramePointers="true"
AdditionalIncludeDirectories="..\objs\langs;..\src\3rdparty\squirrel\include"
- PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\&quot;OpenTTD\&quot;;NO_GARBAGE_COLLECTOR;WITH_ASSERT"
+ PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\&quot;OpenTTD\&quot;;WITH_ASSERT"
StringPooling="true"
ExceptionHandling="1"
RuntimeLibrary="0"
@@ -167,7 +167,7 @@
AdditionalOptions="/MP"
Optimization="0"
AdditionalIncludeDirectories="..\objs\langs;..\src\3rdparty\squirrel\include"
- PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\&quot;OpenTTD\&quot;;NO_GARBAGE_COLLECTOR"
+ PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\&quot;OpenTTD\&quot;;"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
UsePrecompiledHeader="0"
@@ -269,7 +269,7 @@
FavorSizeOrSpeed="2"
OmitFramePointers="true"
AdditionalIncludeDirectories="..\objs\langs;..\src\3rdparty\squirrel\include"
- PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\&quot;OpenTTD\&quot;;NO_GARBAGE_COLLECTOR;_SQ64;WITH_ASSERT"
+ PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\&quot;OpenTTD\&quot;;_SQ64;WITH_ASSERT"
StringPooling="true"
ExceptionHandling="1"
RuntimeLibrary="0"
@@ -377,7 +377,7 @@
AdditionalOptions="/MP"
Optimization="0"
AdditionalIncludeDirectories="..\objs\langs;..\src\3rdparty\squirrel\include"
- PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\&quot;OpenTTD\&quot;;NO_GARBAGE_COLLECTOR;_SQ64"
+ PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\&quot;OpenTTD\&quot;;_SQ64"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
UsePrecompiledHeader="0"
diff --git a/projects/openttd_vs90.vcproj b/projects/openttd_vs90.vcproj
index a3e6257f6..f74335673 100644
--- a/projects/openttd_vs90.vcproj
+++ b/projects/openttd_vs90.vcproj
@@ -61,7 +61,7 @@
FavorSizeOrSpeed="2"
OmitFramePointers="true"
AdditionalIncludeDirectories="..\objs\langs;..\src\3rdparty\squirrel\include"
- PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\&quot;OpenTTD\&quot;;NO_GARBAGE_COLLECTOR;WITH_ASSERT"
+ PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\&quot;OpenTTD\&quot;;WITH_ASSERT"
StringPooling="true"
ExceptionHandling="1"
RuntimeLibrary="0"
@@ -166,7 +166,7 @@
AdditionalOptions="/MP"
Optimization="0"
AdditionalIncludeDirectories="..\objs\langs;..\src\3rdparty\squirrel\include"
- PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\&quot;OpenTTD\&quot;;NO_GARBAGE_COLLECTOR"
+ PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\&quot;OpenTTD\&quot;;"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
UsePrecompiledHeader="0"
@@ -267,7 +267,7 @@
FavorSizeOrSpeed="2"
OmitFramePointers="true"
AdditionalIncludeDirectories="..\objs\langs;..\src\3rdparty\squirrel\include"
- PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\&quot;OpenTTD\&quot;;NO_GARBAGE_COLLECTOR;_SQ64;WITH_ASSERT"
+ PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\&quot;OpenTTD\&quot;;_SQ64;WITH_ASSERT"
StringPooling="true"
ExceptionHandling="1"
RuntimeLibrary="0"
@@ -374,7 +374,7 @@
AdditionalOptions="/MP"
Optimization="0"
AdditionalIncludeDirectories="..\objs\langs;..\src\3rdparty\squirrel\include"
- PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\&quot;OpenTTD\&quot;;NO_GARBAGE_COLLECTOR;_SQ64"
+ PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\&quot;OpenTTD\&quot;;_SQ64"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
UsePrecompiledHeader="0"
diff --git a/projects/openttd_vs90.vcproj.in b/projects/openttd_vs90.vcproj.in
index 85067cd42..08c733872 100644
--- a/projects/openttd_vs90.vcproj.in
+++ b/projects/openttd_vs90.vcproj.in
@@ -61,7 +61,7 @@
FavorSizeOrSpeed="2"
OmitFramePointers="true"
AdditionalIncludeDirectories="..\objs\langs;..\src\3rdparty\squirrel\include"
- PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\&quot;OpenTTD\&quot;;NO_GARBAGE_COLLECTOR;WITH_ASSERT"
+ PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\&quot;OpenTTD\&quot;;WITH_ASSERT"
StringPooling="true"
ExceptionHandling="1"
RuntimeLibrary="0"
@@ -166,7 +166,7 @@
AdditionalOptions="/MP"
Optimization="0"
AdditionalIncludeDirectories="..\objs\langs;..\src\3rdparty\squirrel\include"
- PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\&quot;OpenTTD\&quot;;NO_GARBAGE_COLLECTOR"
+ PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\&quot;OpenTTD\&quot;;"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
UsePrecompiledHeader="0"
@@ -267,7 +267,7 @@
FavorSizeOrSpeed="2"
OmitFramePointers="true"
AdditionalIncludeDirectories="..\objs\langs;..\src\3rdparty\squirrel\include"
- PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\&quot;OpenTTD\&quot;;NO_GARBAGE_COLLECTOR;_SQ64;WITH_ASSERT"
+ PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\&quot;OpenTTD\&quot;;_SQ64;WITH_ASSERT"
StringPooling="true"
ExceptionHandling="1"
RuntimeLibrary="0"
@@ -374,7 +374,7 @@
AdditionalOptions="/MP"
Optimization="0"
AdditionalIncludeDirectories="..\objs\langs;..\src\3rdparty\squirrel\include"
- PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\&quot;OpenTTD\&quot;;NO_GARBAGE_COLLECTOR;_SQ64"
+ PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\&quot;OpenTTD\&quot;;_SQ64"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
UsePrecompiledHeader="0"
diff --git a/src/ai/ai_core.cpp b/src/ai/ai_core.cpp
index e9e2a5bd2..e49a7dd4b 100644
--- a/src/ai/ai_core.cpp
+++ b/src/ai/ai_core.cpp
@@ -3,6 +3,7 @@
/** @file ai_core.cpp Implementation of AI. */
#include "../stdafx.h"
+#include "../core/bitmath_func.hpp"
#include "../company_base.h"
#include "../company_func.h"
#include "../debug.h"
@@ -68,6 +69,13 @@
}
}
+ /* Occasionally collect garbage; every 255 ticks do one company.
+ * Effectively collecting garbage once every two months per AI. */
+ if ((AI::frame_counter & 255) == 0) {
+ CompanyID cid = (CompanyID)GB(AI::frame_counter, 8, 4);
+ if (IsValidCompanyID(cid) && !IsHumanCompany(cid)) GetCompany(cid)->ai_instance->CollectGarbage();
+ }
+
_current_company = OWNER_NONE;
}
diff --git a/src/ai/ai_instance.cpp b/src/ai/ai_instance.cpp
index 26d55481b..37529eeab 100644
--- a/src/ai/ai_instance.cpp
+++ b/src/ai/ai_instance.cpp
@@ -296,6 +296,11 @@ void AIInstance::GameLoop()
}
}
+void AIInstance::CollectGarbage()
+{
+ if (this->is_started && !this->is_dead) this->engine->CollectGarbage();
+}
+
/* static */ void AIInstance::DoCommandReturn(AIInstance *instance)
{
instance->engine->InsertResult(AIObject::GetLastCommandRes());
diff --git a/src/ai/ai_instance.hpp b/src/ai/ai_instance.hpp
index 688b3c133..9c1aaca59 100644
--- a/src/ai/ai_instance.hpp
+++ b/src/ai/ai_instance.hpp
@@ -45,6 +45,11 @@ public:
void GameLoop();
/**
+ * Let the VM collect any garbage.
+ */
+ void CollectGarbage();
+
+ /**
* Get the storage of this AI.
*/
static class AIStorage *GetStorage();
diff --git a/src/script/squirrel.cpp b/src/script/squirrel.cpp
index 26196292c..1400eaf0a 100644
--- a/src/script/squirrel.cpp
+++ b/src/script/squirrel.cpp
@@ -175,6 +175,11 @@ bool Squirrel::Resume(int suspend)
return this->vm->_suspended != 0;
}
+void Squirrel::CollectGarbage()
+{
+ sq_collectgarbage(this->vm);
+}
+
bool Squirrel::CallMethod(HSQOBJECT instance, const char *method_name, HSQOBJECT *ret, int suspend)
{
/* Store the stack-location for the return value. We need to
diff --git a/src/script/squirrel.hpp b/src/script/squirrel.hpp
index 39357bade..fc7472e96 100644
--- a/src/script/squirrel.hpp
+++ b/src/script/squirrel.hpp
@@ -101,6 +101,11 @@ public:
*/
bool Resume(int suspend = -1);
+ /**
+ * Tell the VM to do a garbage collection run.
+ */
+ void CollectGarbage();
+
void InsertResult(bool result);
void InsertResult(int result);