Well, I was coding something, and then I tested on Mac, and it worked.
Then I tested it on Android, and it worked.
Then I tested it on Mac again (without changing code, mind you), and it stopped working.
Puzzled, I threw lots of prints... And what happens, is that suddenly one particular EnterFrame event (that DOES NOT have even a remove function for it, since it is supposed to run 100% of the time until the program closes) stop running, while others remain working fine, also only happens on Mac.
How I figure, why?
Comments
1) ENTER_FRAME event was removed
2) object to which event was attaches, was garbage collected
if none of the above applies to you, then it sounds like a bug and in that case, could you show a simple test case when that happens?
Because if I could, I would discover why it happens, and would avoid it...
But I will see if GC is killing my stuff.
This is NOT the enterframe that stops, but when the if condition on it is reached, the OTHER one stops.
Thus I did this:
local function onEnterFrame()
print("logo enter frame start");
--[[if canSkip and audioEnded then
if logoChan then
logoChan = nil;
end
ended = true;
logoBmp:removeEventListener(Event.ENTER_FRAME, onEnterFrame);
logoBmp:removeEventListener(Event.TOUCHES_END, onTouchEnd);
print("logo ended");
end]]
print("logo enter frame end");
end
And the other enter frame, and this enter frame, remained triggering forever. As I expected.
Then I did this:
local function onEnterFrame()
print("logo enter frame start");
if canSkip and audioEnded then
--[[if logoChan then
logoChan = nil;
end
ended = true;
logoBmp:removeEventListener(Event.ENTER_FRAME, onEnterFrame);
logoBmp:removeEventListener(Event.TOUCHES_END, onTouchEnd);
print("logo ended");]]
end
print("logo enter frame end");
end
I was not expecting anything, yet, when canSkip and audioEnded become true... the other enterframe stops.
Now, why adding two lines (if canSkip and audioEnded then, end) stops another EnterFrame? WTF!
local function onEnterFrame()
print("logo enter frame start");
if audioEnded then
end
print("logo enter frame end");
end
breaks stuff.
local function onEnterFrame()
print("logo enter frame start");
if canSkip then
end
print("logo enter frame end");
end
don't break stuff.
audioEnded changes:
--- logo.lua: This file handles the Kidoteca logo
--- Author: Maurício Gomes
---
local SpriteUtils = require "engine.kidutils.spriteutils"
local system = {};
local logoBmp;
local logoWav;
local logoChan;
local logoTexture;
local canSkip = false;
local ended = false;
local audioEnded = false;
local function onAudioComplete() --triggered by logoChan:addEventListener(Event.COMPLETE, onAudioComplete);
audioEnded = true;
end
function system.Stop()
if logoChan then
logoChan = nil;
audioEnded = true;
end
stage:removeChild(logoBmp);
end
local function onTouchEnd( event )
if canSkip then
if logoChan then
logoChan:stop();
logoChan = nil;
end
audioEnded = true;
end
print("touch end");
event:stopPropagation();
end
Any of these 3 cases, as soon audioEnded is set to true, a unrelated onEnterFrame stops, but only if the audioEnded is checked on that if line I mentioned, and only on Mac (not on Device)
might the problem be, that you have same names for enter frames:
local function onEnterFrame()
and
logoBmp:removeEventListener(Event.ENTER_FRAME, onEnterFrame);
so when you remove one it actually removes the other one?
Also, commenting the removeEventListener do not fix the issue. the only way to fix the issue, is NOT put the variable "audioEnded" on the if clause.
and maybe something just have been cached or something like that, currently really have no idea what could have happened there
The events, movieclip, and timer might stopped, without telling any event completed.
I might know the reason already, it's because i used to much render process or something like that.
For example, i have a huge BG (1912 x 970) and other images present on the screen, i tried to tween 4 big images together (1356x 960 in my case) with movieclip, and if i tried another function/animation after that, somehow they would stop in the middle of the process.
This problem still present even now. Aslo... Might be because something wrong on my code.
@tkhnoman, Timers, UrlLoaders, SoundChannels and GTweens are never garbage collected while they're running. But this isn't the case for MovieClips. If a running movie clip is removed from the stage then it's eligible for GC (even it's running).
I assumed MovieClip is like a tween function when i used it as tweener.
That is why for example at this code:
local mc = MovieClip.new{
{1, 100, sprite, {x = {0, 200, "linear"}}}
}
i added sprite to the stage, but not the mc. That's why it was collected...
When i added mc at stage, it won't be collected.
Well, thanks for the help, and sorry for the trouble.
EDIT: When i'm using 2 MovieClip for one sprite, it become a hassle for the parenting stuff... So instead of adding the MovieClip to the stage, i just added it in a global table. It seems working and not being collected.
I changed nothing, and it stopped happening... So I cannot really reproduce it