File tree Expand file tree Collapse file tree 2 files changed +28
-8
lines changed
WindowsMixedReality/Shared Expand file tree Collapse file tree 2 files changed +28
-8
lines changed Original file line number Diff line number Diff line change @@ -46,10 +46,10 @@ public async Task<GameObject> TryGenerateControllerModelFromPlatformSDK()
46
46
return null ;
47
47
}
48
48
49
- if ( ControllerModelDictionary . TryGetValue ( modelKey , out GameObject controllerModel ) )
49
+ if ( ControllerModelDictionary . TryGetValue ( modelKey , out gltfGameObject ) )
50
50
{
51
- controllerModel . SetActive ( true ) ;
52
- return controllerModel ;
51
+ gltfGameObject . SetActive ( true ) ;
52
+ return gltfGameObject ;
53
53
}
54
54
55
55
byte [ ] modelStream = await controllerModelProvider . TryGetControllerModel ( modelKey ) ;
@@ -65,7 +65,16 @@ public async Task<GameObject> TryGenerateControllerModelFromPlatformSDK()
65
65
66
66
if ( gltfGameObject != null )
67
67
{
68
- ControllerModelDictionary . Add ( modelKey , gltfGameObject ) ;
68
+ // After all the awaits, double check that another task didn't finish earlier
69
+ if ( ControllerModelDictionary . TryGetValue ( modelKey , out GameObject existingGameObject ) )
70
+ {
71
+ Object . Destroy ( gltfGameObject ) ;
72
+ return existingGameObject ;
73
+ }
74
+ else
75
+ {
76
+ ControllerModelDictionary . Add ( modelKey , gltfGameObject ) ;
77
+ }
69
78
}
70
79
#endif // MSFT_OPENXR_0_9_4_OR_NEWER
71
80
Original file line number Diff line number Diff line change @@ -50,11 +50,13 @@ public async Task<GameObject> TryGenerateControllerModelFromPlatformSDK()
50
50
return null ;
51
51
}
52
52
53
+ string key = GenerateKey ( spatialInteractionSource ) ;
54
+
53
55
// See if we've generated this model before and if we can return it
54
- if ( ControllerModelDictionary . TryGetValue ( GenerateKey ( spatialInteractionSource ) , out GameObject controllerModel ) )
56
+ if ( ControllerModelDictionary . TryGetValue ( key , out gltfGameObject ) )
55
57
{
56
- controllerModel . SetActive ( true ) ;
57
- return controllerModel ;
58
+ gltfGameObject . SetActive ( true ) ;
59
+ return gltfGameObject ;
58
60
}
59
61
60
62
Debug . Log ( "Trying to load controller model from platform SDK" ) ;
@@ -82,7 +84,16 @@ public async Task<GameObject> TryGenerateControllerModelFromPlatformSDK()
82
84
gltfGameObject = await gltfObject . ConstructAsync ( ) ;
83
85
if ( gltfGameObject != null )
84
86
{
85
- ControllerModelDictionary . Add ( GenerateKey ( spatialInteractionSource ) , gltfGameObject ) ;
87
+ // After all the awaits, double check that another task didn't finish earlier
88
+ if ( ControllerModelDictionary . TryGetValue ( key , out GameObject existingGameObject ) )
89
+ {
90
+ UnityEngine . Object . Destroy ( gltfGameObject ) ;
91
+ return existingGameObject ;
92
+ }
93
+ else
94
+ {
95
+ ControllerModelDictionary . Add ( key , gltfGameObject ) ;
96
+ }
86
97
}
87
98
}
88
99
#endif // WINDOWS_UWP
You can’t perform that action at this time.
0 commit comments