summaryrefslogtreecommitdiffstats
path: root/src/objects/Object.cpp
diff options
context:
space:
mode:
authorerorcun <erorcunerorcun@hotmail.com.tr>2021-03-06 17:28:59 +0100
committerSergeanur <s.anureev@yandex.ua>2021-06-24 20:34:28 +0200
commit618d689dff9a22d9385abf36f5e364b38273b7cf (patch)
tree9378d463e73933c90dcf90be93da7c9bac3dbeb1 /src/objects/Object.cpp
parentFix quiet police scanner on OpenAL (diff)
downloadre3-618d689dff9a22d9385abf36f5e364b38273b7cf.tar
re3-618d689dff9a22d9385abf36f5e364b38273b7cf.tar.gz
re3-618d689dff9a22d9385abf36f5e364b38273b7cf.tar.bz2
re3-618d689dff9a22d9385abf36f5e364b38273b7cf.tar.lz
re3-618d689dff9a22d9385abf36f5e364b38273b7cf.tar.xz
re3-618d689dff9a22d9385abf36f5e364b38273b7cf.tar.zst
re3-618d689dff9a22d9385abf36f5e364b38273b7cf.zip
Diffstat (limited to '')
-rw-r--r--src/objects/Object.cpp30
1 files changed, 26 insertions, 4 deletions
diff --git a/src/objects/Object.cpp b/src/objects/Object.cpp
index 0721725d..575c592c 100644
--- a/src/objects/Object.cpp
+++ b/src/objects/Object.cpp
@@ -25,10 +25,32 @@ int16 CObject::nNoTempObjects;
//int16 CObject::nBodyCastHealth = 1000;
float CObject::fDistToNearestTree;
-void *CObject::operator new(size_t sz) { return CPools::GetObjectPool()->New(); }
-void *CObject::operator new(size_t sz, int handle) { return CPools::GetObjectPool()->New(handle);};
-void CObject::operator delete(void *p, size_t sz) { CPools::GetObjectPool()->Delete((CObject*)p); }
-void CObject::operator delete(void *p, int handle) { CPools::GetObjectPool()->Delete((CObject*)p); }
+// Object pools tends to be full sometimes, let's free a temp. object in this case.
+#ifdef FIX_BUGS
+void *CObject::operator new(size_t sz) throw() {
+ CObject *obj = CPools::GetObjectPool()->New();
+ if (!obj) {
+ CObjectPool *objectPool = CPools::GetObjectPool();
+ for (int32 i = 0; i < objectPool->GetSize(); i++) {
+ CObject *existing = objectPool->GetSlot(i);
+ if (existing && existing->ObjectCreatedBy == TEMP_OBJECT) {
+ int32 handle = objectPool->GetIndex(existing);
+ CWorld::Remove(existing);
+ delete existing;
+ obj = objectPool->New(handle);
+ break;
+ }
+ }
+ }
+ return obj;
+}
+#else
+void *CObject::operator new(size_t sz) throw() { return CPools::GetObjectPool()->New(); }
+#endif
+void *CObject::operator new(size_t sz, int handle) throw() { return CPools::GetObjectPool()->New(handle); };
+
+void CObject::operator delete(void *p, size_t sz) throw() { CPools::GetObjectPool()->Delete((CObject*)p); }
+void CObject::operator delete(void *p, int handle) throw() { CPools::GetObjectPool()->Delete((CObject*)p); }
CObject::CObject(void)
{