mirror of
https://github.com/PixelGuys/Cubyz.git
synced 2025-09-12 14:01:59 -04:00
Fix undefined behavior in text rendering (TextBuffer.width was initialized with undefined and never changed for draw.print)
(hopefully) finally fixes #595
This commit is contained in:
parent
c297fe0dfc
commit
bd5ea763cb
@ -782,8 +782,14 @@ pub const TextBuffer = struct { // MARK: TextBuffer
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub fn init(allocator: NeverFailingAllocator, text: []const u8, initialFontEffect: FontEffect, showControlCharacters: bool, alignment: Alignment) TextBuffer {
|
pub fn init(allocator: NeverFailingAllocator, text: []const u8, initialFontEffect: FontEffect, showControlCharacters: bool, alignment: Alignment) TextBuffer {
|
||||||
var self: TextBuffer = undefined;
|
var self: TextBuffer = .{
|
||||||
self.alignment = alignment;
|
.alignment = alignment,
|
||||||
|
.width = 1e9,
|
||||||
|
.buffer = null,
|
||||||
|
.glyphs = &.{},
|
||||||
|
.lines = .init(allocator),
|
||||||
|
.lineBreaks = .init(allocator),
|
||||||
|
};
|
||||||
// Parse the input text:
|
// Parse the input text:
|
||||||
var parser = Parser{
|
var parser = Parser{
|
||||||
.unicodeIterator = std.unicode.Utf8Iterator{.bytes = text, .i = 0},
|
.unicodeIterator = std.unicode.Utf8Iterator{.bytes = text, .i = 0},
|
||||||
@ -796,12 +802,9 @@ pub const TextBuffer = struct { // MARK: TextBuffer
|
|||||||
defer parser.fontEffects.deinit();
|
defer parser.fontEffects.deinit();
|
||||||
defer parser.parsedText.deinit();
|
defer parser.parsedText.deinit();
|
||||||
defer parser.characterIndex.deinit();
|
defer parser.characterIndex.deinit();
|
||||||
self.lines = .init(allocator);
|
|
||||||
self.lineBreaks = .init(allocator);
|
|
||||||
parser.parse();
|
parser.parse();
|
||||||
if(parser.parsedText.items.len == 0) {
|
if(parser.parsedText.items.len == 0) {
|
||||||
self.lineBreaks.append(.{.index = 0, .width = 0});
|
self.lineBreaks.append(.{.index = 0, .width = 0});
|
||||||
self.glyphs = &[0]GlyphData{};
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user