Skip to content

Fix: Improve LoadHelper stability with null check and debug logging#752

Open
maxxbox81 wants to merge 1 commit intocmangos:masterfrom
maxxbox81:branch-3
Open

Fix: Improve LoadHelper stability with null check and debug logging#752
maxxbox81 wants to merge 1 commit intocmangos:masterfrom
maxxbox81:branch-3

Conversation

@maxxbox81
Copy link

Added obj = nullptr to ensure default initialization and avoid undefined behavior.

Combined null and load failure check (if (!obj || !obj->LoadFromDB(...))) to prevent invalid access.

Moved IsInWorld() assertion to a conditional debug log using #ifdef MANGOS_DEBUG.

Replaced C-style cast with static_cast<T*> for improved type safety.

Improved overall code robustness and error tolerance without changing functionality.

🍰 Pullrequest

Proof

  • None

Issues

  • None

How2Test

  • None
    error 100
    error 101

Todo / Checklist

  • None

Added obj = nullptr to ensure default initialization and avoid undefined behavior.

Combined null and load failure check (if (!obj || !obj->LoadFromDB(...))) to prevent invalid access.

Moved IsInWorld() assertion to a conditional debug log using #ifdef MANGOS_DEBUG.

Replaced C-style cast with static_cast<T*> for improved type safety.

Improved overall code robustness and error tolerance without changing functionality.
for (uint32 guid : guid_set)
{
T* obj;
T* obj = nullptr;
Copy link
Contributor

Choose a reason for hiding this comment

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

This is unnecessary. Should new fail, it will fail with exception. We populate the field with every flow.

}
// sLog.outString("DEBUG: LoadHelper from table: %s for (guid: %u) Loading",table,guid);
if (!obj->LoadFromDB(guid, map, newGuid, 0))
if (!obj || !obj->LoadFromDB(guid, map, newGuid, 0))
Copy link
Contributor

Choose a reason for hiding this comment

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

Again, null check unnecessary. We populate the field in every case.

}

// Set cell info (used also by creatures)
addUnitState(obj, cell);
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice find

grid.AddGridObject(obj);

// Check whether object is correctly in world
if (!obj->IsInWorld())
Copy link
Contributor

Choose a reason for hiding this comment

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

If this happens, we have a critical problem in the core and need to shut down immediately. The assert is there for a critical reason.

++count;
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Empty space

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants