Pointer problems, changing for no reasons

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jun 10 01:43:57 PDT 2016


On 06/10/2016 01:32 AM, Begah wrote:

 > I have found the problem and i still don't understand why i was a 
problem :
 > struct Model
 > {
 >     TextureType[] textures;
 >
 >     this(TextureType[] textures...) {
 >         this.textures = textures[];
 >     }
 > }

Yeah, that's a bug because the argument array is on the stack and has a 
short lifetime. (I wish the compiler would warn about that.) As a 
result, this.textures is now a reference to elements that are destroyed 
upon constructor exit.

I have some more explanation of it under the "Variadic function 
arguments have a short lifetime" section here:

   http://ddili.org/ders/d.en/parameter_flexibility.html

Ali



More information about the Digitalmars-d-learn mailing list