请教一个协程得报错
Run-time errorWorld: kingodg@sjsj
Function/Sub: wait_timer_resume called by timer
Reason: 正在处理定时器 "wait_timer_6223613"
:1409: coroutine exception
stack traceback:
: in function 'assert'
:1409: in function <:1402>
脚本错误处的上下文:
1405 :
1406 : local thread = wait_table
1407 :
1408 : if thread~=nil and thread~="" then
1409*: assert(coroutine.resume (thread),"coroutine exception")
1410 : --assert (coroutine.running (), "Must be in coroutine")
1411 : else
1412 : print(name," 不存在")
1413 : end -- if
北大侠客行MUD,中国最好的MUD 这个报错 该如何查找原因呢 coroutine有dead状态 coroutine有dead状态
cappuccino 发表于 2015-2-27 07:32 PM http://pkuxkx.com/forum/images/common/back.gif请教 该怎么解决这个dead状态 呈上 三个函数
-- 线程表,储存正在暂停的线程
local wait_table = {}
--setmetatable(wait_table, {__mode = "k"}) --weak table
-- 被定时器调用以恢复一个暂停的线程
function wait_timer_resume(name)
--print(table.getn(wait_table),"数组大小")
--print("wait_id: ",name)
local thread = wait_table
if thread~=nil and thread~="" then
assert(coroutine.resume (thread),"coroutine exception")
--assert (coroutine.running (), "Must be in coroutine")
else
print(name," 不存在")
end -- if
wait_table=nil
--collectgarbage()--垃圾回收
end -- function wait_timer_resume
-- 在脚本中调用这个函数来暂停当前的线程
function f_wait(address, seconds,ActiveWhenClosed)
if seconds<=0 then
address()
return
end
id = "wait_timer_" .. GetUniqueNumber ()
hours = math.floor(seconds / 3600)
seconds = seconds - (hours * 3600)
minutes = math.floor(seconds / 60)
seconds = seconds - (minutes * 60)
--print("等待",seconds,"s"," ",id)
wait_table =coroutine.create(function()
--print("执行")
address()
end)
if ActiveWhenClosed==true then
status = AddTimer (id, hours, minutes, seconds, "",
timer_flag.Enabled + timer_flag.OneShot +
timer_flag.Temporary + timer_flag.Replace+timer_flag.ActiveWhenClosed,
"wait_timer_resume")
else
status = AddTimer (id, hours, minutes, seconds, "",
timer_flag.Enabled + timer_flag.OneShot +
timer_flag.Temporary + timer_flag.Replace,
"wait_timer_resume")
end
assert(status == error_code.eOK, error_desc)
end
function f_clear()
for i,v in pairs(wait_table) do
local thread=wait_table
if thread then
wait_table=nil
--print(i)
--print(coroutine.status(thread))
end
end
wait_table={}
end 我的意思是
if thread~=nil and thread~="" then
assert(coroutine.resume (thread),"coroutine exception")
--assert (coroutine.running (), "Must be in coroutine")
else
print(name," 不存在")
end -- if
wait_table=nil
--collectgarbage()--垃圾回收
end -- function wait_timer_resume
你这段代码里只判断了thread的两种情况,即空和非空。。而实际上dead协程是不会被系统自动清理的,所以如果thread已经dead,就会走非空的这个分支,而一个dead状态的thread是无法resume的,就会报错。。。
以上胡言乱语,不一定就是你出错的真正原因。。
俺对这些的了解也是一知半解而已。
flee 经过测试 好像不是dead协程 有高手可以答疑吗?谢谢了
页:
[1]