Bug 18313 – Default initializer for class isn't always called
Status
RESOLVED
Resolution
DUPLICATE
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2018-01-27T13:38:47Z
Last change time
2019-11-24T12:00:12Z
Assigned to
No Owner
Creator
skocznymr
Comments
Comment #0 by skocznymr — 2018-01-27T13:38:47Z
When working with dlib library (gamedev oriented library) I've noticed a strange behaviour, which seems unexpected to me:
For this example code (add "dlib": "~>0.12.2" to dub dependency to build):
import std.stdio;
import dlib.math;
class Foo
{
Matrix4f mat1;
Matrix4f mat2 = Matrix4f.zero();
Quaternionf q1;
Quaternionf q2 = Quaternionf.identity();;
}
void main()
{
Foo foo = new Foo();
writeln(foo.mat1);
writeln(foo.mat2);
writeln(foo.q1);
writeln(foo.q2);
Matrix4f mat3;
Matrix4f mat4 = Matrix4f.zero();
writeln(mat3);
writeln(mat4);
}
The expectation is that foo.mat2 gets initialized to Matrix4f.zero() value, just like it works with foo.q2 and mat4 variable. But for some reason, foo.mat2 stays uninitialized (filled with NaNs rather than zeroes).
Comment #1 by skocznymr — 2019-11-24T12:00:12Z
*** This issue has been marked as a duplicate of issue 15205 ***