Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Runtime Listener still running...
Started by d.mach Jul 07 2017 03:14 AM

4 replies to this topic
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

d.mach

[GLOBAL: userInfoPane.html]
d.mach
  • Contributor

  • 832 posts
  • Corona SDK

I am calling Runtime:addEventListener("enterFrame",map.updateView) and then remove the listener with scene change: Runtime:removeEventListener("enterFrame",map.updateView)

 

BUT when not moving to a new level and instead trying to play the same level again I have the problem the listener seems to be still running and trying to update, but I then get a Runtime Error because the camera object is NIL

 

I am working with an empty scene between scene changes, so I thought this will "delete" my old level scene in all cases, even when calling the same level again... BUT somehow there seems to be something left running here.

 

I have looked into all the composer details and I think maybe this has to do with the runtime listener in dusk?

 

Anyone have heard about this kind of problem maybe?

 



[TOPIC: post.html]
#2

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,535 posts
  • Enterprise

There are two possibilities I can think  of.

 

1. The value of map.updateView changed between the time you added the listener and the time you're removing it. 

2. When you are removing it, map is unknown. This could be a scoping issue.  Consider:

local map = {}

local function endScene()
       Runtime:removeEventListener("enterFrame",map.updateView)  --<------ map.updateView is currently nil
end

function map.updateView()
    -- do stuff
end

local function startScene()
     Runtime:addEventListener("enterFrame",map.updateView)  --<------ map.updateView has a value now
end

To remove a listener both the type, i.e. "enterFrame" and the address of the function must match what was used when the event handler was created. In this case you're saying:  Look up the "enterFrame" nil function to remove. It can't find it in it's table since it's not there. What's in the table is "enterFrame", 0x98AB4201 (made up memory address for example). And it can't remove it.

 

Rob



[TOPIC: post.html]
#3

d.mach

[GLOBAL: userInfoPane.html]
d.mach
  • Contributor

  • 832 posts
  • Corona SDK

Thank you Rob for your fast help! I appreciate it!

I will look into this asap.



[TOPIC: post.html]
#4

SGS

[GLOBAL: userInfoPane.html]
SGS
  • Corona Geek

  • 2,017 posts
  • Corona SDK

Assuming you want to call the map class externally then this is a more robust implementation

local map = {}

local function map:enterFrame()
    -- do stuff
end

function map:endScene()
    Runtime:removeEventListener("enterFrame", self)
end


function map:startScene()
    Runtime:addEventListener("enterFrame", self)
end


[TOPIC: post.html]
#5

Caleb P

[GLOBAL: userInfoPane.html]
Caleb P
  • Corona Geek

  • 1,424 posts
  • Corona SDK

map.updateView is an object method and as such must be called with a colon; that means you'll need some sort of closure:

local enterFrameListener = function(event)
  map:updateView()
end

-- scene create
Runtime:addEventListener("enterFrame", enterFrameListener)

-- scene remove
Runtime:removeEventListener("enterFrame", enterFrameListener)

Most of the time, map:updateView() is put inside the game-wide enter frame loop. Try that and see if it fixes it.

 

- Caleb




[topic_controls]
[/topic_controls]