Skip to content

Commit ba9ba34

Browse files
committed
Update
1 parent ff4a3e2 commit ba9ba34

File tree

5 files changed

+29
-30
lines changed

5 files changed

+29
-30
lines changed

Assets/CustomTextureRenderer.Samples/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jp.sotanmochi.unitycustomtexturerenderer.samples",
3-
"version": "1.3.1",
3+
"version": "1.3.2",
44
"displayName": "CustomTextureRenderer.Samples",
55
"description": "A graphics utility to update textures from native plugins.",
66
"license": "MIT",

Assets/CustomTextureRenderer/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ The function for updating textures runs on another thread.
1414
// manifest.json
1515
{
1616
"dependencies": {
17-
"jp.sotanmochi.unitycustomtexturerenderer": "https://github.com/sotanmochi/UnityCustomTextureRenderer.git?path=Assets/CustomTextureRenderer#v1.3.1 ",
18-
"jp.sotanmochi.unitycustomtexturerenderer.samples": "https://github.com/sotanmochi/UnityCustomTextureRenderer.git?path=Assets/CustomTextureRenderer.Samples#v1.3.1",
17+
"jp.sotanmochi.unitycustomtexturerenderer": "https://github.com/sotanmochi/UnityCustomTextureRenderer.git?path=Assets/CustomTextureRenderer#v1.3.2 ",
18+
"jp.sotanmochi.unitycustomtexturerenderer.samples": "https://github.com/sotanmochi/UnityCustomTextureRenderer.git?path=Assets/CustomTextureRenderer.Samples#v1.3.2",
1919
...
2020
}
2121
}

Assets/CustomTextureRenderer/Runtime/PluginTextureRenderer.cs

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -139,39 +139,38 @@ public IntPtr CreateTextureBuffer(int width, int height, int bufferSize = 0)
139139
{
140140
_updated = false;
141141

142-
_textureBufferPtr = IntPtr.Zero;
143-
Marshal.FreeHGlobal(_textureUpdateParamsPtr);
144-
145-
if (_textureBuffer != null)
142+
if (_textureWidth != width || _textureHeight != height)
146143
{
147-
_textureBuffer = null;
148-
_textureBufferHandle.Free();
149-
}
144+
UnityEngine.Object.Destroy(_targetTexture);
150145

151-
UnityEngine.Object.Destroy(_targetTexture);
152-
153-
_targetTexture = new Texture2D(width, height, TextureFormat.RGBA32, false);
154-
_textureWidth = width;
155-
_textureHeight = height;
146+
_targetTexture = new Texture2D(width, height, TextureFormat.RGBA32, false);
147+
_textureWidth = width;
148+
_textureHeight = height;
149+
}
156150

157151
if (_rawTextureDataUpdateCallback != null)
158152
{
159-
if (bufferSize > _targetTexture.width * _targetTexture.height)
153+
if (_textureBuffer != null && _textureBuffer.Length < _textureWidth * _textureHeight)
160154
{
161-
_textureBuffer = new uint[bufferSize];
155+
_textureBufferPtr = IntPtr.Zero;
156+
_textureBuffer = null;
157+
_textureBufferHandle.Free();
162158
}
163-
else
159+
160+
if (_textureBuffer is null)
164161
{
165-
_textureBuffer = new uint[_targetTexture.width * _targetTexture.height];
162+
if (bufferSize > _targetTexture.width * _targetTexture.height)
163+
{
164+
_textureBuffer = new uint[bufferSize];
165+
}
166+
else
167+
{
168+
_textureBuffer = new uint[_targetTexture.width * _targetTexture.height];
169+
}
170+
171+
_textureBufferHandle = GCHandle.Alloc(_textureBuffer, GCHandleType.Pinned);
172+
_textureBufferPtr = _textureBufferHandle.AddrOfPinnedObject();
166173
}
167-
168-
_textureBufferHandle = GCHandle.Alloc(_textureBuffer, GCHandleType.Pinned);
169-
_textureBufferPtr = _textureBufferHandle.AddrOfPinnedObject();
170-
}
171-
172-
if (_customTextureUpdateCallback != null)
173-
{
174-
_textureUpdateParamsPtr = Marshal.AllocHGlobal(Marshal.SizeOf(_textureUpdateParams));
175174
}
176175

177176
DebugLog($"[{nameof(PluginTextureRenderer)}] Create texture: {_textureWidth}x{_textureHeight} [pixels]");

Assets/CustomTextureRenderer/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jp.sotanmochi.unitycustomtexturerenderer",
3-
"version": "1.3.1",
3+
"version": "1.3.2",
44
"displayName": "CustomTextureRenderer",
55
"description": "A graphics utility to update textures from native plugins.",
66
"license": "MIT",

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ The function for updating textures runs on another thread.
1414
// manifest.json
1515
{
1616
"dependencies": {
17-
"jp.sotanmochi.unitycustomtexturerenderer": "https://github.com/sotanmochi/UnityCustomTextureRenderer.git?path=Assets/CustomTextureRenderer#v1.3.1",
18-
"jp.sotanmochi.unitycustomtexturerenderer.samples": "https://github.com/sotanmochi/UnityCustomTextureRenderer.git?path=Assets/CustomTextureRenderer.Samples#v1.3.1",
17+
"jp.sotanmochi.unitycustomtexturerenderer": "https://github.com/sotanmochi/UnityCustomTextureRenderer.git?path=Assets/CustomTextureRenderer#v1.3.2",
18+
"jp.sotanmochi.unitycustomtexturerenderer.samples": "https://github.com/sotanmochi/UnityCustomTextureRenderer.git?path=Assets/CustomTextureRenderer.Samples#v1.3.2",
1919
...
2020
}
2121
}

0 commit comments

Comments
 (0)