Slice in Utils.removeValueFromArray

mackaliciouz

  • Posts: 13
You probably clear the engine listeners at the switch of a scene, which is good, because otherwise you'd have a major problem with this bug I just found:

Utils.removeValueFromArray does absolutely nothing at this stage but copying the value passed into empty space. You need to change:

Code: [Select]
...
if(arr[i] == value)
{
       arr.slice(i, 1);
}
...

to:

Code: [Select]
...
if(arr[i] == value)
{
       arr.splice(i, 1);
}
...

Notice that you need to splice to actually remove an element, whereas slice simply returns that element (or range of elements).

Photon

  • Posts: 2691
Are you having problems with the remove element blocks for lists? Because neither of those make calls to the above function.
Do NOT PM me your questions, because I likely will not respond. If I have replied to your question on the forum, keep using that topic. Thanks!

mackaliciouz

  • Posts: 13
I'm talking about the Stencyl engine. Actor.hx calls this function under removeAllListeners(). Pretty major (to me) that this function actually does not remove any listeners which may cause big memory problems in bigger scenes with a lot of characters created then disposed.

I changed this and the problem was solved for me, so I'm not looking for a solution. I'm simply reporting and trying to contribute to a better engine since this may cause problems for others in terms of memory, being a function used in a vital part of the engine.

Jon

  • *
  • Posts: 17524
Thanks for reporting this. I can't say I've seen the consequences of this happen openly, even in some big games (and it'll get cleared out on scene switches), but it's definitely a typo that slipped under the radar.

I've checked it in provisionally - hopefully no crashes or things of the like happen because of it. It's a valid fix, but sometimes you never know what happens down the wire - a properly disposed listener may end up generating a null exception somewhere else.

liteking

  • Posts: 103
Does this relate to my problem here?:
http://community.stencyl.com/index.php/topic,30000.msg172169.html#msg172169
Anyway, I'm downloading the latest build right now.
Many thanks :)

liteking

  • Posts: 103
After downloading the newest build, my project can not be opened.
Stencyl shows these error, then it "Openning" forever
Code: [Select]
HueShader (46) -  Unknown identifier
HueShader (46) -  Unknown identifier
HueShader (46) -  Invalid assign
Long ago I had an actor behavior that changes hue value. But I'm sure I deleted it long time ago.

Jon

  • *
  • Posts: 17524

liteking

  • Posts: 103
Thanks Jon, I can build my project now

out2lunch

  • Posts: 118
Examining that function more closely, the first time it checks arr it's out of bounds, no?
Shouldn't it be  var i:Int = len - 1;
Code: [Select]
var len:Int = arr.length;
var i:Int = len;
while(i > -1)
{
if(arr[i] == value)
{
arr.splice(i, 1);
}
i--;
}

Same goes for contains below it:
Code: [Select]
public static function contains(arr:Array<Dynamic>, value:Dynamic):Bool
{
var len:Int = arr.length;
var i:Int = len;
while(i > -1)
{
if(arr[i] == value)
{
return true;
}
i--;
}
return false;
}
Clacky Train has been released worldwide on the App Store!
Voodoo Zombie's 1.4.1 update has more bosses and magic items on the App Store!
Here's the Launch Trailer on YouTube.

Jon

  • *
  • Posts: 17524
Yes, that would be correct.

Did anything in practice clue you in to this?

out2lunch

  • Posts: 118
No I haven't had any problems with it yet, I've just got an eagle eye for those types of bugs.  ;D

In theory it'd be rare that an out of bounds value, which would be something else's memory, could actually match what it's checking against.  But you really don't want to have to track down out of bounds array bugs, they're a nightmare.

Big thanks to mackaliciouz for finding the splice bug!  Go team!

« Last Edit: April 11, 2014, 02:43:35 am by out2lunch »
Clacky Train has been released worldwide on the App Store!
Voodoo Zombie's 1.4.1 update has more bosses and magic items on the App Store!
Here's the Launch Trailer on YouTube.

Jon

  • *
  • Posts: 17524
Checked in to SVN. Thanks again!