JBenda / inkcpp

Inkle Ink C++ Runtime with JSON>Binary Compiler
MIT License
70 stars 13 forks source link

Crash with Tags #53

Closed sandiz closed 2 years ago

sandiz commented 2 years ago

Hey guys, I am seeing a crash with tags that happen when I add a bunch of them. Any ideas why this is happening ?

Ink FIle

->test_knot
===test_knot
line 110#loc:loc-line-1#in#op:1#cl:1
line 2#loc:loc-line-2#en#op:1#cl:1
line 3#loc:loc-line-3#in#op:1#cl:1
->DONE

Test case

SCENARIO("tags")
{
    inklecate("ink/AHF.ink", "AHF.tmp");
    ink::compiler::run("AHF.tmp", "AHF.bin");
    auto ink = story::from_file("AHF.bin");
    runner thread = ink->new_runner();

    thread->move_to(ink::hash_string("test_knot"));
    do
    {
        auto line = thread->getline();
        std::cout << line << std::endl;
    } while (thread->can_continue());

    REQUIRE(thread->can_continue() == false);

}

The test crashes with this ink file:

'inkcpp_test.exe' (Win32): Loaded 'D:\Projects\inkcpp\out\build\x64-Debug\inkcpp_test\inkcpp_test.exe'. Symbols loaded.
'inkcpp_test.exe' (Win32): Loaded 'C:\Windows\System32\ntdll.dll'. 
'inkcpp_test.exe' (Win32): Loaded 'C:\Windows\System32\kernel32.dll'. 
'inkcpp_test.exe' (Win32): Loaded 'C:\Windows\System32\KernelBase.dll'. 
'inkcpp_test.exe' (Win32): Loaded 'C:\Windows\System32\msvcp140d.dll'. 
'inkcpp_test.exe' (Win32): Loaded 'C:\Windows\System32\vcruntime140d.dll'. 
'inkcpp_test.exe' (Win32): Loaded 'C:\Windows\System32\vcruntime140_1d.dll'. 
'inkcpp_test.exe' (Win32): Loaded 'C:\Windows\System32\ucrtbased.dll'. 
The thread 0xb184 has exited with code 0 (0x0).
'inkcpp_test.exe' (Win32): Loaded 'C:\Windows\System32\sechost.dll'. 
'inkcpp_test.exe' (Win32): Loaded 'C:\Windows\System32\rpcrt4.dll'. 
Exception thrown at 0x00007FFD33A64FD9 in inkcpp_test.exe: Microsoft C++ exception: std::runtime_error at memory location 0x000000E566B0D570.
Exception thrown at 0x00007FFD33A64FD9 in inkcpp_test.exe: Microsoft C++ exception: [rethrow] at memory location 0x0000000000000000.
Exception thrown at 0x00007FFD33A64FD9 in inkcpp_test.exe: Microsoft C++ exception: std::runtime_error at memory location 0x000000E566B0D570.
Exception thrown at 0x00007FFD33A64FD9 in inkcpp_test.exe: Microsoft C++ exception: std::runtime_error at memory location 0x000000E566B08C10.
'inkcpp_test.exe' (Win32): Loaded 'C:\Windows\System32\kernel.appcore.dll'. 
'inkcpp_test.exe' (Win32): Loaded 'C:\Windows\System32\msvcrt.dll'. 
The thread 0xafa4 has exited with code 1 (0x1).
The thread 0x871c has exited with code 1 (0x1).
The program '[42160] inkcpp_test.exe' has exited with code 1 (0x1).

Note: removing any single tag from line110 fixes the issue, so it could be an issue with memory size ?

Let me know if you guys can repro this on your end.

Many thanks!

sandiz commented 2 years ago

Sorry for the false alarm y'all: found this config while looking further

    static constexpr int limitActiveTags = 10;

bumping this to -10 fixes the issue.

JBenda commented 2 years ago

yea, the minimal heap memory has its caviats, we should probaly make -10 the default ...

BorutPfeifer commented 1 year ago

So I'm still getting a crash with this example... I had a simple example with one tag, like #character:name and that was crashing until I found the limitactivetags and tried, which fixed my simple tag example. But it wasn't actually getting the tag string correctly (typically empty), even though it wasn't crashing.

So I went back and tried the example here, and it crashes the same spot in restorable.h

        template<typename IsNullPredicate>
        const ElementType& pop(IsNullPredicate isNull)
        {
            // Make sure we have something to pop
            inkAssert(_pos > 0, "Can not pop. No elements to pop!");
JBenda commented 1 year ago

I tested it with the current Master, it works ??, have you changed something as described above?

config file

    /// number of simultaneous active tags
    static constexpr int limitActiveTags = -10;

Ink File

->test_knot
===test_knot
line 110#loc:loc-line-1#in#op:1#cl:1
line 2#loc:loc-line-2#en#op:1#cl:1
line 3#loc:loc-line-3#in#op:1#cl:1
->DONE

TestCase

SCENARIO("tags", "[tags]")
{
    inklecate("ink/AHF.ink", "AHF.tmp");
    ink::compiler::run("AHF.tmp", "AHF.bin");
    auto ink = story::from_file("AHF.bin");
    runner thread = ink->new_runner();
    thread->move_to(ink::hash_string("test_knot"));
    while(thread->can_continue()) {
        auto line = thread->getline();
        std::cout << line << std::endl;
        for ( ink::size_t i = 0; i < thread->num_tags(); ++i) {
            std::cout << "\t" << thread->get_tag(i) << std::endl;
        }
    }
    REQUIRE(thread->can_continue() == false);
}

Output

➜ inkcpp_test (master) ✗ ./inkcpp_test '[tags]' 
Filters: [tags]
line 110

    loc:loc-line-1
    in
    op:1
    cl:1
line 2

    loc:loc-line-1
    in
    op:1
    cl:1
    loc:loc-line-2
    en
    op:1
    cl:1
line 3

    loc:loc-line-1
    in
    op:1
    cl:1
    loc:loc-line-2
    en
    op:1
    cl:1
    loc:loc-line-3
    in
    op:1
    cl:1
===============================================================================
All tests passed (27 assertions in 2 test cases)