diff --git a/src/xrGame/quadtree.h b/src/xrGame/quadtree.h index 5d899843b7d..0aa232aa828 100644 --- a/src/xrGame/quadtree.h +++ b/src/xrGame/quadtree.h @@ -50,6 +50,10 @@ class CQuadTree IC T* get_object() { VERIFY(m_free); + VERIFY(m_free); + if (!m_free) + return nullptr; + T* node = m_free; m_free = m_free->next(); ZeroMemory(node, sizeof(T)); diff --git a/src/xrGame/quadtree_inline.h b/src/xrGame/quadtree_inline.h index a0a82506e8c..634ebdf9de2 100644 --- a/src/xrGame/quadtree_inline.h +++ b/src/xrGame/quadtree_inline.h @@ -92,8 +92,14 @@ IC void CSQuadTree::insert(_object_type* object) if (depth == m_max_depth) { CListItem* list_item = m_list_items->get_object(); + if (!list_item) + return; + list_item->m_object = object; list_item->m_next = (CListItem*)((void*)(*node)); + if (!list_item->m_next) + return; + *node = (CQuadNode*)((void*)list_item); ++m_leaf_count; return; @@ -102,6 +108,9 @@ IC void CSQuadTree::insert(_object_type* object) if (!*node) *node = m_nodes->get_object(); + if (!node) + return; + distance *= .5f; u32 index = neighbour_index(object->position(), center, distance); VERIFY(index < 4); @@ -267,6 +276,9 @@ IC _object_type* CSQuadTree::remove( const _object_type* object, CQuadNode*& node, Fvector center, float distance, int depth) { VERIFY(node); + if (!node) + return nullptr; + if (depth == m_max_depth) { CListItem*& node_leaf = ((CListItem*&)((void*&)(node)));