Skip to content
This repository was archived by the owner on Apr 29, 2021. It is now read-only.

Commit 0da2258

Browse files
authored
Merge pull request #220 from UnityTech/gif
Fix GIF memory overflow issue.
2 parents c16cca7 + b87a6b3 commit 0da2258

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

Runtime/ui/painting/codec_gif.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class FrameData {
2525
volatile int _repetitionCount;
2626
volatile bool _isDone;
2727
volatile int _frameIndex;
28+
volatile Texture2D _texture;
2829
readonly UIWidgetsCoroutine _coroutine;
2930

3031
public GifCodec(byte[] bytes) {
@@ -129,20 +130,24 @@ public IPromise<FrameInfo> getNextFrame() {
129130
return frame.Then(frameData => {
130131
this._nextFrame();
131132

132-
if (frameData.frameInfo != null) {
133-
return frameData.frameInfo;
133+
if (this._texture == null) {
134+
this._texture = new Texture2D(this._width, this._height, TextureFormat.BGRA32, false);
135+
this._texture.hideFlags = HideFlags.HideAndDontSave;
134136
}
135137

136-
var tex = new Texture2D(this._width, this._height, TextureFormat.BGRA32, false);
137-
tex.hideFlags = HideFlags.HideAndDontSave;
138+
var tex = this._texture;
138139
tex.LoadRawTextureData(frameData.gifFrame.bytes);
139140
tex.Apply();
140141

142+
if (frameData.frameInfo != null) {
143+
return frameData.frameInfo;
144+
}
145+
141146
frameData.frameInfo = new FrameInfo {
142147
image = new Image(tex),
143148
duration = TimeSpan.FromMilliseconds(frameData.gifFrame.delay)
144149
};
145-
frameData.gifFrame = null; // dispose gifFrame
150+
// frameData.gifFrame = null; // dispose gifFrame
146151

147152
return frameData.frameInfo;
148153
});

0 commit comments

Comments
 (0)