summaryrefslogtreecommitdiffstats
path: root/src/objects
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/objects/Object.cpp30
-rw-r--r--src/objects/Object.h8
2 files changed, 30 insertions, 8 deletions
diff --git a/src/objects/Object.cpp b/src/objects/Object.cpp
index 85936bb8..2a7de2c7 100644
--- a/src/objects/Object.cpp
+++ b/src/objects/Object.cpp
@@ -16,10 +16,32 @@
int16 CObject::nNoTempObjects;
int16 CObject::nBodyCastHealth = 1000;
-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)
{
diff --git a/src/objects/Object.h b/src/objects/Object.h
index c9a1bba8..114a1a9f 100644
--- a/src/objects/Object.h
+++ b/src/objects/Object.h
@@ -65,10 +65,10 @@ public:
static int16 nNoTempObjects;
static int16 nBodyCastHealth;
- static void *operator new(size_t);
- static void *operator new(size_t, int);
- static void operator delete(void*, size_t);
- static void operator delete(void*, int);
+ static void *operator new(size_t) throw();
+ static void *operator new(size_t, int) throw();
+ static void operator delete(void*, size_t) throw();
+ static void operator delete(void*, int) throw();
CObject(void);
CObject(int32, bool);