fix: Implement CodeRabbit resource management and type safety improvements

- Move RenderTexture cleanup to finally block to ensure proper disposal
- Add PNG data validation before Base64 conversion
- Add explicit TextureFormat.RGB24 specification
- Add bool() coercion for prefer_last parameter to handle non-boolean JSON values

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
main
David Sarno 2025-09-03 17:58:05 -07:00
parent 264b585ceb
commit 064dc29213
2 changed files with 11 additions and 8 deletions

View File

@ -1279,21 +1279,24 @@ namespace MCPForUnity.Editor.Tools
rt = RenderTexture.GetTemporary(preview.width, preview.height);
Graphics.Blit(preview, rt);
RenderTexture.active = rt;
readablePreview = new Texture2D(preview.width, preview.height);
readablePreview = new Texture2D(preview.width, preview.height, TextureFormat.RGB24, false);
readablePreview.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0);
readablePreview.Apply();
var pngData = readablePreview.EncodeToPNG();
if (pngData != null && pngData.Length > 0)
{
previewBase64 = Convert.ToBase64String(pngData);
previewWidth = readablePreview.width;
previewHeight = readablePreview.height;
}
}
finally
{
RenderTexture.active = previous;
if (rt != null) RenderTexture.ReleaseTemporary(rt);
if (readablePreview != null) UnityEngine.Object.DestroyImmediate(readablePreview);
}
var pngData = readablePreview.EncodeToPNG();
previewBase64 = Convert.ToBase64String(pngData);
previewWidth = readablePreview.width;
previewHeight = readablePreview.height;
UnityEngine.Object.DestroyImmediate(readablePreview);
}
catch (Exception ex)
{

View File

@ -42,7 +42,7 @@ def _apply_edits_locally(original_text: str, edits: List[Dict[str, Any]]) -> str
flags = re.MULTILINE | (re.IGNORECASE if edit.get("ignore_case") else 0)
# Find the best match using improved heuristics
match = _find_best_anchor_match(anchor, text, flags, edit.get("prefer_last", True))
match = _find_best_anchor_match(anchor, text, flags, bool(edit.get("prefer_last", True)))
if not match:
if edit.get("allow_noop", True):
continue