On 20/03/16 8:49 PM, stunaep wrote:
The gc throws invalid memory errors if I use Arrays from std.container.
For example, this throws an InvalidMemoryOperationError:
import std.stdio;
import std.container;

void main() {
    new Test();
}

class Test {

    private Array!string test = Array!string();

    this() {
        test.insert("test");
        writeln(test[0]);
    }
}

and here's the stack trace

    testt.exe!app.onInvalidMemoryOperationError( void* _param_0 ) Line
21    D
    
testt.exe!_D2gc2gc2GC134__T9runLockedS57_D2gc2gc2GC11removeRangeMFNbNiPvZ2goFNbNiPS2gc2gc3GcxPvZvS19_D2gc2gc9otherTimelS19_D2gc2gc9numOtherslTPS2gc2gc3GcxTPvZ9runLockedMFNbNiKPS2gc2gc3GcxKPvZv()
+ 0x52 bytes    D
    testt.exe!_D2gc2gc2GC11removeRangeMFNbNiPvZv() + 0x29 bytes    D
    testt.exe!gc_removeRange() + 0x21 bytes    D
    testt.exe!_D4core6memory2GC11removeRangeFNbNixPvZv() + 0xd bytes    D
    testt.exe!std.container.array.Array!string.Array.Payload.~this()
Line 229 + 0x1f bytes    D
    
testt.exe!object._destructRecurse!(std.container.array.Array!string.Array.Payload)._destructRecurse(
std.container.array.Array!string.Array.Payload* s ) Line 2409 + 0xd
bytes    D
    
testt.exe!object.destroy!(std.container.array.Array!string.Array.Payload).destroy(
std.container.array.Array!string.Array.Payload* obj ) Line 2778 + 0xd
bytes    D
    
testt.exe!std.typecons.RefCounted!(std.container.array.Array!string.Array.Payload,
cast(RefCountedAutoInitialize)0).RefCounted.~this() Line 4864 + 0x10
bytes    D
    testt.exe!std.container.array.Array!string.Array.~this() Line 198
+ 0x15 bytes    D
    testt.exe!app.Test.~this() Line 10 + 0x19 bytes    D
    testt.exe!rt_finalize2() + 0xb8 bytes    D
    testt.exe!rt_finalizeFromGC() + 0x24 bytes    D
    testt.exe!_D2gc2gc3Gcx5sweepMFNbZm() + 0x3a3 bytes    D
    testt.exe!_D2gc2gc3Gcx11fullcollectMFNbbZm() + 0x57a bytes    D
    
testt.exe!_D2gc2gc2GC86__T9runLockedS56_D2gc2gc2GC18fullCollectNoStackMFNbZ2goFNbPS2gc2gc3GcxZmTPS2gc2gc3GcxZ9runLockedMFNbKPS2gc2gc3GcxZm()
+ 0x72 bytes    D
    testt.exe!_D2gc2gc2GC18fullCollectNoStackMFNbZv() + 0x11 bytes    D
    testt.exe!gc_term() + 0x14 bytes    D
    testt.exe!rt_term() + 0x9e bytes    D
    testt.exe!_D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZv() +
0x4d bytes    D
    testt.exe!_D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ7tryExecMFMDFZvZv() +
0x6f bytes    D
    testt.exe!_d_run_main() + 0x419 bytes    D
    testt.exe!__entrypoint.main( int argc, char** argv ) + 0x22
bytes    D
    testt.exe!__tmainCRTStartup() Line 255 + 0x12 bytes    D
    kernel32.dll!0000000076cd59cd
    ntdll.dll!0000000076f0b891

Not sure what to do here

That looks like an error indeed.
But move the initialization of Array into the constructor.

---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

Reply via email to