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

Conversation

sobkas
Copy link
Contributor

@sobkas sobkas commented Aug 27, 2023

For some reason game sometimes crashes while in Garbage.

@Xottab-DUTY Xottab-DUTY changed the title [Linux]: Fix other crash in Gargage [Linux]: Fix other crash in Garbage Aug 27, 2023
Comment on lines 52 to 55
if (m_free == NULL)
{
return NULL;
}
Copy link
Member

Choose a reason for hiding this comment

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

Codestyle, plus it's better to leave VERIFY here, because it's not normal when m_free is null.

Suggested change
if (m_free == NULL)
{
return NULL;
}
VERIFY(m_free);
if (!m_free)
return nullptr;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Copy link
Member

Choose a reason for hiding this comment

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

Partially fixed, but not fully because:

  1. We always use nullptr, NULL is not used (and is replaced to nullptr during code refactoring)
  2. We don't check for nullptr explicitly, where it's possible to not do it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Partially fixed, but not fully because:

1. We always use nullptr, NULL is not used (and is replaced to nullptr during code refactoring)

2. We don't check for nullptr explicitly, where it's possible to not do it.

Well there is need to check if we have nullptr, otherwise there is a crash.

Copy link
Member

@Xottab-DUTY Xottab-DUTY Aug 28, 2023

Choose a reason for hiding this comment

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

Partially fixed, but not fully because:

1. We always use nullptr, NULL is not used (and is replaced to nullptr during code refactoring)

2. We don't check for nullptr explicitly, where it's possible to not do it.

Well there is need to check if we have nullptr, otherwise there is a crash.

I mean, we use if (!ptr) of if (ptr) checks rather than directly comparing to nullptr.

Comment on lines 95 to 99

if (list_item == NULL)
{
return;
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (list_item == NULL)
{
return;
}
if (!list_item)
return;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Comment on lines 286 to 289
if (node == NULL)
{
return NULL;
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (node == NULL)
{
return NULL;
}
VERIFY(node);
if (!node)
return nullptr;

@@ -102,6 +114,11 @@ IC void CSQuadTree::insert(_object_type* object)
if (!*node)
*node = m_nodes->get_object();

if (node == NULL)
Copy link
Member

Choose a reason for hiding this comment

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

node gets dereferenced 3 lines above :D
Also, we are in the cycle here. I'm not sure at the moment if we should return or continue the cycle.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now get_object() can return null, needs to check for it.

Copy link
Contributor Author

@sobkas sobkas Aug 27, 2023

Choose a reason for hiding this comment

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

Based on code already there return is ok, continue causes crashes.

Copy link
Member

Choose a reason for hiding this comment

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

Now get_object() can return null, needs to check for it.

But here we check if node is null, while get_object assigns to *node, not node 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now get_object() can return null, needs to check for it.

But here we check if node is null, while get_object assigns to *node, not node 🤔

Now get_object() can return null, needs to check for it.

But here we check if node is null, while get_object assigns to *node, not node 🤔

node is CQuadNode** node so *node is pointer I think? Otherwise it wouldn't compile.

@Xottab-DUTY Xottab-DUTY added Bug The issue in the run-time. Code Quality labels Aug 27, 2023
@sobkas sobkas force-pushed the other_crash branch 3 times, most recently from 6d41c16 to 49e4e0e Compare August 28, 2023 15:07
Copy link
Member

@Xottab-DUTY Xottab-DUTY left a comment

Choose a reason for hiding this comment

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

In the Files tab of a pull request, you can just press Add suggestion to batch and merge all my suggestions as one commit instead of porting them and recommiting manually.

So, I'm again here, with these suggestions. :)
We still need to leave those VERIFY in the code, because original devs assumed that it is not normal if m_free is nullptr.
Since QuadTree is a generic container it's good to keep it robust with nullptr checks, but it's also good to keep these assertions (VERIFYs) for debugging purposes.

src/xrGame/quadtree.h Show resolved Hide resolved
@@ -92,8 +92,16 @@ IC void CSQuadTree::insert(_object_type* object)
if (depth == m_max_depth)
{
CListItem* list_item = m_list_items->get_object();

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change

list_item->m_object = object;
list_item->m_next = (CListItem*)((void*)(*node));

if (!list_item->m_next )
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (!list_item->m_next )
if (!list_item->m_next)

For some reason game sometimes crashes while in Garbage.
@Xottab-DUTY
Copy link
Member

Could you give me the save file with the crash?

@sobkas
Copy link
Contributor Author

sobkas commented Sep 4, 2023

Could you give me the save file with the crash?

I started shooting at bandits and it crashed(it might take some time).
a234.sav.gz

Co-authored-by: Xottab_DUTY <Xottab-DUTY@users.noreply.github.com>
@sobkas
Copy link
Contributor Author

sobkas commented Sep 4, 2023

In the Files tab of a pull request, you can just press Add suggestion to batch and merge all my suggestions as one commit instead of porting them and recommiting manually.

I hate that there are two commit then, I prefer fix commits manually.
It's bad habit I took from using gerrit/baremetal git.

@sobkas
Copy link
Contributor Author

sobkas commented Sep 9, 2023

It's needed to be merged, without it I have rare but occurring crashes.

@sobkas sobkas closed this Sep 9, 2023
@sobkas sobkas deleted the other_crash branch September 9, 2023 16:17
@Xottab-DUTY
Copy link
Member

Superseded by #1439, and then by #1440

@@ -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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug The issue in the run-time. Code Quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants