Fix: Improve LoadHelper stability with null check and debug logging#752
Open
maxxbox81 wants to merge 1 commit intocmangos:masterfrom
Open
Fix: Improve LoadHelper stability with null check and debug logging#752maxxbox81 wants to merge 1 commit intocmangos:masterfrom
maxxbox81 wants to merge 1 commit intocmangos:masterfrom
Conversation
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.
killerwife
reviewed
Aug 1, 2025
| for (uint32 guid : guid_set) | ||
| { | ||
| T* obj; | ||
| T* obj = nullptr; |
Contributor
There was a problem hiding this comment.
This is unnecessary. Should new fail, it will fail with exception. We populate the field with every flow.
killerwife
reviewed
Aug 1, 2025
| } | ||
| // 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)) |
Contributor
There was a problem hiding this comment.
Again, null check unnecessary. We populate the field in every case.
killerwife
reviewed
Aug 1, 2025
| } | ||
|
|
||
| // Set cell info (used also by creatures) | ||
| addUnitState(obj, cell); |
killerwife
reviewed
Aug 1, 2025
| grid.AddGridObject(obj); | ||
|
|
||
| // Check whether object is correctly in world | ||
| if (!obj->IsInWorld()) |
Contributor
There was a problem hiding this comment.
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.
killerwife
reviewed
Aug 1, 2025
| ++count; | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Issues
How2Test
Todo / Checklist