[0.17.1543] UnityException Texture is not readable. Texture memory

Started by Kiame, May 23, 2017, 01:17:23 AM

Previous topic - Next topic

Kiame

I have a script that reads the user's selected color from a color-pallet texture. I've done some reading and it looks like a texture-load setting is incorrect in the mod texture load area.

Looking at the source

Verse.ModContentLoader
...
private static Texture2D LoadPNG(string filePath)
{
Texture2D texture2D = null;
if (File.Exists(filePath))
{
byte[] data = File.ReadAllBytes(filePath);
texture2D = new Texture2D(2, 2, TextureFormat.Alpha8, true);
texture2D.LoadImage(data);
texture2D.Compress(true);
texture2D.name = Path.GetFileNameWithoutExtension(filePath);
texture2D.filterMode = FilterMode.Bilinear;
texture2D.anisoLevel = 2;
texture2D.Apply(true, true);
}
return texture2D;
}


LoadImage(data, true); would fix the problem.

I'll keep trying to play around and find a workaround for mods

Solution:
Texture2D colorFinder = new Texture2D(2, 2, TextureFormat.Alpha8, true);
colorFinder.LoadImage(data, false);
Color pixel = texture.GetPixel(imageX, imageY);



[attachment deleted by admin due to age]

Fluffy (l2032)

you may want to PM Brainzz, he's run into the same problem.

In short, loading textures as non-readable costs less memory, so this is working as designed. You'll have to manually call the Unity method(s) to read image data into a texture - Brainzz has presumably figured this out already.

Kiame

Thank you for the feedback Fluffy. I will try that and if i can't get it working I'll contact Brainzz

Fluffy (l2032)

Oh an a related note, you might want to look at the Clutter mod by Mrofa. It includes a full HSVa colour picker I did a while back.

Kiame

If anyone runs into this issue here's how to load a texture that can be read:

Texture2D colorFinder = new Texture2D(2, 2, TextureFormat.Alpha8, true);
colorFinder.LoadImage(data, false);
Color pixel = texture.GetPixel(imageX, imageY);

ison

It's not a bug, textures are supposed to be loaded as non-readable. You have to manually load a texture or somehow copy it to be able to edit it. Thanks for reporting anyway.