Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Linux]: Fix other crash in Garbage #1432

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/xrGame/quadtree.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ class CQuadTree
IC T* get_object()
{
VERIFY(m_free);
VERIFY(m_free);
if (!m_free)
sobkas marked this conversation as resolved.
Show resolved Hide resolved
return nullptr;

T* node = m_free;
m_free = m_free->next();
ZeroMemory(node, sizeof(T));
Expand Down
12 changes: 12 additions & 0 deletions src/xrGame/quadtree_inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -102,6 +108,9 @@ IC void CSQuadTree::insert(_object_type* object)
if (!*node)
*node = m_nodes->get_object();

if (!node)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, back to the old discussion, we can't do *node (dereference) two lines above if node is nullptr, so this if (!node) check is actually late and we need to check for nullptr earlier.

return;

distance *= .5f;
u32 index = neighbour_index(object->position(), center, distance);
VERIFY(index < 4);
Expand Down Expand Up @@ -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)));
Expand Down