Skip to content

[rtext] LoadFont() somehow distorts the memory of TextSplit() #4704

Closed
@AnkurMal

Description

@AnkurMal
  • I tested it on latest raylib version from master branch
  • I checked there is no similar issue already reported
  • I checked the documentation on the wiki
  • My code has no errors or misuse of raylib

Issue description

Essentially, the array of strings (splits) returned by TextSplit(), gets "garbage" value after I use it after loading a font using LoadFont().

Environment

HP 15s, Windows 11 24H2, Intel iRIS Xe

Code Example

#include "include/raylib.h"

int main(void) {
    int count;

    InitWindow(800, 450, "sample");

    char* data = "1.2.3.4";
    const char **spl = TextSplit(data, '.', &count);

    Font font = LoadFont("assets/font/font.ttf");
    for(int i=0; i<count; i++) printf("%s\n", spl[i]);

    SetTargetFPS(60);
    while (!WindowShouldClose()) {
        BeginDrawing();
            ClearBackground(BLACK);
        EndDrawing();
    }
    
    UnloadFont(font);
    CloseWindow();
    return 0;
}

here, if I put the line for(int i=0; i<count; i++) printf("%s\n", spl[i]); before Font font = LoadFont("assets/font/font.ttf");, it prints the output as it should be, i,e,

1
2
3
4

But if I put it after that, it produces garbage:

.ttf
tf

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions