#value is being mutated oddly

1 messages · Page 1 of 1 (latest)

pure nexus
#

how is t0 getting over written by t4's value?

#

im using raylib TextFormat function

#
const std = @import("std");
const print = std.debug.print;
const rl = @cImport(@cInclude("raylib.h"));

pub fn main() !void {
    const value: c_int = 255;
    const t0 = rl.TextFormat("Frames: %d/%d", value, value);
    const t1 = rl.TextFormat("Opacity: %d", value);
    const t2 = rl.TextFormat("r: %d", value);
    const t3 = rl.TextFormat("g: %d", value);
    const t4 = rl.TextFormat("b: %d", value);
    const t5 = rl.TextFormat("a: %d", value);
    print("{s} {s} {s} {s} {s} {s}\n", .{ t0, t1, t2, t3, t4, t5 });
}
#

build.zig

const std = @import("std");
pub fn build(b: *std.Build) void {
    const target = b.standardTargetOptions(.{});
    const optimize = b.standardOptimizeOption(.{});
    const lib = b.addStaticLibrary(.{
        .name = "testing",
        // In this case the main source file is merely a path, however, in more
        // complicated build scripts, this could be a generated file.
        .root_source_file = .{ .path = "src/root.zig" },
        .target = target,
        .optimize = optimize,
    });
    b.installArtifact(lib);
    const exe = b.addExecutable(.{
        .name = "testing",
        .root_source_file = .{ .path = "src/main.zig" },
        .target = target,
        .optimize = optimize,
    });
    exe.linkSystemLibrary("raylib");
    exe.linkSystemLibrary("c");
    b.installArtifact(exe);
    const run_cmd = b.addRunArtifact(exe);
    run_cmd.step.dependOn(b.getInstallStep());
    if (b.args) |args| {
        run_cmd.addArgs(args);
    }
    const run_step = b.step("run", "Run the app");
    run_step.dependOn(&run_cmd.step);
    const lib_unit_tests = b.addTest(.{
        .root_source_file = .{ .path = "src/root.zig" },
        .target = target,
        .optimize = optimize,
    });
    const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests);
    const exe_unit_tests = b.addTest(.{
        .root_source_file = .{ .path = "src/main.zig" },
        .target = target,
        .optimize = optimize,
    });
    const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests);
    const test_step = b.step("test", "Run unit tests");
    test_step.dependOn(&run_lib_unit_tests.step);
    test_step.dependOn(&run_exe_unit_tests.step);
}
#
#include <stdio.h>
#include "raylib.h"
int main(void) {
    int value = 255;
    char const * t0 = TextFormat("Frames: %d/%d", value, value);
    char const * t1 = TextFormat("Opacity: %d", value);
    char const * t2 = TextFormat("r: %d", value);
    char const * t3 = TextFormat("g: %d", value);
    char const * t4 = TextFormat("b: %d", value);
    char const * t5 = TextFormat("a: %d", value);
    printf("%s %s %s %s %s %s \n", t0, t1, t2, t3, t4, t5);

    return 0;
}
#

welp its just me.

#

i dont understand

#

same output in c which is good i suppose.

steep hearth
#

// WARNING: String returned will expire after this function is called MAX_TEXTFORMAT_BUFFERS times

pure nexus
#

yeah i seen that.....

#

I tried using std.fmt.allocPrint but then drawing the text its all jacked up!

stable solstice
#

Might want allocPrintZ

pure nexus
#

oh

stable solstice
#

Raylib wants a null terminated string IIRC

#

So like

#

That'll bite you if you don't have one

pure nexus
#

oh

#

and allocPrintZ creates them.

#

welp thanks!