Search Issue Tracker
Fixed in 2022.2.9f1
Fixed in 2022.2.X, 2023.1.X, 2023.2.X, 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)
Comments (1)
-
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
- UI Document (UXML) UI disappears from the Game view when any asset is imported and does not reappear until clicking in the Editor
- Warnings about invalid URIs are thrown when UI Builder's Material field is set to null
- Warnings about invalid URIs are thrown when UI Builder's Variable Asset Reference field is set to null
- "Attempting to use an invalid operation handle" error is thrown when stopping Play Mode after loading an Addressable scene using LoadSceneAsync
- Arabic separator character (066B) is treated as a full-width character when Duospacing is enabled on a TMP text component
Resolution Note (fix version 2023.2):
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):
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):
Setting a Sprite for an Image that had a Sprite with a null Texture assigned will not throw a NullReferenceException anymore.