What a nice bug!

Denis Koroskin 2korden at gmail.com
Mon May 18 04:52:49 PDT 2009

After a *very* small refactoring which only involved a class and a corresponding file rename, I got a strange bug that prints "object.Error: Access Violation" and hangs my GUI application.
After 2 hours of tracking an issue, I could find the following code (highly modified to reduce its size as much as possible):

final void startMonitoring()
    _monitorInfos.length = _monitorInfos.length + 1; // removing this makes issue disappear

    char[] buffer = null;
    buffer.length = 4096;

Note that even though buffer is unused (anymore), it is what causes an AV and a hang.
The funny thing is that if you change "buffer.length = 4096;" to "buffer.length = 4095;", the bug goes away!

Since I got no stack trace from an Exception, I have no idea where it comes from, but it definitely crashes somewhere else.
Even after tracking this far, it's still a lot of code to post (500+ Kb of D source code), so I'm trying to reduce it even further. Problem is, changing nearly anything leads to either another crash or problem disappears. For example, there is dummy thread now that does completely nothing (I removed all of its references and functionality while tracking it down):

void run()
    while (true) {

Thread mainThread = new Thread(&run);

But if I remove this thread (comment out the "mainThread.start()" or make run() empty), it leads to crash in some other part of program - a GUI code (An exception was thrown while finalizing an instance of class ui.control.impl.win32.Win32FormImpl.Win32FormImpl - object.Error: Access Violation). I don't know what the hell it is either, and trying to hunt it.

P.S. DMD2.030 + Phobos

More information about the Digitalmars-d mailing list