From f139cab3727e28e0af7390d2c2620fbca7264203 Mon Sep 17 00:00:00 2001
From: Amorilia <amorilia@users.sourceforge.net>
Date: Tue, 30 May 2006 05:42:32 +0000
Subject: [PATCH] Converted asserts into runtime errors.

---
 xml_extract.h | 388 +++++++++++++++++++++++++++++++++-----------------
 1 file changed, 258 insertions(+), 130 deletions(-)

diff --git a/xml_extract.h b/xml_extract.h
index f05f53f4..0c2cace8 100644
--- a/xml_extract.h
+++ b/xml_extract.h
@@ -10,7 +10,6 @@ All rights reserved.  Please see niflib.h for licence. */
 #include <fstream>
 #include <vector>
 #include <string>
-#include <cassert>
 
 using namespace std;
 
@@ -1278,13 +1277,15 @@ return out.str(); \
 
 #define A_PARTICLE_MODIFIER_FIXLINKS \
 NiObject::FixLinks( objects, link_stack, version ); \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   nextModifier = DynamicCast<AParticleModifier>(objects[link_stack.front()]); \
 else \
   nextModifier = NULL; \
 link_stack.pop_front(); \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   controller = DynamicCast<NiParticleSystemController>(objects[link_stack.front()]); \
 else \
