4coder » Forums » Crash With Basic Custom Keybindings File (4.0.29)
yyam
2 posts
#16868 Crash With Basic Custom Keybindings File (4.0.29)
2 weeks, 4 days ago Edited by yyam on Nov. 27, 2018, 6:46 p.m.

Hey there, I just downloaded 4coder (v4.0.29) and I'm trying to mess around with some custom key bindings. I ran into a problem pretty early on, I feel like I'm missing something. I'd appreiciate if anyone can help me get this working!

I was following this tutorial and got a basic file set up:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "4coder_default_include.cpp"

CUSTOM_COMMAND_SIG(hello_world_test)
{
    print_message(app, "Hello World.", sizeof( "Hello World." ) - 1);
}

void
test_keys(
    Bind_Helper *context)
{
    begin_map(context, mapid_global);
    {
        bind(context, 'x', MDFR_ALT, command_lister);
        bind(context, 'p', MDFR_CTRL, hello_world_test);
    }
    end_map(context);
}

#if !defined(NO_BINDING)
extern "C" int32_t
get_bindings(void *data, int32_t size){
    Bind_Helper context_ = begin_bind_helper(data, size);
    Bind_Helper *context = &context_;

    set_all_default_hooks(context);
#if defined(__APPLE__) && defined(__MACH__)
    mac_default_keys(context);
#else
    test_keys(context);
#endif

    int32_t result = end_bind_helper(context);
    return(result);
}
#endif //NO_BINDING


I build with buildsuper.bat and run 4ed.exe and it crashes before a window is created. It's worth noting that the editor works fine if I build the default key bindings.

I did a little investigation and found that it was crashing on a release mode assert in 4coder_default_hooks.cpp. I think this was the line:
1
Assert(map_id_query == default_lister_ui_map);


I realised that if I remove the call to set_all_default_hooks(context); in get_bindings, then this code path doesn't get triggered and the editor launches , albeit without any features :p However when I open the command lister (ALT-x in my bindings) it crashes.

I did find this thread with a similar problem to mine but I seem to already have the suggested fix in my code.

So now I'm out of ideas. I feel like I'm doing something stupid. (or stupidly forgetting something!)
yyam
2 posts
#16869 Crash With Basic Custom Keybindings File (4.0.29)
2 weeks, 4 days ago

Solved. (thanks to the very helpful people on the discord server)

In case anyone finds this thread, check out this pastebin for the notes that helped solve the issue. For reference, here's the working file: (4.0.29 requires a few maps to be present)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "4coder_default_include.cpp"

CUSTOM_COMMAND_SIG(hello_world_test)
{
    print_message(app, "Hello World.\n", sizeof( "Hello World.\n" ) - 1);
}

void
test_keys(
    Bind_Helper *context)
{
    begin_map(context, default_lister_ui_map);
    bind_vanilla_keys(context, lister__write_character);
    bind(context, key_esc, MDFR_NONE, lister__quit);
    bind(context, '\n', MDFR_NONE, lister__activate);
    bind(context, '\t', MDFR_NONE, lister__activate);
    bind(context, key_back, MDFR_NONE, lister__backspace_text_field);
    bind(context, key_up, MDFR_NONE, lister__move_up);
    bind(context, key_page_up, MDFR_NONE, lister__move_up);
    bind(context, key_down, MDFR_NONE, lister__move_down);
    bind(context, key_page_down, MDFR_NONE, lister__move_down);
    bind(context, key_mouse_wheel, MDFR_NONE, lister__wheel_scroll);
    bind(context, key_mouse_left, MDFR_NONE, lister__mouse_press);
    bind(context, key_mouse_left_release, MDFR_NONE, lister__mouse_release);
    bind(context, key_mouse_move, MDFR_NONE, lister__repaint);
    bind(context, key_animate, MDFR_NONE, lister__repaint);
    end_map(context);

    begin_map(context, mapid_global);
    bind(context, 'x', MDFR_ALT, command_lister);
    bind(context, 'p', MDFR_CTRL, hello_world_test);
    end_map(context);

    begin_map(context, mapid_file);
    end_map(context);

    begin_map(context, default_code_map);
    inherit_map(context, mapid_file);
    end_map(context);
}

#if !defined(NO_BINDING)
extern "C" int32_t
get_bindings(void *data, int32_t size){
    Bind_Helper context_ = begin_bind_helper(data, size);
    Bind_Helper *context = &context_;

    set_all_default_hooks(context);
#if defined(__APPLE__) && defined(__MACH__)
    mac_default_keys(context);
#else
    test_keys(context);
#endif

    int32_t result = end_bind_helper(context);
    return(result);
}
#endif //NO_BINDING
mrmixer
Simon Anciaux
491 posts
#16872 Crash With Basic Custom Keybindings File (4.0.29)
2 weeks, 4 days ago Edited by Simon Anciaux on Nov. 27, 2018, 7:34 p.m. Reason: typo

I updated the "Getting started" post with those information. I intended to do it sooner but I completely forgot.