Skip to content

Commit

Permalink
defensive null checking
Browse files Browse the repository at this point in the history
  • Loading branch information
m1el committed Mar 29, 2021
1 parent 20ee949 commit 3dca12b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
5 changes: 3 additions & 2 deletions Core/NsvController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void Tick()
var delta = Time.deltaTime;
foreach (var slicedBlock in _slicedBlockPool)
{
if (slicedBlock.isActive)
if (!(slicedBlock is null) && slicedBlock.isActive)
{
slicedBlock.ExternalUpdate(delta);
}
Expand All @@ -74,7 +74,7 @@ public void Dispose()

foreach (var slicedBlock in _slicedBlockPool)
{
if (!slicedBlock) { continue; }
if (slicedBlock is null) { continue; }
slicedBlock.Dispose();
}
}
Expand All @@ -93,6 +93,7 @@ private void OnNoteCut(NoteController noteController, in NoteCutInfo noteCutInfo
var lineIndex = ((noteController.noteData.lineIndex % 4) + 4) % 4;
var blockIndex = lineIndex + 4 * lineLayer;
var slicedBlock = _slicedBlockPool[blockIndex];
if (slicedBlock is null) { return; }
slicedBlock.SetData(noteController, noteCutInfo, noteData);
}

Expand Down
11 changes: 8 additions & 3 deletions NsvAssetLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,22 @@ internal class NsvAssetLoader : IInitializable, IDisposable
private readonly SiraLog _siraLog;

private Material? _uiNoGlowMaterial;
private bool _loggedNoGlowMaterial = false;

public Material UINoGlowMaterial {
public Material? UINoGlowMaterial {
get {
if (!(_uiNoGlowMaterial is null))
{
return _uiNoGlowMaterial;
}
var sprite = Resources.FindObjectsOfTypeAll<Material>().First(m => m.name == "GameUISprite");
var sprite = Resources.FindObjectsOfTypeAll<Material>().FirstOrDefault(m => m.name == "GameUISprite");
if (sprite is null)
{
_siraLog.Error("Trying to get GameUISprite before it was loaded. This should not happen.");
if (!_loggedNoGlowMaterial)
{
_loggedNoGlowMaterial = true;
_siraLog.Error("Trying to get GameUISprite before it was loaded. This should not happen.");
}
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"id": "SliceVisualizer",
"name": "SliceVisualizer",
"author": "Igor null <[email protected]>",
"version": "0.1.2",
"version": "0.1.3",
"description": "Shows your cut data to train your accuracy",
"gameVersion": "1.13.4",
"dependsOn": {
Expand Down

0 comments on commit 3dca12b

Please sign in to comment.