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
parent
264b585ceb
commit
064dc29213
|
|
@ -1279,21 +1279,24 @@ namespace MCPForUnity.Editor.Tools
|
||||||
rt = RenderTexture.GetTemporary(preview.width, preview.height);
|
rt = RenderTexture.GetTemporary(preview.width, preview.height);
|
||||||
Graphics.Blit(preview, rt);
|
Graphics.Blit(preview, rt);
|
||||||
RenderTexture.active = 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.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0);
|
||||||
readablePreview.Apply();
|
readablePreview.Apply();
|
||||||
|
|
||||||
|
var pngData = readablePreview.EncodeToPNG();
|
||||||
|
if (pngData != null && pngData.Length > 0)
|
||||||
|
{
|
||||||
|
previewBase64 = Convert.ToBase64String(pngData);
|
||||||
|
previewWidth = readablePreview.width;
|
||||||
|
previewHeight = readablePreview.height;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
RenderTexture.active = previous;
|
RenderTexture.active = previous;
|
||||||
if (rt != null) RenderTexture.ReleaseTemporary(rt);
|
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)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -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)
|
flags = re.MULTILINE | (re.IGNORECASE if edit.get("ignore_case") else 0)
|
||||||
|
|
||||||
# Find the best match using improved heuristics
|
# 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 not match:
|
||||||
if edit.get("allow_noop", True):
|
if edit.get("allow_noop", True):
|
||||||
continue
|
continue
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue