Call to MemorySafeList<T>.ToHashSet() does not return MemorySafeHashSet<T>
Good day! Upon updating my game version to 1.206.028 (Fieldwork update), I have discovered my scripts no longer compile. This issue can be tracked down to the ToHashSet() method no longer returning a HashSet<T>.
Specifically, this method returns a MemorySafeList<T>. Upon decompiling the code and finding the (apparently new) namespace VRage.Scripting.MemorySafeTypes containing memory safe implementations of different data structures (including the MemorySafeList and also a MemorySafeHashSet).
Printing out the types of the declared data structures (script attached below), we see that what was declared as List<int> was actually a MemorySafeList<int> from the aforementioned namespace, and crucially, so was the intHashSet variable after calling ToHashSet() on the MemorySafeList<int> (thus this call incorrectly returns MemorySafeList<T> instead of MemorySafeHashSet<T>). I presume this arises from an oversight in an extension method somewhere, or perhaps a lack thereof, though I haven't found the exact issue while decompiling.
SCRIPT:
public void Main(string argument, UpdateType updateSource) { List<int> intList = new List<int>(); var intHashSet = intList.ToHashSet(); Echo("" + intList.GetType().FullName); Echo("" + intHashSet.GetType().FullName); }ECHO OUTPUT:
VRage.Scripting.MemorySafeTypes.MemorySafeList`1[[System.Int32, ...]] VRage.Scripting.MemorySafeTypes.MemorySafeList`1[[System.Int32, ...]]Sincerely,
StarWarsFTW
P.S. I love what you've done with these memory safe structures to seamlessly keep track of the usage and beat badly behaving scripts with an exception. Thanks for making the game safer! o7
EDIT: I have managed to bully my decompiler into actually working. The precise location of the bug appears to be VRage.Scripting.MemorySafeTypes.MemorySafeLinqExtensions.cs, specifically the ToMemorySafeHashSet extension method for a source IEnumerable<T>
Code listed below:
public static MemorySafeList<T> ToMemorySafeHashSet<T>(this IEnumerable<T> source) { return new MemorySafeList<T>(source); }Presumably should be:
public static MemorySafeList<T> ToMemorySafeHashSet<T>(this IEnumerable<T> source) { return new MemorySafeHashSet<T>(source); }
Again, thank you for your time :)
Hello,
Thank you for the report. We added it to the internal system.
Best Regards,
Keen Software House: QA Department
Hello,
Thank you for the report. We added it to the internal system.
Best Regards,
Keen Software House: QA Department
Oops, forgot to match the return type of the method :) doesn't matter, the idea is conveyed
Oops, forgot to match the return type of the method :) doesn't matter, the idea is conveyed
Oh, another somewhat related bug it seems -
Some terminal properties accessible from the scripting API through IMyTerminalBlock.SetValue<T>() and GetValue<T>() 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:
We can work around this by explicitly setting the type parameter in the last line: 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?
Oh, another somewhat related bug it seems -
Some terminal properties accessible from the scripting API through IMyTerminalBlock.SetValue<T>() and GetValue<T>() 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:
We can work around this by explicitly setting the type parameter in the last line: 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?
hello! I have the same error, I will be grateful if you can fix it.
hello! I have the same error, I will be grateful if you can fix it.
I also want to report an incorrect error message. The following script is valid c# code
public static class Test {
public static void ToHashSet() {}
}
public void Main(string argument, UpdateType updateSource)
{
Test.ToHashSet();
}
but an error occurs when compiling in the program block:
Program(9.17): Error: 'Program.Test' does not contain a definition for 'ToMemorySafeHashSet'
I also want to report an incorrect error message. The following script is valid c# code
public static class Test {
public static void ToHashSet() {}
}
public void Main(string argument, UpdateType updateSource)
{
Test.ToHashSet();
}
but an error occurs when compiling in the program block:
Program(9.17): Error: 'Program.Test' does not contain a definition for 'ToMemorySafeHashSet'
Hello Engineers,
We released a hotfix on Friday that includes a change intended to prevent this issue from happening again.
If you notice any new problems with this feature, please submit a new report.
Thank you,
Keen Software House – QA Department
Hello Engineers,
We released a hotfix on Friday that includes a change intended to prevent this issue from happening again.
If you notice any new problems with this feature, please submit a new report.
Thank you,
Keen Software House – QA Department
StarWarsFTW's workaround for writing Broadcast Controller messages:
for the MemorySafeStringBuilder issue worked only for a brief time for me, then stopped working (keep getting the same runtime exception "Property Message0 is not of type MemorySafeStringBuilder, correct type is StringBuilder").
Please look into a fix for this as well.
Thank you for the support and the awesome game!!!
StarWarsFTW's workaround for writing Broadcast Controller messages:
for the MemorySafeStringBuilder issue worked only for a brief time for me, then stopped working (keep getting the same runtime exception "Property Message0 is not of type MemorySafeStringBuilder, correct type is StringBuilder").
Please look into a fix for this as well.
Thank you for the support and the awesome game!!!
Replies have been locked on this page!