Immediate-Mode-UI / Nuklear

A single-header ANSI C immediate mode cross-platform GUI library
https://immediate-mode-ui.github.io/Nuklear/doc/index.html
Other
9.08k stars 544 forks source link

Bus Error #491

Closed shabman closed 6 months ago

shabman commented 2 years ago

Hi, I am new to Nuklear and when I use the demo code I get a Bus Error.

The documentation isn't very clear for newcomers.

Steps to reproduce error:


#include <iostream>

#define NK_IMPLEMENTATION

#define NK_INCLUDE_DEFAULT_ALLOCATOR
#define NK_INCLUDE_STANDARD_IO

#define NK_INCLUDE_FIXED_TYPES
#define NK_INCLUDE_DEFAULT_FONT
#define NK_INCLUDE_FONT_BAKING
#define NK_BUTTON_TRIGGER_ON_RELEASE
#define NK_ZERO_COMMAND_MEMORY
#define NK_UINT_DRAW_INDEX

#include "./ui/nuklear.h"

int main() {
     struct nk_user_font uf;
    /* init gui state */
    struct nk_context ctx;
    nk_style_set_font(&ctx, &uf);
    nk_init_fixed(&ctx, calloc(1, 1024), 1024, &uf);

    enum {EASY, HARD};
    static int op = EASY;
    static float value = 0.6f;
    static int i =  20;

    if (nk_begin(&ctx, "Show", nk_rect(50, 50, 220, 220),
        NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_CLOSABLE)) {
        /* fixed widget pixel width */
        nk_layout_row_static(&ctx, 30, 80, 1);
        if (nk_button_label(&ctx, "button")) {
            /* event handling */
        }

        /* fixed widget window ratio width */
        nk_layout_row_dynamic(&ctx, 30, 2);
        if (nk_option_label(&ctx, "easy", op == EASY)) op = EASY;
        if (nk_option_label(&ctx, "hard", op == HARD)) op = HARD;

        /* custom widget pixel width */
        nk_layout_row_begin(&ctx, NK_STATIC, 30, 2);
        {
            nk_layout_row_push(&ctx, 50);
            nk_label(&ctx, "Volume:", NK_TEXT_LEFT);
            nk_layout_row_push(&ctx, 110);
            nk_slider_float(&ctx, 0, &value, 1.0f, 0.1f);
        }
        nk_layout_row_end(&ctx);
    }
    nk_end(&ctx);
}

Output:

zsh: bus error  ./a.out

Specs:

MacBook Pro 2017 15 Inch Intel CPU 16GB RAM

macOS Monterey 12.5
ishaan-jaff commented 1 year ago

Are you using any external libraries? Are you compiling the code with any special flags? - Clerkie

RobLoach commented 6 months ago

Try compiling one of the SDL examples