RESOLVED: Director + coroutines?

My app is polling a UDP socket, which I’m trying to thread with a coroutine. Everything works fine until director changes scenes, then the coroutine goes to “dead” status. Am I missing something basic?

Here is my main.lua where I set up the coroutine. The MessagePump module reads the UDP socket and returns a list of packets read. I can see the print(packet.debug()) output until the scene changes.

[code]
local rkThread = nil

local function crankPump(event)
coroutine.resume(rkThread)
end

local function main()
MessagePump.new() – init socket and packet factory

rkThread = coroutine.create(
function()
while true do
local pktlist = MessagePump.readall()
for _,packet in pairs(pktlist) do
print(packet.debug)
packet:updateState()
end
coroutine.yield()
end
end
)

Runtime:addEventListener(“enterFrame”, crankPump)

mainGroup:insert(director.directorView)
director:changeScene(“SplashScene”, “fade”)

return true
end

main() [import]uid: 58455 topic_id: 24031 reply_id: 324031[/import]

It’s not director – I commented it out and have the same problem – it’s just main() ending. I think I need to refactor my code. Still not quite grokking coroutines I guess. [import]uid: 58455 topic_id: 24031 reply_id: 96897[/import]

Resolved.

I moved my coroutine logic to the MessagePump module, to no avail. Then I did what I should have done before I coded this - carefully read the reference manual on Lua Coroutines.

coroutine.resume() returns a status and a message. I decided to interrogate said status and message.

My coroutine was exiting because of runtime errors in a few of my packets’ updatePacket() method. So it had nothing to do with Director or scope - just programmer error, per usual.

*facepalm*
[import]uid: 58455 topic_id: 24031 reply_id: 96910[/import]