@@ -1379,7 +1380,8 @@ return out.str(); \
 #define ABHK_CONSTRAINT_FIXLINKS \
 bhkSerializable::FixLinks( objects, link_stack, version ); \
 for (uint i0 = 0; i0 < numBodies; i0++) { \
-  assert(!link_stack.empty()); \
+  if (!link_stack.empty()) \
+    throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
   if (link_stack.front() != 0xffffffff) \
     bodies[i0] = DynamicCast<bhkShape>(objects[link_stack.front()]); \
   else \
@@ -1605,7 +1607,8 @@ return out.str(); \
 
 #define BHK_ENTITY_FIXLINKS \
 bhkWorldObject::FixLinks( objects, link_stack, version ); \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   shape = DynamicCast<bhkShape>(objects[link_stack.front()]); \
 else \
@@ -1649,13 +1652,15 @@ return out.str(); \
 
 #define NI_COLLISION_OBJECT_FIXLINKS \
 NiObject::FixLinks( objects, link_stack, version ); \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   parent = DynamicCast<NiAVObject>(objects[link_stack.front()]); \
 else \
   parent = NULL; \
 link_stack.pop_front(); \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   body = DynamicCast<NiObject>(objects[link_stack.front()]); \
 else \
@@ -1703,7 +1708,8 @@ return out.str(); \
 #define NI_EXTRA_DATA_FIXLINKS \
 NiObject::FixLinks( objects, link_stack, version ); \
 if ( version <= 0x04020200 ) { \
-  assert(!link_stack.empty()); \
+  if (!link_stack.empty()) \
+    throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
   if (link_stack.front() != 0xffffffff) \
     nextExtraData = DynamicCast<NiExtraData>(objects[link_stack.front()]); \
   else \
@@ -1857,7 +1863,8 @@ return out.str(); \
 #define NI_OBJECT_N_E_T_FIXLINKS \
 NiObject::FixLinks( objects, link_stack, version ); \
 if ( version <= 0x04020200 ) { \
-  assert(!link_stack.empty()); \
+  if (!link_stack.empty()) \
+    throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
   if (link_stack.front() != 0xffffffff) \
     extraData = DynamicCast<NiExtraData>(objects[link_stack.front()]); \
   else \
@@ -1866,7 +1873,8 @@ if ( version <= 0x04020200 ) { \
 }; \
 if ( version >= 0x0A000100 ) { \
   for (uint i1 = 0; i1 < numExtraDataList; i1++) { \
-    assert(!link_stack.empty()); \
+    if (!link_stack.empty()) \
+      throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
     if (link_stack.front() != 0xffffffff) \
       extraDataList[i1] = DynamicCast<NiExtraData>(objects[link_stack.front()]); \
     else \
@@ -1874,7 +1882,8 @@ if ( version >= 0x0A000100 ) { \
     link_stack.pop_front(); \
   }; \
 }; \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   controller = DynamicCast<NiTimeController>(objects[link_stack.front()]); \
 else \
@@ -1990,7 +1999,8 @@ return out.str(); \
 #define NI_A_V_OBJECT_FIXLINKS \
 NiObjectNET::FixLinks( objects, link_stack, version ); \
 for (uint i0 = 0; i0 < numProperties; i0++) { \
-  assert(!link_stack.empty()); \
+  if (!link_stack.empty()) \
+    throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
   if (link_stack.front() != 0xffffffff) \
     properties[i0] = DynamicCast<NiProperty>(objects[link_stack.front()]); \
   else \
@@ -1998,7 +2008,8 @@ for (uint i0 = 0; i0 < numProperties; i0++) { \
   link_stack.pop_front(); \
 }; \
 if ( ( version >= 0x0A000100 ) && ( version <= 0x14000004 ) ) { \
-  assert(!link_stack.empty()); \
+  if (!link_stack.empty()) \
+    throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
   if (link_stack.front() != 0xffffffff) \
     collisionData = DynamicCast<NiCollisionData>(objects[link_stack.front()]); \
   else \
@@ -2006,7 +2017,8 @@ if ( ( version >= 0x0A000100 ) && ( version <= 0x14000004 ) ) { \
   link_stack.pop_front(); \
 }; \
 if ( version >= 0x14000005 ) { \
-  assert(!link_stack.empty()); \
+  if (!link_stack.empty()) \
+    throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
   if (link_stack.front() != 0xffffffff) \
     collisionObject = DynamicCast<NiCollisionObject>(objects[link_stack.front()]); \
   else \
@@ -2085,7 +2097,8 @@ return out.str(); \
 NiAVObject::FixLinks( objects, link_stack, version ); \
 if ( version >= 0x0A010000 ) { \
   for (uint i1 = 0; i1 < numAffectedNodes; i1++) { \
-    assert(!link_stack.empty()); \
+    if (!link_stack.empty()) \
+      throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
     if (link_stack.front() != 0xffffffff) \
       affectedNodes[i1] = DynamicCast<NiAVObject>(objects[link_stack.front()]); \
     else \
@@ -2195,7 +2208,8 @@ return out.str(); \
 
 #define NI_P_SYS_MODIFIER_FIXLINKS \
 NiObject::FixLinks( objects, link_stack, version ); \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   target = DynamicCast<NiParticleSystem>(objects[link_stack.front()]); \
 else \
@@ -2302,7 +2316,8 @@ return out.str(); \
 #define NI_P_SYS_VOLUME_EMITTER_FIXLINKS \
 NiPSysEmitter::FixLinks( objects, link_stack, version ); \
 if ( version >= 0x14000004 ) { \
-  assert(!link_stack.empty()); \
+  if (!link_stack.empty()) \
+    throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
   if (link_stack.front() != 0xffffffff) \
     emitterObject = DynamicCast<NiNode>(objects[link_stack.front()]); \
   else \
@@ -2363,13 +2378,15 @@ return out.str(); \
 
 #define NI_TIME_CONTROLLER_FIXLINKS \
 NiObject::FixLinks( objects, link_stack, version ); \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   nextController = DynamicCast<NiTimeController>(objects[link_stack.front()]); \
 else \
   nextController = NULL; \
 link_stack.pop_front(); \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   target = DynamicCast<NiObject>(objects[link_stack.front()]); \
 else \
@@ -2435,7 +2452,8 @@ return out.str(); \
 NiTimeController::FixLinks( objects, link_stack, version ); \
 for (uint i0 = 0; i0 < numNodeGroups; i0++) { \
   for (uint i1 = 0; i1 < nodeGroups[i0].numNodes; i1++) { \
-    assert(!link_stack.empty()); \
+    if (!link_stack.empty()) \
+      throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
     if (link_stack.front() != 0xffffffff) \
       nodeGroups[i0].nodes[i1] = DynamicCast<NiNode>(objects[link_stack.front()]); \
     else \
@@ -2477,7 +2495,8 @@ return out.str(); \
 #define NI_SINGLE_INTERPOLATOR_CONTROLLER_FIXLINKS \
 NiTimeController::FixLinks( objects, link_stack, version ); \
 if ( version >= 0x0A020000 ) { \
-  assert(!link_stack.empty()); \
+  if (!link_stack.empty()) \
+    throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
   if (link_stack.front() != 0xffffffff) \
     interpolator = DynamicCast<NiInterpolator>(objects[link_stack.front()]); \
   else \
@@ -2567,13 +2586,15 @@ return out.str(); \
 
 #define NI_TRI_BASED_GEOM_FIXLINKS \
 NiAVObject::FixLinks( objects, link_stack, version ); \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   data = DynamicCast<NiTriBasedGeomData>(objects[link_stack.front()]); \
 else \
   data = NULL; \
 link_stack.pop_front(); \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   skinInstance = DynamicCast<NiSkinInstance>(objects[link_stack.front()]); \
 else \
@@ -2581,7 +2602,8 @@ else \
 link_stack.pop_front(); \
 if ( version >= 0x0A000100 ) { \
   if ( (hasShader != 0) ) { \
-    assert(!link_stack.empty()); \
+    if (!link_stack.empty()) \
+      throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
     if (link_stack.front() != 0xffffffff) \
       unknownLink = DynamicCast<NiObject>(objects[link_stack.front()]); \
     else \
@@ -2824,7 +2846,8 @@ return out.str(); \
 #define NI_TRI_BASED_GEOM_DATA_FIXLINKS \
 NiObject::FixLinks( objects, link_stack, version ); \
 if ( version >= 0x14000004 ) { \
-  assert(!link_stack.empty()); \
+  if (!link_stack.empty()) \
+    throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
   if (link_stack.front() != 0xffffffff) \
     unknownLink = DynamicCast<NiObject>(objects[link_stack.front()]); \
   else \
@@ -3297,7 +3320,8 @@ return out.str(); \
 #define BHK_LIST_SHAPE_FIXLINKS \
 AbhkShapeCollection::FixLinks( objects, link_stack, version ); \
 for (uint i0 = 0; i0 < numSubShapes; i0++) { \
-  assert(!link_stack.empty()); \
+  if (!link_stack.empty()) \
+    throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
   if (link_stack.front() != 0xffffffff) \
     subShapes[i0] = DynamicCast<bhkShape>(objects[link_stack.front()]); \
   else \
@@ -3394,13 +3418,15 @@ return out.str(); \
 
 #define BHK_MALLEABLE_CONSTRAINT_FIXLINKS \
 AbhkConstraint::FixLinks( objects, link_stack, version ); \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   unknownLink1 = DynamicCast<NiObject>(objects[link_stack.front()]); \
 else \
   unknownLink1 = NULL; \
 link_stack.pop_front(); \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   unknownLink2 = DynamicCast<NiObject>(objects[link_stack.front()]); \
 else \
@@ -3477,7 +3503,8 @@ return out.str(); \
 
 #define BHK_MOPP_BV_TREE_SHAPE_FIXLINKS \
 bhkShape::FixLinks( objects, link_stack, version ); \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   shape = DynamicCast<bhkShape>(objects[link_stack.front()]); \
 else \
@@ -3626,7 +3653,8 @@ return out.str(); \
 #define BHK_NI_TRI_STRIPS_SHAPE_FIXLINKS \
 bhkSphereRepShape::FixLinks( objects, link_stack, version ); \
 for (uint i0 = 0; i0 < numStripsData; i0++) { \
-  assert(!link_stack.empty()); \
+  if (!link_stack.empty()) \
+    throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
   if (link_stack.front() != 0xffffffff) \
     stripsData[i0] = DynamicCast<NiTriStripsData>(objects[link_stack.front()]); \
   else \
@@ -3711,7 +3739,8 @@ return out.str(); \
 
 #define BHK_PACKED_NI_TRI_STRIPS_SHAPE_FIXLINKS \
 AbhkShapeCollection::FixLinks( objects, link_stack, version ); \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   data = DynamicCast<hkPackedNiTriStripsData>(objects[link_stack.front()]); \
 else \
@@ -3987,7 +4016,8 @@ return out.str(); \
 #define BHK_RIGID_BODY_FIXLINKS \
 bhkEntity::FixLinks( objects, link_stack, version ); \
 for (uint i0 = 0; i0 < numConstraints; i0++) { \
-  assert(!link_stack.empty()); \
+  if (!link_stack.empty()) \
+    throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
   if (link_stack.front() != 0xffffffff) \
     constraints[i0] = DynamicCast<AbhkConstraint>(objects[link_stack.front()]); \
   else \
@@ -4478,7 +4508,8 @@ return out.str(); \
 #define NI_ALPHA_CONTROLLER_FIXLINKS \
 NiSingleInterpolatorController::FixLinks( objects, link_stack, version ); \
 if ( version <= 0x0A010000 ) { \
-  assert(!link_stack.empty()); \
+  if (!link_stack.empty()) \
+    throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
   if (link_stack.front() != 0xffffffff) \
     data = DynamicCast<NiFloatData>(objects[link_stack.front()]); \
   else \
@@ -4831,13 +4862,15 @@ return out.str(); \
 ABoneLODController::FixLinks( objects, link_stack, version ); \
 for (uint i0 = 0; i0 < numShapeGroups; i0++) { \
   for (uint i1 = 0; i1 < shapeGroups1[i0].numLinkPairs; i1++) { \
-    assert(!link_stack.empty()); \
+    if (!link_stack.empty()) \
+      throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
     if (link_stack.front() != 0xffffffff) \
       shapeGroups1[i0].linkPairs[i1].shape = DynamicCast<NiTriShape>(objects[link_stack.front()]); \
     else \
       shapeGroups1[i0].linkPairs[i1].shape = NULL; \
     link_stack.pop_front(); \
-    assert(!link_stack.empty()); \
+    if (!link_stack.empty()) \
+      throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
     if (link_stack.front() != 0xffffffff) \
       shapeGroups1[i0].linkPairs[i1].skinInstance = DynamicCast<NiSkinInstance>(objects[link_stack.front()]); \
     else \
@@ -4846,7 +4879,8 @@ for (uint i0 = 0; i0 < numShapeGroups; i0++) { \
   }; \
 }; \
 for (uint i0 = 0; i0 < numShapeGroups2; i0++) { \
-  assert(!link_stack.empty()); \
+  if (!link_stack.empty()) \
+    throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
   if (link_stack.front() != 0xffffffff) \
     shapeGroups2[i0] = DynamicCast<NiTriShape>(objects[link_stack.front()]); \
   else \
@@ -4958,7 +4992,8 @@ return out.str(); \
 
 #define NI_BOOL_INTERPOLATOR_FIXLINKS \
 NiInterpolator::FixLinks( objects, link_stack, version ); \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   data = DynamicCast<NiBoolData>(objects[link_stack.front()]); \
 else \
@@ -4997,7 +5032,8 @@ return out.str(); \
 
 #define NI_BOOL_TIMELINE_INTERPOLATOR_FIXLINKS \
 NiInterpolator::FixLinks( objects, link_stack, version ); \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   data = DynamicCast<NiBoolData>(objects[link_stack.front()]); \
 else \
@@ -5130,13 +5166,15 @@ return out.str(); \
 
 #define NI_B_SPLINE_COMP_POINT3_INTERPOLATOR_FIXLINKS \
 NiBSplineInterpolator::FixLinks( objects, link_stack, version ); \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   data = DynamicCast<NiBSplineData>(objects[link_stack.front()]); \
 else \
   data = NULL; \
 link_stack.pop_front(); \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   unknownLink = DynamicCast<NiObject>(objects[link_stack.front()]); \
 else \
@@ -5187,13 +5225,15 @@ return out.str(); \
 
 #define NI_B_SPLINE_COMP_TRANSFORM_INTERPOLATOR_FIXLINKS \
 NiBSplineInterpolator::FixLinks( objects, link_stack, version ); \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   data = DynamicCast<NiBSplineData>(objects[link_stack.front()]); \
 else \
   data = NULL; \
 link_stack.pop_front(); \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   basisData = DynamicCast<NiBSplineBasisData>(objects[link_stack.front()]); \
 else \
@@ -5350,7 +5390,8 @@ return out.str(); \
 
 #define NI_CAMERA_FIXLINKS \
 NiAVObject::FixLinks( objects, link_stack, version ); \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   unknownLink_ = DynamicCast<NiObject>(objects[link_stack.front()]); \
 else \
@@ -5445,7 +5486,8 @@ return out.str(); \
 
 #define NI_COLLISION_DATA_FIXLINKS \
 NiObject::FixLinks( objects, link_stack, version ); \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   targetNode = DynamicCast<NiNode>(objects[link_stack.front()]); \
 else \
@@ -5572,14 +5614,16 @@ return out.str(); \
 #define NI_CONTROLLER_MANAGER_FIXLINKS \
 NiTimeController::FixLinks( objects, link_stack, version ); \
 for (uint i0 = 0; i0 < numControllerSequences; i0++) { \
-  assert(!link_stack.empty()); \
+  if (!link_stack.empty()) \
+    throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
   if (link_stack.front() != 0xffffffff) \
     controllerSequences[i0] = DynamicCast<NiControllerSequence>(objects[link_stack.front()]); \
   else \
     controllerSequences[i0] = NULL; \
   link_stack.pop_front(); \
 }; \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   objectPalette = DynamicCast<NiDefaultAVObjectPalette>(objects[link_stack.front()]); \
 else \
@@ -5948,14 +5992,16 @@ return out.str(); \
 #define NI_CONTROLLER_SEQUENCE_FIXLINKS \
 NiObject::FixLinks( objects, link_stack, version ); \
 if ( version <= 0x0A010000 ) { \
-  assert(!link_stack.empty()); \
+  if (!link_stack.empty()) \
+    throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
   if (link_stack.front() != 0xffffffff) \
     textKeys.interpolator = DynamicCast<NiInterpolator>(objects[link_stack.front()]); \
   else \
     textKeys.interpolator = NULL; \
   link_stack.pop_front(); \
   if ( version >= 0x0A01006A ) { \
-    assert(!link_stack.empty()); \
+    if (!link_stack.empty()) \
+      throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
     if (link_stack.front() != 0xffffffff) \
       textKeys.unknownLink1 = DynamicCast<NiObject>(objects[link_stack.front()]); \
     else \
@@ -5963,7 +6009,8 @@ if ( version <= 0x0A010000 ) { \
     link_stack.pop_front(); \
   }; \
   if ( ( version >= 0x0A01006A ) && ( version <= 0x0A01006A ) ) { \
-    assert(!link_stack.empty()); \
+    if (!link_stack.empty()) \
+      throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
     if (link_stack.front() != 0xffffffff) \
       textKeys.unknownLink2 = DynamicCast<NiObject>(objects[link_stack.front()]); \
     else \
@@ -5971,7 +6018,8 @@ if ( version <= 0x0A010000 ) { \
     link_stack.pop_front(); \
   }; \
   if ( version >= 0x0A020000 ) { \
-    assert(!link_stack.empty()); \
+    if (!link_stack.empty()) \
+      throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
     if (link_stack.front() != 0xffffffff) \
       textKeys.stringPalette = DynamicCast<NiStringPalette>(objects[link_stack.front()]); \
     else \
@@ -5980,14 +6028,16 @@ if ( version <= 0x0A010000 ) { \
   }; \
 }; \
 for (uint i0 = 0; i0 < numControlledBlocks; i0++) { \
-  assert(!link_stack.empty()); \
+  if (!link_stack.empty()) \
+    throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
   if (link_stack.front() != 0xffffffff) \
     controlledBlocks[i0].interpolator = DynamicCast<NiInterpolator>(objects[link_stack.front()]); \
   else \
     controlledBlocks[i0].interpolator = NULL; \
   link_stack.pop_front(); \
   if ( version >= 0x0A01006A ) { \
-    assert(!link_stack.empty()); \
+    if (!link_stack.empty()) \
+      throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
     if (link_stack.front() != 0xffffffff) \
       controlledBlocks[i0].unknownLink1 = DynamicCast<NiObject>(objects[link_stack.front()]); \
     else \
@@ -5995,7 +6045,8 @@ for (uint i0 = 0; i0 < numControlledBlocks; i0++) { \
     link_stack.pop_front(); \
   }; \
   if ( ( version >= 0x0A01006A ) && ( version <= 0x0A01006A ) ) { \
-    assert(!link_stack.empty()); \
+    if (!link_stack.empty()) \
+      throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
     if (link_stack.front() != 0xffffffff) \
       controlledBlocks[i0].unknownLink2 = DynamicCast<NiObject>(objects[link_stack.front()]); \
     else \
@@ -6003,7 +6054,8 @@ for (uint i0 = 0; i0 < numControlledBlocks; i0++) { \
     link_stack.pop_front(); \
   }; \
   if ( version >= 0x0A020000 ) { \
-    assert(!link_stack.empty()); \
+    if (!link_stack.empty()) \
+      throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
     if (link_stack.front() != 0xffffffff) \
       controlledBlocks[i0].stringPalette = DynamicCast<NiStringPalette>(objects[link_stack.front()]); \
     else \
@@ -6012,13 +6064,15 @@ for (uint i0 = 0; i0 < numControlledBlocks; i0++) { \
   }; \
 }; \
 if ( version >= 0x0A01006A ) { \
-  assert(!link_stack.empty()); \
+  if (!link_stack.empty()) \
+    throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
   if (link_stack.front() != 0xffffffff) \
     textKeys2 = DynamicCast<NiTextKeyExtraData>(objects[link_stack.front()]); \
   else \
     textKeys2 = NULL; \
   link_stack.pop_front(); \
-  assert(!link_stack.empty()); \
+  if (!link_stack.empty()) \
+    throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
   if (link_stack.front() != 0xffffffff) \
     manager = DynamicCast<NiControllerManager>(objects[link_stack.front()]); \
   else \
@@ -6026,7 +6080,8 @@ if ( version >= 0x0A01006A ) { \
   link_stack.pop_front(); \
 }; \
 if ( version >= 0x0A020000 ) { \
-  assert(!link_stack.empty()); \
+  if (!link_stack.empty()) \
+    throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
   if (link_stack.front() != 0xffffffff) \
     stringPalette = DynamicCast<NiStringPalette>(objects[link_stack.front()]); \
   else \
@@ -6081,7 +6136,8 @@ return out.str(); \
 #define NI_DEFAULT_A_V_OBJECT_PALETTE_FIXLINKS \
 NiObject::FixLinks( objects, link_stack, version ); \
 for (uint i0 = 0; i0 < numObjs; i0++) { \
-  assert(!link_stack.empty()); \
+  if (!link_stack.empty()) \
+    throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
   if (link_stack.front() != 0xffffffff) \
     objs[i0].object = DynamicCast<NiAVObject>(objects[link_stack.front()]); \
   else \
@@ -6194,7 +6250,8 @@ return out.str(); \
 #define NI_FLIP_CONTROLLER_FIXLINKS \
 NiSingleInterpolatorController::FixLinks( objects, link_stack, version ); \
 for (uint i0 = 0; i0 < numSources; i0++) { \
-  assert(!link_stack.empty()); \
+  if (!link_stack.empty()) \
+    throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
   if (link_stack.front() != 0xffffffff) \
     sources[i0] = DynamicCast<NiSourceTexture>(objects[link_stack.front()]); \
   else \
@@ -6311,7 +6368,8 @@ return out.str(); \
 #define NI_FLOAT_EXTRA_DATA_CONTROLLER_FIXLINKS \
 NiTimeController::FixLinks( objects, link_stack, version ); \
 if ( version >= 0x14000004 ) { \
-  assert(!link_stack.empty()); \
+  if (!link_stack.empty()) \
+    throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
   if (link_stack.front() != 0xffffffff) \
     unknownLink = DynamicCast<NiObject>(objects[link_stack.front()]); \
   else \
@@ -6351,7 +6409,8 @@ return out.str(); \
 
 #define NI_FLOAT_INTERPOLATOR_FIXLINKS \
 NiInterpolator::FixLinks( objects, link_stack, version ); \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   data = DynamicCast<NiFloatData>(objects[link_stack.front()]); \
 else \
@@ -6518,7 +6577,8 @@ return out.str(); \
 
 #define NI_GEOM_MORPHER_CONTROLLER_FIXLINKS \
 NiTimeController::FixLinks( objects, link_stack, version ); \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   data = DynamicCast<NiMorphData>(objects[link_stack.front()]); \
 else \
@@ -6526,7 +6586,8 @@ else \
 link_stack.pop_front(); \
 if ( version >= 0x0A01006A ) { \
   for (uint i1 = 0; i1 < numInterpolators; i1++) { \
-    assert(!link_stack.empty()); \
+    if (!link_stack.empty()) \
+      throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
     if (link_stack.front() != 0xffffffff) \
       interpolators[i1] = DynamicCast<NiInterpolator>(objects[link_stack.front()]); \
     else \
@@ -6671,7 +6732,8 @@ return out.str(); \
 
 #define NI_KEYFRAME_CONTROLLER_FIXLINKS \
 NiTimeController::FixLinks( objects, link_stack, version ); \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   data = DynamicCast<NiKeyframeData>(objects[link_stack.front()]); \
 else \
@@ -6706,7 +6768,8 @@ return out.str(); \
 
 #define B_S_KEYFRAME_CONTROLLER_FIXLINKS \
 NiKeyframeController::FixLinks( objects, link_stack, version ); \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   data2 = DynamicCast<NiKeyframeData>(objects[link_stack.front()]); \
 else \
@@ -6913,7 +6976,8 @@ return out.str(); \
 #define NI_LIGHT_COLOR_CONTROLLER_FIXLINKS \
 NiTimeController::FixLinks( objects, link_stack, version ); \
 if ( version <= 0x0A010000 ) { \
-  assert(!link_stack.empty()); \
+  if (!link_stack.empty()) \
+    throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
   if (link_stack.front() != 0xffffffff) \
     data = DynamicCast<NiPosData>(objects[link_stack.front()]); \
   else \
@@ -6921,7 +6985,8 @@ if ( version <= 0x0A010000 ) { \
   link_stack.pop_front(); \
 }; \
 if ( version >= 0x0A020000 ) { \
-  assert(!link_stack.empty()); \
+  if (!link_stack.empty()) \
+    throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
   if (link_stack.front() != 0xffffffff) \
     interpolator = DynamicCast<NiPoint3Interpolator>(objects[link_stack.front()]); \
   else \
@@ -6957,7 +7022,8 @@ return out.str(); \
 
 #define NI_LIGHT_DIMMER_CONTROLLER_FIXLINKS \
 NiTimeController::FixLinks( objects, link_stack, version ); \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   unknownLink = DynamicCast<NiInterpolator>(objects[link_stack.front()]); \
 else \
@@ -7000,7 +7066,8 @@ return out.str(); \
 
 #define NI_LOOK_AT_CONTROLLER_FIXLINKS \
 NiTimeController::FixLinks( objects, link_stack, version ); \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   lookAtNode = DynamicCast<NiNode>(objects[link_stack.front()]); \
 else \
@@ -7070,25 +7137,29 @@ return out.str(); \
 
 #define NI_LOOK_AT_INTERPOLATOR_FIXLINKS \
 NiInterpolator::FixLinks( objects, link_stack, version ); \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   lookAt = DynamicCast<NiNode>(objects[link_stack.front()]); \
 else \
   lookAt = NULL; \
 link_stack.pop_front(); \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   unknownLink1 = DynamicCast<NiPoint3Interpolator>(objects[link_stack.front()]); \
 else \
   unknownLink1 = NULL; \
 link_stack.pop_front(); \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   unknownLink2 = DynamicCast<NiFloatInterpolator>(objects[link_stack.front()]); \
 else \
   unknownLink2 = NULL; \
 link_stack.pop_front(); \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   unknownLink3 = DynamicCast<NiFloatInterpolator>(objects[link_stack.front()]); \
 else \
@@ -7136,7 +7207,8 @@ return out.str(); \
 #define NI_MATERIAL_COLOR_CONTROLLER_FIXLINKS \
 NiSingleInterpolatorController::FixLinks( objects, link_stack, version ); \
 if ( version <= 0x0A010000 ) { \
-  assert(!link_stack.empty()); \
+  if (!link_stack.empty()) \
+    throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
   if (link_stack.front() != 0xffffffff) \
     data = DynamicCast<NiPosData>(objects[link_stack.front()]); \
   else \
@@ -7366,7 +7438,8 @@ return out.str(); \
 #define NI_MESH_P_SYS_DATA_FIXLINKS \
 APSysData::FixLinks( objects, link_stack, version ); \
 if ( version <= 0x14000004 ) { \
-  assert(!link_stack.empty()); \
+  if (!link_stack.empty()) \
+    throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
   if (link_stack.front() != 0xffffffff) \
     modifier = DynamicCast<AParticleModifier>(objects[link_stack.front()]); \
   else \
@@ -7375,7 +7448,8 @@ if ( version <= 0x14000004 ) { \
 }; \
 if ( ( version >= 0x0A020000 ) && ( version <= 0x14000004 ) ) { \
   for (uint i1 = 0; i1 < numUnknownLinks; i1++) { \
-    assert(!link_stack.empty()); \
+    if (!link_stack.empty()) \
+      throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
     if (link_stack.front() != 0xffffffff) \
       unknownLinks[i1] = DynamicCast<AParticleModifier>(objects[link_stack.front()]); \
     else \
@@ -7384,7 +7458,8 @@ if ( ( version >= 0x0A020000 ) && ( version <= 0x14000004 ) ) { \
   }; \
 }; \
 if ( version >= 0x0A020000 ) { \
-  assert(!link_stack.empty()); \
+  if (!link_stack.empty()) \
+    throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
   if (link_stack.front() != 0xffffffff) \
     unknownLink2 = DynamicCast<NiNode>(objects[link_stack.front()]); \
   else \
@@ -7519,7 +7594,8 @@ return out.str(); \
 #define NI_MULTI_TARGET_TRANSFORM_CONTROLLER_FIXLINKS \
 NiTimeController::FixLinks( objects, link_stack, version ); \
 for (uint i0 = 0; i0 < numExtraTargets; i0++) { \
-  assert(!link_stack.empty()); \
+  if (!link_stack.empty()) \
+    throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
   if (link_stack.front() != 0xffffffff) \
     extraTargets[i0] = DynamicCast<NiNode>(objects[link_stack.front()]); \
   else \
@@ -7583,7 +7659,8 @@ return out.str(); \
 #define NI_NODE_FIXLINKS \
 NiAVObject::FixLinks( objects, link_stack, version ); \
 for (uint i0 = 0; i0 < numChildren; i0++) { \
-  assert(!link_stack.empty()); \
+  if (!link_stack.empty()) \
+    throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
   if (link_stack.front() != 0xffffffff) \
     children[i0] = DynamicCast<NiAVObject>(objects[link_stack.front()]); \
   else \
@@ -7591,7 +7668,8 @@ for (uint i0 = 0; i0 < numChildren; i0++) { \
   link_stack.pop_front(); \
 }; \
 for (uint i0 = 0; i0 < numEffects; i0++) { \
-  assert(!link_stack.empty()); \
+  if (!link_stack.empty()) \
+    throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
   if (link_stack.front() != 0xffffffff) \
     effects[i0] = DynamicCast<NiDynamicEffect>(objects[link_stack.front()]); \
   else \
@@ -7733,7 +7811,8 @@ return out.str(); \
 #define FX_RADIO_BUTTON_FIXLINKS \
 FxWidget::FixLinks( objects, link_stack, version ); \
 for (uint i0 = 0; i0 < numUnknownLinks; i0++) { \
-  assert(!link_stack.empty()); \
+  if (!link_stack.empty()) \
+    throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
   if (link_stack.front() != 0xffffffff) \
     unknownLinks[i0] = DynamicCast<NiObject>(objects[link_stack.front()]); \
   else \
@@ -7887,7 +7966,8 @@ return out.str(); \
 #define NI_L_O_D_NODE_FIXLINKS \
 NiNode::FixLinks( objects, link_stack, version ); \
 if ( (lodType == 1) ) { \
-  assert(!link_stack.empty()); \
+  if (!link_stack.empty()) \
+    throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
   if (link_stack.front() != 0xffffffff) \
     rangeData = DynamicCast<NiRangeLODData>(objects[link_stack.front()]); \
   else \
@@ -8044,7 +8124,8 @@ return out.str(); \
 
 #define NI_PARTICLE_COLOR_MODIFIER_FIXLINKS \
 AParticleModifier::FixLinks( objects, link_stack, version ); \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   colorData = DynamicCast<NiColorData>(objects[link_stack.front()]); \
 else \
@@ -8114,7 +8195,8 @@ return out.str(); \
 
 #define NI_PARTICLE_MESH_MODIFIER_FIXLINKS \
 AParticleModifier::FixLinks( objects, link_stack, version ); \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   particleMeshes = DynamicCast<NiTriBasedGeom>(objects[link_stack.front()]); \
 else \
@@ -8331,7 +8413,8 @@ return out.str(); \
 
 #define NI_PARTICLE_MESHES_DATA_FIXLINKS \
 NiParticlesData::FixLinks( objects, link_stack, version ); \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   unknownLink2 = DynamicCast<NiTriBasedGeom>(objects[link_stack.front()]); \
 else \
@@ -8387,7 +8470,8 @@ return out.str(); \
 NiParticles::FixLinks( objects, link_stack, version ); \
 if ( version >= 0x0A010000 ) { \
   for (uint i1 = 0; i1 < numModifiers; i1++) { \
-    assert(!link_stack.empty()); \
+    if (!link_stack.empty()) \
+      throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
     if (link_stack.front() != 0xffffffff) \
       modifiers[i1] = DynamicCast<NiPSysModifier>(objects[link_stack.front()]); \
     else \
@@ -8610,25 +8694,29 @@ return out.str(); \
 
 #define NI_PARTICLE_SYSTEM_CONTROLLER_FIXLINKS \
 NiTimeController::FixLinks( objects, link_stack, version ); \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   emitter = DynamicCast<NiObject>(objects[link_stack.front()]); \
 else \
   emitter = NULL; \
 link_stack.pop_front(); \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   unknownLink = DynamicCast<NiObject>(objects[link_stack.front()]); \
 else \
   unknownLink = NULL; \
 link_stack.pop_front(); \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   particleExtra = DynamicCast<AParticleModifier>(objects[link_stack.front()]); \
 else \
   particleExtra = NULL; \
 link_stack.pop_front(); \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   unknownLink2 = DynamicCast<NiObject>(objects[link_stack.front()]); \
 else \
@@ -8714,13 +8802,15 @@ return out.str(); \
 
 #define NI_PATH_CONTROLLER_FIXLINKS \
 NiTimeController::FixLinks( objects, link_stack, version ); \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   posData = DynamicCast<NiPosData>(objects[link_stack.front()]); \
 else \
   posData = NULL; \
 link_stack.pop_front(); \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   floatData = DynamicCast<NiFloatData>(objects[link_stack.front()]); \
 else \
@@ -8772,13 +8862,15 @@ return out.str(); \
 
 #define NI_PATH_INTERPOLATOR_FIXLINKS \
 NiBlendInterpolator::FixLinks( objects, link_stack, version ); \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   posData = DynamicCast<NiPosData>(objects[link_stack.front()]); \
 else \
   posData = NULL; \
 link_stack.pop_front(); \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   floatData = DynamicCast<NiFloatData>(objects[link_stack.front()]); \
 else \
@@ -8921,7 +9013,8 @@ return out.str(); \
 
 #define NI_PIXEL_DATA_FIXLINKS \
 NiObject::FixLinks( objects, link_stack, version ); \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   palette = DynamicCast<NiPalette>(objects[link_stack.front()]); \
 else \
@@ -9063,7 +9156,8 @@ return out.str(); \
 
 #define NI_POINT3_INTERPOLATOR_FIXLINKS \
 NiInterpolator::FixLinks( objects, link_stack, version ); \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   data = DynamicCast<NiPosData>(objects[link_stack.front()]); \
 else \
@@ -9182,7 +9276,8 @@ return out.str(); \
 
 #define NI_P_SYS_AGE_DEATH_MODIFIER_FIXLINKS \
 NiPSysModifier::FixLinks( objects, link_stack, version ); \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   spawnModifier = DynamicCast<NiPSysSpawnModifier>(objects[link_stack.front()]); \
 else \
@@ -9250,7 +9345,8 @@ return out.str(); \
 
 #define NI_P_SYS_BOMB_MODIFIER_FIXLINKS \
 NiPSysModifier::FixLinks( objects, link_stack, version ); \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   unknownLink = DynamicCast<NiNode>(objects[link_stack.front()]); \
 else \
@@ -9347,7 +9443,8 @@ return out.str(); \
 
 #define NI_P_SYS_COLLIDER_MANAGER_FIXLINKS \
 NiPSysModifier::FixLinks( objects, link_stack, version ); \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   collider = DynamicCast<NiPSysPlanarCollider>(objects[link_stack.front()]); \
 else \
@@ -9382,7 +9479,8 @@ return out.str(); \
 
 #define NI_P_SYS_COLOR_MODIFIER_FIXLINKS \
 NiPSysModifier::FixLinks( objects, link_stack, version ); \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   data = DynamicCast<NiColorData>(objects[link_stack.front()]); \
 else \
@@ -9605,7 +9703,8 @@ return out.str(); \
 
 #define NI_P_SYS_DRAG_MODIFIER_FIXLINKS \
 NiPSysModifier::FixLinks( objects, link_stack, version ); \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   parent = DynamicCast<NiObject>(objects[link_stack.front()]); \
 else \
@@ -9640,7 +9739,8 @@ return out.str(); \
 
 #define NI_P_SYS_EMITTER_CTLR_FIXLINKS \
 APSysCtlr::FixLinks( objects, link_stack, version ); \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   visibilityInterpolator = DynamicCast<NiInterpolator>(objects[link_stack.front()]); \
 else \
@@ -9870,7 +9970,8 @@ return out.str(); \
 
 #define NI_P_SYS_GRAVITY_MODIFIER_FIXLINKS \
 NiPSysModifier::FixLinks( objects, link_stack, version ); \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   gravityObject = DynamicCast<NiNode>(objects[link_stack.front()]); \
 else \
@@ -9990,7 +10091,8 @@ return out.str(); \
 #define NI_P_SYS_MESH_EMITTER_FIXLINKS \
 NiPSysEmitter::FixLinks( objects, link_stack, version ); \
 for (uint i0 = 0; i0 < numEmitterMeshes; i0++) { \
-  assert(!link_stack.empty()); \
+  if (!link_stack.empty()) \
+    throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
   if (link_stack.front() != 0xffffffff) \
     emitterMeshes[i0] = DynamicCast<NiTriBasedGeom>(objects[link_stack.front()]); \
   else \
@@ -10038,7 +10140,8 @@ return out.str(); \
 #define NI_P_SYS_MESH_UPDATE_MODIFIER_FIXLINKS \
 NiPSysModifier::FixLinks( objects, link_stack, version ); \
 for (uint i0 = 0; i0 < numMeshes; i0++) { \
-  assert(!link_stack.empty()); \
+  if (!link_stack.empty()) \
+    throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
   if (link_stack.front() != 0xffffffff) \
     meshes[i0] = DynamicCast<NiNode>(objects[link_stack.front()]); \
   else \
@@ -10139,25 +10242,29 @@ return out.str(); \
 
 #define NI_P_SYS_PLANAR_COLLIDER_FIXLINKS \
 NiObject::FixLinks( objects, link_stack, version ); \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   spawnModifier = DynamicCast<NiPSysSpawnModifier>(objects[link_stack.front()]); \
 else \
   spawnModifier = NULL; \
 link_stack.pop_front(); \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   parent = DynamicCast<NiObject>(objects[link_stack.front()]); \
 else \
   parent = NULL; \
 link_stack.pop_front(); \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   unknownLink_ = DynamicCast<NiObject>(objects[link_stack.front()]); \
 else \
   unknownLink_ = NULL; \
 link_stack.pop_front(); \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   colliderObject = DynamicCast<NiNode>(objects[link_stack.front()]); \
 else \
@@ -10654,7 +10761,8 @@ return out.str(); \
 #define NI_SKIN_DATA_FIXLINKS \
 NiObject::FixLinks( objects, link_stack, version ); \
 if ( version <= 0x0A010000 ) { \
-  assert(!link_stack.empty()); \
+  if (!link_stack.empty()) \
+    throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
   if (link_stack.front() != 0xffffffff) \
     skinPartition = DynamicCast<NiSkinPartition>(objects[link_stack.front()]); \
   else \
@@ -10719,28 +10827,32 @@ return out.str(); \
 
 #define NI_SKIN_INSTANCE_FIXLINKS \
 NiObject::FixLinks( objects, link_stack, version ); \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   data = DynamicCast<NiSkinData>(objects[link_stack.front()]); \
 else \
   data = NULL; \
 link_stack.pop_front(); \
 if ( version >= 0x0A020000 ) { \
-  assert(!link_stack.empty()); \
+  if (!link_stack.empty()) \
+    throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
   if (link_stack.front() != 0xffffffff) \
     skinPartition = DynamicCast<NiSkinPartition>(objects[link_stack.front()]); \
   else \
     skinPartition = NULL; \
   link_stack.pop_front(); \
 }; \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   skeletonRoot = DynamicCast<NiNode>(objects[link_stack.front()]); \
 else \
   skeletonRoot = NULL; \
 link_stack.pop_front(); \
 for (uint i0 = 0; i0 < bones.numBones; i0++) { \
-  assert(!link_stack.empty()); \
+  if (!link_stack.empty()) \
+    throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
   if (link_stack.front() != 0xffffffff) \
     bones.bones[i0] = DynamicCast<NiNode>(objects[link_stack.front()]); \
   else \
@@ -11102,7 +11214,8 @@ return out.str(); \
 NiObjectNET::FixLinks( objects, link_stack, version ); \
 if ( version >= 0x0A010000 ) { \
   if ( (useExternal == 1) ) { \
-    assert(!link_stack.empty()); \
+    if (!link_stack.empty()) \
+      throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
     if (link_stack.front() != 0xffffffff) \
       unknownLink = DynamicCast<NiObject>(objects[link_stack.front()]); \
     else \
@@ -11111,7 +11224,8 @@ if ( version >= 0x0A010000 ) { \
   }; \
 }; \
 if ( (useExternal == 0) ) { \
-  assert(!link_stack.empty()); \
+  if (!link_stack.empty()) \
+    throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
   if (link_stack.front() != 0xffffffff) \
     pixelData = DynamicCast<NiPixelData>(objects[link_stack.front()]); \
   else \
@@ -11519,7 +11633,8 @@ return out.str(); \
 
 #define NI_TEXTURE_EFFECT_FIXLINKS \
 NiDynamicEffect::FixLinks( objects, link_stack, version ); \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   sourceTexture = DynamicCast<NiSourceTexture>(objects[link_stack.front()]); \
 else \
@@ -11571,7 +11686,8 @@ return out.str(); \
 #define NI_TEXTURE_TRANSFORM_CONTROLLER_FIXLINKS \
 NiSingleInterpolatorController::FixLinks( objects, link_stack, version ); \
 if ( version <= 0x0A010000 ) { \
-  assert(!link_stack.empty()); \
+  if (!link_stack.empty()) \
+    throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
   if (link_stack.front() != 0xffffffff) \
     data = DynamicCast<NiFloatData>(objects[link_stack.front()]); \
   else \
@@ -12279,7 +12395,8 @@ return out.str(); \
 #define NI_TEXTURING_PROPERTY_FIXLINKS \
 NiProperty::FixLinks( objects, link_stack, version ); \
 if ( (hasBaseTexture != 0) ) { \
-  assert(!link_stack.empty()); \
+  if (!link_stack.empty()) \
+    throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
   if (link_stack.front() != 0xffffffff) \
     baseTexture.source = DynamicCast<NiSourceTexture>(objects[link_stack.front()]); \
   else \
@@ -12287,7 +12404,8 @@ if ( (hasBaseTexture != 0) ) { \
   link_stack.pop_front(); \
 }; \
 if ( (hasDarkTexture != 0) ) { \
-  assert(!link_stack.empty()); \
+  if (!link_stack.empty()) \
+    throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
   if (link_stack.front() != 0xffffffff) \
     darkTexture.source = DynamicCast<NiSourceTexture>(objects[link_stack.front()]); \
   else \
@@ -12295,7 +12413,8 @@ if ( (hasDarkTexture != 0) ) { \
   link_stack.pop_front(); \
 }; \
 if ( (hasDetailTexture != 0) ) { \
-  assert(!link_stack.empty()); \
+  if (!link_stack.empty()) \
+    throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
   if (link_stack.front() != 0xffffffff) \
     detailTexture.source = DynamicCast<NiSourceTexture>(objects[link_stack.front()]); \
   else \
@@ -12303,7 +12422,8 @@ if ( (hasDetailTexture != 0) ) { \
   link_stack.pop_front(); \
 }; \
 if ( (hasGlossTexture != 0) ) { \
-  assert(!link_stack.empty()); \
+  if (!link_stack.empty()) \
+    throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
   if (link_stack.front() != 0xffffffff) \
     glossTexture.source = DynamicCast<NiSourceTexture>(objects[link_stack.front()]); \
   else \
@@ -12311,7 +12431,8 @@ if ( (hasGlossTexture != 0) ) { \
   link_stack.pop_front(); \
 }; \
 if ( (hasGlowTexture != 0) ) { \
-  assert(!link_stack.empty()); \
+  if (!link_stack.empty()) \
+    throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
   if (link_stack.front() != 0xffffffff) \
     glowTexture.source = DynamicCast<NiSourceTexture>(objects[link_stack.front()]); \
   else \
@@ -12319,7 +12440,8 @@ if ( (hasGlowTexture != 0) ) { \
   link_stack.pop_front(); \
 }; \
 if ( (hasBumpMapTexture != 0) ) { \
-  assert(!link_stack.empty()); \
+  if (!link_stack.empty()) \
+    throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
   if (link_stack.front() != 0xffffffff) \
     bumpMapTexture.source = DynamicCast<NiSourceTexture>(objects[link_stack.front()]); \
   else \
@@ -12327,7 +12449,8 @@ if ( (hasBumpMapTexture != 0) ) { \
   link_stack.pop_front(); \
 }; \
 if ( (hasDecal0Texture != 0) ) { \
-  assert(!link_stack.empty()); \
+  if (!link_stack.empty()) \
+    throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
   if (link_stack.front() != 0xffffffff) \
     decal0Texture.source = DynamicCast<NiSourceTexture>(objects[link_stack.front()]); \
   else \
@@ -12336,7 +12459,8 @@ if ( (hasDecal0Texture != 0) ) { \
 }; \
 if ( version >= 0x14000004 ) { \
   if ( (((textureCount == 8)) && ((hasDecal1Texture != 0))) ) { \
-    assert(!link_stack.empty()); \
+    if (!link_stack.empty()) \
+      throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
     if (link_stack.front() != 0xffffffff) \
       decal1Texture.source = DynamicCast<NiSourceTexture>(objects[link_stack.front()]); \
     else \
@@ -12347,7 +12471,8 @@ if ( version >= 0x14000004 ) { \
 if ( version >= 0x0A000100 ) { \
   for (uint i1 = 0; i1 < numShaderTextures; i1++) { \
     if ( (shaderTextures[i1].isUsed != 0) ) { \
-      assert(!link_stack.empty()); \
+      if (!link_stack.empty()) \
+        throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
       if (link_stack.front() != 0xffffffff) \
         shaderTextures[i1].textureData.source = DynamicCast<NiSourceTexture>(objects[link_stack.front()]); \
       else \
@@ -12456,7 +12581,8 @@ return out.str(); \
 
 #define NI_TRANSFORM_INTERPOLATOR_FIXLINKS \
 NiInterpolator::FixLinks( objects, link_stack, version ); \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   data = DynamicCast<NiTransformData>(objects[link_stack.front()]); \
 else \
@@ -12727,7 +12853,8 @@ return out.str(); \
 
 #define NI_U_V_CONTROLLER_FIXLINKS \
 NiTimeController::FixLinks( objects, link_stack, version ); \
-assert(!link_stack.empty()); \
+if (!link_stack.empty()) \
+  throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
 if (link_stack.front() != 0xffffffff) \
   data = DynamicCast<NiUVData>(objects[link_stack.front()]); \
 else \
@@ -12927,7 +13054,8 @@ return out.str(); \
 #define NI_VIS_CONTROLLER_FIXLINKS \
 NiSingleInterpolatorController::FixLinks( objects, link_stack, version ); \
 if ( version <= 0x0A010000 ) { \
-  assert(!link_stack.empty()); \
+  if (!link_stack.empty()) \
+    throw runtime_error("Trying to pop a link from empty stack. This is probably a bug."); \
   if (link_stack.front() != 0xffffffff) \
     data = DynamicCast<NiVisData>(objects[link_stack.front()]); \
   else \
-- 
GitLab