ITerminalProperty StringBuilder InvalidOperationException (Version 1.206.032 b0)
Dear Keen Software House Development Team,
I am writing to report a persistent bug encountered while developing in-game scripts for Space Engineers, particularly affecting programmatic StringBuilder interactions with ITerminalProperty. This issue appears to be new or exacerbated by recent game updates, as functionalities that previously worked are now failing.
My Current Game Version: 1.206.032 b0
Bug: ITerminalProperty StringBuilder GetValue/SetValue Throws InvalidOperationException
Description: Attempting to read or write properties that are internally handled as StringBuilder (such as the "Message0" property of an IMyBroadcastController) using GetValue<StringBuilder>() or SetValue<StringBuilder>() now throws an InvalidOperationException. The error message specifically states: "Property Message0 is not of type MemorySafeStringBuilder, correct type is StringBuilder".
This issue effectively breaks programmatic reading and writing of these properties, as the expected type for GetValue/SetValue (standard StringBuilder) is not what the internal API is expecting (MemorySafeStringBuilder).
Impact: While the script can continue executing if this operation is wrapped in a try-catch block, the inability to directly manipulate these properties is a significant limitation. For example, it prevents setting persistent messages on Broadcast Controllers directly via script. Additionally, an unhandled instance of this InvalidOperationException can disrupt the behavior of other unrelated systems controlled by the same Programmable Block script (e.g., preventing IMyCameraBlock.Raycast() from properly releasing its internal hit state, leading to stale detection results).
Steps to Reproduce:
- Setup: Start a new vanilla world (ensure no mods are enabled). Place one Programmable Block and one Broadcast Controller on a powered grid.
- Script: Load the following minimal C# script into the Programmable Block:
public Program() { Runtime.UpdateFrequency = UpdateFrequency.Once; } public void Main(string argument, UpdateType updateSource) { IMyBroadcastController bc = GridTerminalSystem.GetBlockWithName("Broadcast Controller") as IMyBroadcastController; if (bc == null) { Echo("Broadcast Controller not found."); return; } try { // Attempt to read the Message0 property // This line causes the InvalidOperationException StringBuilder message0 = bc.GetValue<StringBuilder>("Message0"); Echo($"Read Message0: {message0}"); } catch (Exception e) { // The specific error observed is: // "InvalidOperationException - Property Message0 is not of type MemorySafeStringBuilder, correct type is StringBuilder" Echo($"ERROR reading Message0: {e.GetType().Name} - {e.Message}"); } try { // Attempt to write to the Message0 property // This line also causes the InvalidOperationException bc.SetValue<StringBuilder>("Message0", new StringBuilder("Test Message")); Echo("Wrote 'Test Message' to Message0."); } catch (Exception e) { // The specific error observed is: // "InvalidOperationException - Property Message0 is not of type MemorySafeStringBuilder, correct type is StringBuilder" Echo($"ERROR writing Message0: {e.GetType().Name} - {e.Message}"); } }
(Ensure your Broadcast Controller block's custom name in the terminal is "Broadcast Controller".) - Run Script: Run the Programmable Block.
- Observe Error: The Programmable Block's "Detail Info" output will display the InvalidOperationException as described above for both the read and write attempts.
I believe this issue significantly impacts scripting capabilities related to blocks with StringBuilder properties and can lead to unexpected secondary behaviors if not explicitly handled by a try-catch block. I hope this detailed report assists your team in investigating and resolving this. Please let me know if you require any further information or script examples.
Thank you for your time and efforts in maintaining Space Engineers.
Sincerely,
InimicaExcido, Space Engineer
Replies have been locked on this page!