not-fl3 / macroquad

Cross-platform game engine in Rust.
Apache License 2.0
3.27k stars 317 forks source link

cache_glyph() fails with large text #750

Open AdamSlayer opened 3 months ago

AdamSlayer commented 3 months ago

The same happens with measure_text() and populate_font_cache(), problem is in the cache_glyph() function. Minimal reproduction:

use macroquad::text::measure_text;

#[macroquad::main("test")]
async fn main() {
    measure_text("place the entry portal", None, 358, 1.0);
}

358 is the exact value, it works fine with 357. When called more than once, it will fail even with smaller values:

use macroquad::text::measure_text;

#[macroquad::main("test")]
async fn main() {
    measure_text("place the entry portal", None, 200, 1.0);
    measure_text("place the entry portal", None, 201, 1.0);
    measure_text("place the entry portal", None, 202, 1.0);
}

The size at which is starts failing also depends on the text, for example, for "text", it starts to fail at 581 text size.

use macroquad::text::measure_text;

#[macroquad::main("test")]
async fn main() {
    measure_text("text", None, 581, 1.0);
}