Hello there once again! I mentioned this in a reply to my previous bug report regarding calls to MemorySafeList<T>.ToHashSet() returning a list instead of a hashset (which has since been fixed - thanks!) but I should have made a separate bug report - so I'm doing it now.
Some terminal properties accessible from the scripting API through IMyTerminalBlock.SetValue<T>(string propertyId, T value) and GetValue<T>(string propertyId) use the type StringBuilder. Since any variables of type StringBuilder get automatically replaced with MemorySafeStringBuilder from VRage.Scripting.MemorySafeTypes, if we let the type parameter be set implicitly, it uses the memory safe version and throws an exception - as demonstrated by the following code:
public void Main(string argument, UpdateType updateSource)
{
IMyBroadcastController broadcastController = GridTerminalSystem.GetBlockWithName("Broadcast Controller") as IMyBroadcastController;
StringBuilder message = new StringBuilder("Test Message");
// Type parameter set implicitly to MemorySafeStringBuilder for the SetValue call
broadcastController.SetValue("Message0", message);
}
We can work around this by explicitly setting the type parameter in the last line:
broadcastController.SetValue<StringBuilder>("Message0", message);
Here, presumably since the MemorySafeStringBuilder class has an implicit cast to StringBuilder, the code executes without an exception.
This workaround feels a bit clunky though and it would be nice if we could again use implicit type parameters - perhaps by changing the terminal properties from the StringBuilder type to MemorySafeStringBuilder and possibly even making the memory safe structures whitelisted to the scripting API?
Meant to post this as a bug, could someone move it please?
Meant to post this as a bug, could someone move it please?
Hello engineer,
Thank you for reaching our forum with this.
We have reproduced this issue on our side and put it into our internal system.
Kind Regards,
Keen Software House: QA Department
Hello engineer,
Thank you for reaching our forum with this.
We have reproduced this issue on our side and put it into our internal system.
Kind Regards,
Keen Software House: QA Department
This bug also happens to GetValue<StringBuilder>()
It seems some types (StringBuilder, List, Dictionary, etc) are now internally redirected to the corresponding MemorySafeXXX type, but the GetValue and SetValue are still expecting the old types.
This bug also happens to GetValue<StringBuilder>()
It seems some types (StringBuilder, List, Dictionary, etc) are now internally redirected to the corresponding MemorySafeXXX type, but the GetValue and SetValue are still expecting the old types.
Replies have been locked on this page!