This repository was archived by the owner on Feb 25, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -18,14 +18,26 @@ base class ShaderLibrary extends NativeFieldWrapperClass1 {
18
18
19
19
ShaderLibrary ._();
20
20
21
+ // Hold a Dart-side reference to shaders in the library as they're wrapped for
22
+ // the first time. This prevents the wrapper from getting prematurely
23
+ // destroyed.
24
+ Map <String , Shader > shaders_ = {};
25
+
21
26
Shader ? operator [](String shaderName) {
22
27
// This `flutter_gpu` library isn't always registered as part of the builtin
23
28
// DartClassLibrary, and so we can't instantiate the Dart classes on the
24
29
// engine side.
25
30
// Providing a new wrapper to [_getShader] for wrapping the native
26
31
// counterpart (if it hasn't been wrapped already) is a hack to work around
27
32
// this.
28
- return _getShader (shaderName, Shader ._());
33
+ Shader ? result = shaders_[shaderName];
34
+ if (result == null ) {
35
+ result = _getShader (shaderName, Shader ._());
36
+ if (result != null ) {
37
+ shaders_[shaderName] = result;
38
+ }
39
+ }
40
+ return result;
29
41
}
30
42
31
43
@Native < Handle Function (Handle , Handle )> (
You can’t perform that action at this time.
0 commit comments