mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-01-23 17:43:08 -05:00
Fix immediate crashing
This commit is contained in:
parent
704dcebc46
commit
ee0e3dac02
1 changed files with 17 additions and 15 deletions
|
@ -158,8 +158,8 @@ namespace ClassicalSharp.Gui.Widgets {
|
|||
args.Font = (bit.ReducedLen & 0x8000) == 0 ? font : underlineFont;
|
||||
|
||||
int width = game.Drawer2D.MeasureSize(ref args).Width;
|
||||
if (args.Font != font && mouseX >= x && mouseX < x + width) {
|
||||
return new string(chars, bit.ReducedBeg, bit.ReducedLen);
|
||||
if (args.Font != font && mouseX >= x && mouseX < x + width) {
|
||||
return new string(chars, bit.ReducedBeg, bit.ReducedLen & 0x7FFF);
|
||||
}
|
||||
x += width;
|
||||
}
|
||||
|
@ -172,7 +172,7 @@ namespace ClassicalSharp.Gui.Widgets {
|
|||
|
||||
if (IDrawer2D.EmptyText(text)) {
|
||||
lines[index] = null;
|
||||
tex = default(Texture);
|
||||
tex = default(Texture);
|
||||
tex.Height = (ushort)(PlaceholderHeight[index] ? defaultHeight : 0);
|
||||
} else {
|
||||
lines[index] = text;
|
||||
|
@ -205,7 +205,7 @@ namespace ClassicalSharp.Gui.Widgets {
|
|||
Portion* portions = stackalloc Portion[(96 / 7) * 2];
|
||||
int portionsCount = Reduce(chars, index, portions);
|
||||
|
||||
Size total = Size.Empty;
|
||||
Size total = Size.Empty;
|
||||
Size* partSizes = stackalloc Size[portionsCount];
|
||||
|
||||
for (int i = 0; i < portionsCount; i++) {
|
||||
|
@ -242,13 +242,14 @@ namespace ClassicalSharp.Gui.Widgets {
|
|||
int left = len - i;
|
||||
if (left < 7) return -1; // "http://".Length
|
||||
|
||||
int start = i;
|
||||
// Starts with "http" ?
|
||||
if (chars[i + 1] != 't' || chars[i + 2] != 't' || chars[i + 3] != 'p') continue;
|
||||
left -= 4; i += 4;
|
||||
|
||||
// And then with "s://" or "://" ?
|
||||
if (chars[i] == 's') { left--; i++; }
|
||||
if (left >= 3 && chars[i] == ':' && chars[i + 1] == '/' && chars[i + 2] == '/') return i;
|
||||
if (left >= 3 && chars[i] == ':' && chars[i + 1] == '/' && chars[i + 2] == '/') return start;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
@ -283,14 +284,15 @@ namespace ClassicalSharp.Gui.Widgets {
|
|||
if (line == null) continue;
|
||||
|
||||
if (i == target) {
|
||||
lineBeg = total; lineLen = line.Length;
|
||||
lineEnd = lineBeg + lineEnd;
|
||||
lineBeg = total;
|
||||
lineLen = line.Length;
|
||||
lineEnd = lineBeg + lineLen;
|
||||
}
|
||||
total += line.Length;
|
||||
}
|
||||
|
||||
bit.Beg = mappings[bit.ReducedBeg];
|
||||
if (bit.Beg >= lineEnd) return;
|
||||
if (bit.Beg >= lineEnd || bit.ReducedLen == 0) return;
|
||||
|
||||
// Map back this reduced portion to original lines
|
||||
int end = bit.ReducedBeg + (bit.ReducedLen & 0x7FFF);
|
||||
|
@ -299,9 +301,9 @@ namespace ClassicalSharp.Gui.Widgets {
|
|||
|
||||
// Adjust this reduced portion to lie inside line we care about
|
||||
if (bit.Beg >= lineBeg) {
|
||||
} else if (bit.Beg + bit.Len > lineBeg) {
|
||||
// Clamp start of portion to lie in this line
|
||||
int underBy = (bit.Beg + bit.Len) - lineBeg;
|
||||
} else if (bit.Beg + bit.Len > lineBeg) {
|
||||
// Clamp start of portion to lie in this line
|
||||
int underBy = lineBeg - bit.Beg;
|
||||
bit.Beg += underBy; bit.Len -= underBy;
|
||||
} else {
|
||||
return;
|
||||
|
@ -312,14 +314,14 @@ namespace ClassicalSharp.Gui.Widgets {
|
|||
if (overBy > 0) bit.Len -= overBy;
|
||||
|
||||
bit.Beg -= lineBeg;
|
||||
if (bit.Len == 0) return;
|
||||
if (bit.Len == 0) return;
|
||||
*portions = bit; portions++;
|
||||
}
|
||||
|
||||
struct Portion { public int ReducedBeg, ReducedLen, Beg, Len; }
|
||||
unsafe int Reduce(char* chars, int target, Portion* portions) {
|
||||
ushort* mappings = stackalloc ushort[lines.Length * 96];
|
||||
Portion* portionsStart = portions;
|
||||
Portion* start = portions;
|
||||
int count = 0;
|
||||
|
||||
for (int i = 0, offset = 0; i < lines.Length; i++) {
|
||||
|
@ -350,8 +352,8 @@ namespace ClassicalSharp.Gui.Widgets {
|
|||
bit = default(Portion); bit.ReducedBeg = nextUrlStart;
|
||||
bit.ReducedLen = (urlEnd - nextUrlStart) | 0x8000;
|
||||
Output(bit, mappings, count, target, lines, ref portions);
|
||||
}
|
||||
return (int)(portions - portionsStart);
|
||||
}
|
||||
return (int)(portions - start);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue