Graphic's GetCopy() fails on Graphic_RandomRotated (for mod authors)

Started by LWM, September 29, 2020, 11:43:55 PM

Previous topic - Next topic


If you have a piece of apparel on the ground, the graphic used is a cached Graphic_RandomRotated.  If you take the graphic and do a GetCopy(newSize) it fails.

  var tinyGraphic = apparel.Graphic.GetCopy(new Vector2(0.5f,0.5f));

When this is attempted in game, the GraphicDatabase fails:

Exception getting Verse.Graphic_RandomRotated at : System.ArgumentException: Invalid generic arguments
Parameter name: typeArguments
  at (wrapper managed-to-native) System.Reflection.MonoMethod.MakeGenericMethod_impl(System.Reflection.MonoMethod,System.Type[])
  at System.Reflection.MonoMethod.MakeGenericMethod (System.Type[] methodInstantiation) [0x00071] in <567df3e0919241ba98db88bec4c6696f>:0
  at Verse.GenGeneric.InvokeStaticGenericMethod (System.Type baseClass, System.Type genericParam, System.String methodName, System.Object[] args) [0x00009] in <b02b390b894d4487a224faae4a3db641>:0
  at Verse.GraphicDatabase.Get (System.Type graphicClass, System.String path, UnityEngine.Shader shader, UnityEngine.Vector2 drawSize, UnityEngine.Color color, UnityEngine.Color colorTwo, Verse.GraphicData data, System.Collections.Generic.List`1[T] shaderParameters) [0x00105] in <b02b390b894d4487a224faae4a3db641>:0
Verse.Log:Error(String, Boolean)
Verse.GraphicDatabase:Get(Type, String, Shader, Vector2, Color, Color, GraphicData, List`1)
Verse.GraphicDatabase:Get(Type, String, Shader, Vector2, Color, Color)

This is mainly of interest to mod authors who want to draw tiny suits of plate armor on conveyor belts or in storage.  At the least, if `subGraphic` were public, we could use that.  If there is another workaround (or a better way to scale the image of spawned apparel) I would happily use it?