Thread overview
In what situation can new Struct() return null?
May 10, 2019
faissaloo
May 10, 2019
Cym13
May 10, 2019
faissaloo
May 10, 2019
H. S. Teoh
May 11, 2019
faissaloo
May 11, 2019
Jonathan M Davis
May 10, 2019
My program contains the following statement:
    auto newChildNode = new Node();

In debugging I have found that this pointer evaluates to null, what could cause this? I should have plenty of memory, my only other idea is some sort of heap corruption.
May 10, 2019
On Friday, 10 May 2019 at 10:11:51 UTC, faissaloo wrote:
> My program contains the following statement:
>     auto newChildNode = new Node();
>
> In debugging I have found that this pointer evaluates to null, what could cause this? I should have plenty of memory, my only other idea is some sort of heap corruption.

Could you share a complete, concise, compilable example demonstrating that bug? One line is rather short to understand what's happening.
May 10, 2019
On Friday, 10 May 2019 at 12:19:29 UTC, Cym13 wrote:
> On Friday, 10 May 2019 at 10:11:51 UTC, faissaloo wrote:
>> My program contains the following statement:
>>     auto newChildNode = new Node();
>>
>> In debugging I have found that this pointer evaluates to null, what could cause this? I should have plenty of memory, my only other idea is some sort of heap corruption.
>
> Could you share a complete, concise, compilable example demonstrating that bug? One line is rather short to understand what's happening.

Unfortunately not, I can't seem to reproduce it outside my codebase.
May 10, 2019
On Fri, May 10, 2019 at 05:32:25PM +0000, faissaloo via Digitalmars-d-learn wrote:
> On Friday, 10 May 2019 at 12:19:29 UTC, Cym13 wrote:
> > On Friday, 10 May 2019 at 10:11:51 UTC, faissaloo wrote:
> > > My program contains the following statement:
> > >     auto newChildNode = new Node();
> > > 
> > > In debugging I have found that this pointer evaluates to null, what could cause this? I should have plenty of memory, my only other idea is some sort of heap corruption.
> > 
> > Could you share a complete, concise, compilable example demonstrating that bug? One line is rather short to understand what's happening.
> 
> Unfortunately not, I can't seem to reproduce it outside my codebase.

Perhaps try Dustmite on it?

AFAIK, calling new on a struct should never return null. So there must be something else not quite right here.  But without actual code it's anybody's guess as to what it might be.

The last time I heard somebody run into this, it was caused by some unrelated compiler codegen bug that left the CPU registers in an inconsistent state, thus causing an unrelated call to `new` to return the wrong value.  Perhaps you could try a different compiler to see if that makes a difference?


T

-- 
The fact that anyone still uses AOL shows that even the presence of options doesn't stop some people from picking the pessimal one. - Mike Ellis
May 11, 2019
On Friday, May 10, 2019 11:54:44 AM MDT H. S. Teoh via Digitalmars-d-learn wrote:
> On Fri, May 10, 2019 at 05:32:25PM +0000, faissaloo via Digitalmars-d-
learn wrote:
> > On Friday, 10 May 2019 at 12:19:29 UTC, Cym13 wrote:
> > > On Friday, 10 May 2019 at 10:11:51 UTC, faissaloo wrote:
> > > > My program contains the following statement:
> > > >     auto newChildNode = new Node();
> > > >
> > > > In debugging I have found that this pointer evaluates to null, what could cause this? I should have plenty of memory, my only other idea is some sort of heap corruption.
> > >
> > > Could you share a complete, concise, compilable example demonstrating that bug? One line is rather short to understand what's happening.
> >
> > Unfortunately not, I can't seem to reproduce it outside my codebase.
>
> Perhaps try Dustmite on it?
>
> AFAIK, calling new on a struct should never return null. So there must be something else not quite right here.  But without actual code it's anybody's guess as to what it might be.

If the GC fails to allocate, it will throw an OutOfMemoryError. So, new should never return null. I have no clue what could be happening in this case.

- Jonathan M Davis



May 11, 2019
On Friday, 10 May 2019 at 17:54:44 UTC, H. S. Teoh wrote:
> Perhaps try Dustmite on it?
>
> AFAIK, calling new on a struct should never return null. So there must be something else not quite right here.  But without actual code it's anybody's guess as to what it might be.
>
> The last time I heard somebody run into this, it was caused by some unrelated compiler codegen bug that left the CPU registers in an inconsistent state, thus causing an unrelated call to `new` to return the wrong value.  Perhaps you could try a different compiler to see if that makes a difference?
>
>
> T

I've tried a number of different compilers and the issue persists, I think the issue is the garbage collector. This issue did have spontaneously disappear but generally with my project there seem to be a number of memory corruption issues that as far as I can tell, shouldn't be happening. I've submitted a bug report here: https://issues.dlang.org/show_bug.cgi?id=19860