Pointer problems, changing for no reasons

Begah via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jun 10 01:32:40 PDT 2016


On Friday, 10 June 2016 at 07:28:44 UTC, Begah wrote:
> On Thursday, 9 June 2016 at 19:00:42 UTC, cy wrote:
>> I can't help but notice that loadModel is not a static member 
>> function, yet you don't seem to call it with a Model object in 
>> your "get" function.
>>
>> Also have a look at std.typecons.RefCounted if you want 
>> reference counted data..
>
> loadModel is not a method, it is a function. Being a function 
> it doesn't have a 'this' so doesn't need to be called with an 
> object.
> Also, i tried using std.typecons.RefCounted but i didn't like 
> the lack of control i had over it ( refCount is private and 
> only has a getter method ).

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[];
	}
}

In the constructor, i copied the textures to the model's inner 
texture array, and for some reason this caused the problem.
So i needed to change to something like :

this.textures.length = textures.length;
foreach(i; 0..textures.length) {
	this.textures[i] = textures[i];
}


More information about the Digitalmars-d-learn mailing list