www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Unknown bug disallows growth of dynamic arrays

reply solidstate1991 <laszloszeremi outlook.com> writes:
Here's the offending function: 
https://github.com/ZILtoid1991/collections-d/blob/master/source/collections/sortedlist.d#L38

It causes to throw an exception with `Access violation reading 
location` and a memory address, int the function 
`_d_arraysetlengthT`. Variable `ti` is a TypeInfo_Array, `value` 
of this object is null.

Error happens when adding a sprite in this class: 
https://github.com/ZILtoid1991/pixelperfectengine/blob/master/pixelperfecteditor/src/app.d#L64
However, the same doesn't happen when the editor is being run.

Since leaving out any addition of sprites causes errors 
elsewhere, I was thinking that it might be a memory leakage 
issue. Could memory leakage cause such errors when attempting to 
grow or shrink arrays?
Jun 28
next sibling parent reply frame <frame86 live.com> writes:
On Monday, 28 June 2021 at 20:55:44 UTC, solidstate1991 wrote:
 Here's the offending function: 
 https://github.com/ZILtoid1991/collections-d/blob/master/source/collections/sortedlist.d#L38

 It causes to throw an exception with `Access violation reading 
 location` and a memory address, int the function 
 `_d_arraysetlengthT`. Variable `ti` is a TypeInfo_Array, 
 `value` of this object is null.

 Error happens when adding a sprite in this class: 
 https://github.com/ZILtoid1991/pixelperfectengine/blob/master/pixelperfecteditor/src/app.d#L64
 However, the same doesn't happen when the editor is being run.

 Since leaving out any addition of sprites causes errors 
 elsewhere, I was thinking that it might be a memory leakage 
 issue. Could memory leakage cause such errors when attempting 
 to grow or shrink arrays?
Hmm.. have you enabled bounds checking? The SpriteLayer.addSprite() method accepts ushort. That's max. 65535. You supply 65_536. You may have similiar errors in your code.
Jun 28
parent frame <frame86 live.com> writes:
On Monday, 28 June 2021 at 21:45:05 UTC, frame wrote:

 The SpriteLayer.addSprite() method accepts ushort. That's max. 
 65535. You supply 65_536.
Ah I mixed the argumets, forget that. However, your comment //ocd.objects[65_536] may also I hint that you try to access elements that are not there.
Jun 28
prev sibling parent solidstate1991 <laszloszeremi outlook.com> writes:
On Monday, 28 June 2021 at 20:55:44 UTC, solidstate1991 wrote:
 Here's the offending function: 
 https://github.com/ZILtoid1991/collections-d/blob/master/source/collections/sortedlist.d#L38

 It causes to throw an exception with `Access violation reading 
 location` and a memory address, int the function 
 `_d_arraysetlengthT`. Variable `ti` is a TypeInfo_Array, 
 `value` of this object is null.

 Error happens when adding a sprite in this class: 
 https://github.com/ZILtoid1991/pixelperfectengine/blob/master/pixelperfecteditor/src/app.d#L64
 However, the same doesn't happen when the editor is being run.

 Since leaving out any addition of sprites causes errors 
 elsewhere, I was thinking that it might be a memory leakage 
 issue. Could memory leakage cause such errors when attempting 
 to grow or shrink arrays?
It seems I could solve the issue with the reserve() function, and it occurred twice so far. I often have to disable bounds checking, since it takes up precious CPU cycles, instead I do it in an "at once" fashion rather than per-index access, and need to be done in such fashion with the graphics rendering functions I made.
Jul 01