improve: add bounds check for sprites loading#1457
Merged
Conversation
Updated isValidDatId to verify that the provided category is less than ThingLastCategory, preventing out-of-bounds access to m_thingTypes.
Refactored Creature::setOutfit to validate and adjust the outfit category before assignment. Added error handling to revert to the previous outfit if the thing type is invalid, ensuring more robust state management.
Introduces validation to ensure the sprite ID is within the valid range for the sheet. Logs an error and returns nullptr if the ID is out of bounds, preventing potential crashes or undefined behavior.
The 'static' specifier was removed from the categoryName function in thingtype.cpp, as it is in an anonymous namespace and does not require static linkage.
Introduces a custom fmt::formatter specialization for TPoint<T>, enabling formatted output of point coordinates using the fmt library.
|
Contributor
|
I get this error when error in to the .spr/.dat system. ERROR: Failed to fetch sprite id 0 for thing (7028, item), layer 1, pattern 0x0x0, frame 0 0, offset 1x0
ERROR: Failed to fetch sprite id 0 for thing (128, creature), layer 0, pattern 0x0x0, frame 0 0, offset 1x0
ERROR: Failed to fetch sprite id 0 for thing (128, creature), layer 0, pattern 0x0x0, frame 0 0, offset 1x0
ERROR: Failed to fetch sprite id 0 for thing (128, creature), layer 0, pattern 0x0x0, frame 0 0, offset 1x0
ERROR: Failed to fetch sprite id 0 for thing (128, creature), layer 0, pattern 0x0x0, frame 0 0, offset 1x0
ERROR: Failed to fetch sprite id 0 for thing (128, creature), layer 0, pattern 0x0x0, frame 0 0, offset 1x0
ERROR: Failed to fetch sprite id 0 for thing (128, creature), layer 0, pattern 0x0x0, frame 0 0, offset 1x0
ERROR: Failed to fetch sprite id 0 for thing (128, creature), layer 0, pattern 0x0x0, frame 0 0, offset 1x0
ERROR: Failed to fetch sprite id 0 for thing (128, creature), layer 0, pattern 0x0x0, frame 0 0, offset 1x0
ERROR: Failed to fetch sprite id 0 for thing (128, creature), layer 0, pattern 0x0x0, frame 0 0, offset 1x0
ERROR: Failed to fetch sprite id 0 for thing (128, creature), layer 0, pattern 0x0x0, frame 0 0, offset 1x0
ERROR: Failed to fetch sprite id 0 for thing (130, creature), layer 0, pattern 0x0x0, frame 0 0, offset 1x0
ERROR: Failed to fetch sprite id 0 for thing (130, creature), layer 0, pattern 0x0x0, frame 0 0, offset 1x0
ERROR: Failed to fetch sprite id 0 for thing (130, creature), layer 0, pattern 0x0x0, frame 0 0, offset 1x0
ERROR: Failed to fetch sprite id 0 for thing (130, creature), layer 0, pattern 0x0x0, frame 0 0, offset 1x0 |
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.



This pull request introduces several improvements and bug fixes related to sprite sheet management, error handling, and outfit assignment in the client codebase. The changes enhance robustness by adding bounds checking, improving error reporting, and ensuring proper handling of invalid data.
Sprite Sheet Management and Validation
getSpritesPerSheet()method toSpriteSheet, and used it to clamplastSpriteIdif it exceeds the sheet's capacity when loading appearances, preventing out-of-bounds sprite access. [1] [2] [3]SpriteAppearances::getSpriteImage()to log and prevent access to sprites outside the valid range for a sheet.Error Reporting and Logging
ThingType::loadTexture()to report failures when fetching sprite images, including detailed context such as sprite ID, thing name, category, and pattern/frame info. [1] [2] [3]Outfit Assignment and Validation
Creature::setOutfit()to handle invalid outfits by setting the appropriate category and reverting to the old outfit if the thing type is invalid, with error logging. [1] [2]Miscellaneous
isValidDatId()inThingTypeManagerto ensure category bounds are checked before validating IDs.