Skip to content

Commit 1d7829f

Browse files
committed
Fixed issue with logs that would exceed the vertex limit (used to be unimplemented).
1 parent c46b8d9 commit 1d7829f

2 files changed

Lines changed: 28 additions & 13 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88
- Changed command suggestions / autocomplete to also work with aliases.
9+
- Fixed issues with displaying logs that exceed the rendering limit.
910

1011
## [0.1.9-alpha] - 2021-08-05
1112
- Added events for when the console is enabled/disabled, opened/closed and focused/unfocused.

Runtime/DevConsoleMono.cs

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,9 @@ private void LateUpdate()
774774
// Process the stored logs, displaying them to the console
775775
if (_logTextStore != string.Empty)
776776
{
777-
ProcessStoredLogs();
777+
string logText = string.Copy(_logTextStore);
778+
_logTextStore = string.Empty;
779+
ProcessLogText(logText);
778780
}
779781

780782
// Check if the developer console toggle key was pressed
@@ -2113,37 +2115,49 @@ private void CycleCommandSuggestions(int direction)
21132115

21142116
#region Log content methods
21152117

2116-
private void ProcessStoredLogs()
2118+
private void ProcessLogText(in string logText)
21172119
{
2118-
// Determine number of vertices needed to render the stored logs
2119-
int vertexCountStored = GetVertexCount(_logTextStore);
2120+
// Determine number of vertices needed to render the log text
2121+
int vertexCountStored = GetVertexCount(logText);
21202122

2121-
// Check if the stored logs exceeds the maximum vertex count
2123+
// Check if the log text exceeds the maximum vertex count
21222124
if (vertexCountStored > MaximumTextVertices)
21232125
{
2124-
// TODO: Split into multiple
2125-
// For now, produce an error
2126-
_logTextStore = $"\n<color={ErrorColour}>Message to log exceeded {MaximumTextVertices} vertices and was ignored.</color>";
2126+
// Split into two halves and recursively call this same method
2127+
2128+
// Attempt to split into two halves at the closest new line character from the middle
2129+
int length = logText.IndexOf('\n', logText.Length / 2);
2130+
if (length == -1)
2131+
{
2132+
// Otherwise just split straight in the middle (may format weirdly in the console)
2133+
length = logText.Length / 2;
2134+
}
2135+
2136+
// Process the first half
2137+
ProcessLogText(logText.Substring(0, length));
2138+
2139+
// Process the second half
2140+
ProcessLogText(logText.Substring(length, logText.Length - length));
21272141
return;
21282142
}
21292143

2130-
// Check if the stored logs appended to the current logs exceeds the maximum vertex count
2144+
// Check if the log text appended to the current logs exceeds the maximum vertex count
21312145
else if (_vertexCount + vertexCountStored > MaximumTextVertices)
21322146
{
21332147
// Split once
21342148
AddLogField();
2135-
_logFields.Last().text = _logTextStore.TrimStart('\n');
2149+
_logFields.Last().text = logText.TrimStart('\n');
21362150
_vertexCount = vertexCountStored;
21372151
}
21382152

2139-
// Otherwise, simply append the stored logs to the current logs
2153+
// Otherwise, simply append the log text to the current logs
21402154
else
21412155
{
2142-
_logFields.Last().text += _logTextStore;
2156+
_logFields.Last().text += logText;
21432157
_vertexCount += vertexCountStored;
21442158
}
21452159

2146-
_logTextStore = string.Empty;
2160+
// Refresh the UI, so that the text re-positions nicely
21472161
RebuildLayout();
21482162
}
21492163

0 commit comments

Comments
 (0)