Search Issue Tracker
Fixed
Fixed in 2022.2.9f1, 2023.1.0b6, 2023.2.0a4
Votes
4
Found in
2022.1.15f1
2022.2.0b6
2023.1.0a9
2023.2.0a1
Issue ID
UUM-13053
Regression
Yes
UGUI NullReferenceException when sprite.texture is null
Reproduction steps:
1. Open the attached project
2. Open Assets/Scene scene and press Play
3. Inspect the Console window
Expected result: No errors are thrown
Actual result: NullReferenceException is thrown
Reproducible with: 2022.1.0a7, 2022.1.15f1, 2022.2.0b6, 2023.1.0a9
Not reproducible with: 2020.3.38f1, 2021.3.9f1, 2022.1.0a6
Reproducible on: macOS 12.5
Full error:
_NullReferenceException: Object reference not set to an instance of an object_
_UnityEngine.UI.Image.set_sprite (UnityEngine.Sprite value) (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/UI/Core/Image.cs:306)_
_Script.Start () (at Assets/Script.cs:21)_
-
hippogames
Nov 09, 2022 16:05
The following code of UnityEngine.UI.Image is unsafe (line 288)
m_SkipMaterialUpdate = m_Sprite.texture == (value ? value.texture : null);
bool wasReadeable = !GraphicsFormatUtility.IsCrunchFormat(m_Sprite.texture.format) && m_Sprite.texture.isReadable;It may throw NRE when texture was destroyed previously because of m_Sprite.texture may be NULL (line 288), and in the next line you're accessing m_Sprite.texture.format and m_Sprite.texture.isReadable
The error has appeared after upgrading to Unity 2022 from 2021.
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- Mouse inputs cannot be inputted when searching the Shortcuts Menu by type "Shortcut"
- "Debug Assertion Failed!" error when launching Windows Dedicated Server Player with Script Debugging enabled
- [Cinematic Studio][3D HDRP] Shader warnings thrown in the Console window when creating a new project with Cinematic Studio template
- Autoplay is triggered on Audio Assets when changing Asset Bundle tags
- Inspector Asset Bundle section has no indication for Variants, AssetBundle is written without a space, and Variant dropdown menu is available without setting the Asset Bundle first
Resolution Note (fix version 2023.2.0a4):
Setting a Sprite for an Image that had a Sprite with a null Texture assigned will not throw a NullReferenceException anymore.
Resolution Note (fix version 2023.1.0b6):
Setting a Sprite for an Image that had a Sprite with a null Texture assigned will not throw a NullReferenceException anymore.
Resolution Note (fix version 2022.2.9f1):
Setting a Sprite for an Image that had a Sprite with a null Texture assigned will not throw a NullReferenceException anymore.