Skip to content

Commit 9cefcf5

Browse files
authored
Merge pull request #3 from Thundernerd/develop
Fixed null reference exceptions
2 parents 911029f + d9aa7a3 commit 9cefcf5

File tree

5 files changed

+18
-4
lines changed

5 files changed

+18
-4
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## [1.1.1] - 2020-08-19
4+
5+
### Fixed
6+
- Null reference exceptions
7+
38
## [1.1.0] - 2020-08-01
49

510
### Added

Runtime/SafeEvent.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@ public struct SafeEvent
1212

1313
public void RemoveAllSubscriptions()
1414
{
15-
subscriptions.Clear();
15+
subscriptions?.Clear();
1616
}
1717

1818
public void Invoke()
1919
{
20+
if (subscriptions == null)
21+
return;
22+
2023
foreach (var subscription in subscriptions)
2124
{
2225
#if UNITY_EDITOR || DEBUG

Runtime/SafeEventOneParameter.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@ public struct SafeEvent<T>
1212

1313
public void RemoveAllSubscriptions()
1414
{
15-
subscriptions.Clear();
15+
subscriptions?.Clear();
1616
}
1717

1818
public void Invoke(T obj)
1919
{
20+
if (subscriptions == null)
21+
return;
22+
2023
foreach (var subscription in subscriptions)
2124
{
2225
#if UNITY_EDITOR || DEBUG

Runtime/SafeEventTwoParameters.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@ public struct SafeEvent<T, T2>
1212

1313
public void RemoveAllSubscriptions()
1414
{
15-
subscriptions.Clear();
15+
subscriptions?.Clear();
1616
}
1717

1818
public void Invoke(T arg1, T2 arg2)
1919
{
20+
if (subscriptions == null)
21+
return;
22+
2023
foreach (var subscription in subscriptions)
2124
{
2225
#if UNITY_EDITOR || DEBUG

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "net.tnrd.safeevent",
33
"displayName": "Safe Event",
4-
"version": "1.0.0",
4+
"version": "1.1.1",
55
"unity": "2019.1",
66
"description": "An event class that has extra checks to help prevent mistakes",
77
"keywords": [

0 commit comments

Comments
 (0)