Skip to content

Commit

Permalink
Add try/catch around rendering to avoid destroying the map
Browse files Browse the repository at this point in the history
Fixes #1
  • Loading branch information
Jonathan Troyer committed Mar 27, 2020
1 parent 38d0e6f commit d2ee650
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions Source/MapComponents/MapComponent_RenderManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using HarmonyLib;
using ProgressRenderer.Source.Enum;
using RimWorld;
using RimWorld.Planet;
using RimWorld.Planet;
using UnityEngine;
using Verse;

Expand Down Expand Up @@ -300,18 +300,24 @@ private IEnumerator DoRendering(bool forceRenderFullMap = false)
RenderTexture.active = renderTexture;

// Render the image texture
if (PRModSettings.renderWeather)
try
{
map.weatherManager.DrawAllWeather();
}
for (int i = 0; i < renderCountZ; i++)
{
for (int j = 0; j < renderCountX; j++)
if (PRModSettings.renderWeather)
{
camera.transform.position = new Vector3(startX + cameraBasePos.x * (2 * j + 1), cameraBasePos.y, startZ + cameraBasePos.z * (2 * i + 1));
camera.Render();
imageTexture.ReadPixels(new Rect(0, 0, renderWidth, renderHeight), renderWidth * j, renderHeight * i, false);
map.weatherManager.DrawAllWeather();
}
for (int i = 0; i < renderCountZ; i++)
{
for (int j = 0; j < renderCountX; j++)
{
camera.transform.position = new Vector3(startX + cameraBasePos.x * (2 * j + 1), cameraBasePos.y, startZ + cameraBasePos.z * (2 * i + 1));
camera.Render();
imageTexture.ReadPixels(new Rect(0, 0, renderWidth, renderHeight), renderWidth * j, renderHeight * i, false);
}
}
} catch(Exception e)
{
Log.Error(e.Message, true);
}

// Restore camera and viewport
Expand Down
Binary file modified v1.1/Assemblies/Progress-Renderer.dll
Binary file not shown.

0 comments on commit d2ee650

Please sign in to comment.