Skip to content

Commit

Permalink
Fixed texture leak in sim (#69)
Browse files Browse the repository at this point in the history
* Removed retro_log

* Removed the retro log dir

* Fixed texture leak in sim
  • Loading branch information
telemething authored Oct 13, 2021
1 parent dd640fe commit 918fef7
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions KomatsuSimulator/Assets/Scripts/Sensors/ImagePublisher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class ImagePublisher : MonoBehaviour

//private MessageTypes.Sensor.CompressedImage message;
private Texture2D texture2D;
private Texture2D texture2DFlipped;
private Rect rect;
private const int isBigEndian = 1;
private const int step = 3;
Expand All @@ -27,7 +28,7 @@ public class ImagePublisher : MonoBehaviour
/// Arg original: incoming texture
/// Returns: void
//*************************************************************************
public static void FlipTextureVerticallyInplace(Texture2D original)
public void FlipTextureVerticallyInplace(Texture2D original)
{
var originalPixels = original.GetPixels();

Expand All @@ -53,25 +54,18 @@ public static void FlipTextureVerticallyInplace(Texture2D original)
/// Arg original: incoming texture
/// Returns: Flipped texture
//*************************************************************************
public static Texture2D FlipTextureVertically(Texture2D original)
public Texture2D FlipTextureVertically(Texture2D original)
{
Texture2D flipped = new Texture2D(
original.width, original.height, original.format, false);

int xN = original.width;
int yN = original.height;

for (int i = 0; i < xN; i++)
{
for (int j = 0; j < yN; j++)
{
flipped.SetPixel(i, yN - j - 1, original.GetPixel(i, j));
}
}
texture2DFlipped.SetPixel(i, yN - j - 1, original.GetPixel(i, j));

flipped.Apply();
texture2DFlipped.Apply();

return flipped;
return texture2DFlipped;
}

//************************************************************************
Expand Down Expand Up @@ -105,6 +99,7 @@ private void InitializeGameObject()
{
ImageCamera.enabled = true;
texture2D = new Texture2D(resolutionWidth, resolutionHeight, TextureFormat.RGB24, false);
texture2DFlipped = new Texture2D(resolutionWidth, resolutionHeight, TextureFormat.RGB24, false);
rect = new Rect(0, 0, resolutionWidth, resolutionHeight);
ImageCamera.targetTexture = new RenderTexture(resolutionWidth, resolutionHeight, 24);
}
Expand All @@ -121,7 +116,7 @@ private void InitializeMessage()

//************************************************************************
/// Description: Update message, send to ROS
/// Returns: void
/// Returns: void
//*************************************************************************
public IEnumerator UpdateMessage()
{
Expand Down

0 comments on commit 918fef7

Please sign in to comment.