修复部分启动瞬间报错会导致闪退
This commit is contained in:
@@ -356,53 +356,106 @@ local function secondLoopThread()
|
|||||||
repeat yield()until mainLoop()
|
repeat yield()until mainLoop()
|
||||||
end
|
end
|
||||||
function love.errorhandler(msg)
|
function love.errorhandler(msg)
|
||||||
--Generate error message
|
if LOADED then
|
||||||
local errData={}
|
--Generate error message
|
||||||
errData.mes={"Error:"..msg}
|
local errData={}
|
||||||
local c=2
|
errData.mes={"Error:"..msg}
|
||||||
for l in debug.traceback("",2):gmatch("(.-)\n")do
|
local c=2
|
||||||
if c>2 then
|
for l in debug.traceback("",2):gmatch("(.-)\n")do
|
||||||
if not l:find("boot")then
|
if c>2 then
|
||||||
errData.mes[c]=l:gsub("^\t*","")
|
if not l:find("boot")then
|
||||||
c=c+1
|
errData.mes[c]=l:gsub("^\t*","")
|
||||||
|
c=c+1
|
||||||
|
end
|
||||||
|
else
|
||||||
|
errData.mes[2]="Traceback"
|
||||||
|
c=3
|
||||||
end
|
end
|
||||||
else
|
end
|
||||||
errData.mes[2]="Traceback"
|
local errMes=table.concat(errData.mes,"\n",1,c-2)
|
||||||
c=3
|
DBP(errMes)
|
||||||
|
|
||||||
|
--Write messages to log file
|
||||||
|
love.filesystem.append("conf/error.log",
|
||||||
|
os.date("%Y/%m/%d %A %H:%M:%S\n")..
|
||||||
|
#ERRDATA.." crash(es) "..SYSTEM.."-"..VERSION_NAME.." scene: "..(SCN and SCN.cur or"NULL").."\n"..
|
||||||
|
errMes.."\n\n"
|
||||||
|
)
|
||||||
|
|
||||||
|
ins(ERRDATA,errData)
|
||||||
|
|
||||||
|
--Force quit if error too much
|
||||||
|
if #ERRDATA>=5 then return end
|
||||||
|
|
||||||
|
--Get screencapture
|
||||||
|
BG.set("none")
|
||||||
|
love.audio.stop()
|
||||||
|
gc.reset()
|
||||||
|
gc.captureScreenshot(function(_)errData.shot=gc.newImage(_)end)
|
||||||
|
gc.present()
|
||||||
|
|
||||||
|
--Create a new mainLoop thread to keep game alive
|
||||||
|
local status,resume=coroutine.status,coroutine.resume
|
||||||
|
local loopThread=coroutine.create(secondLoopThread)
|
||||||
|
repeat
|
||||||
|
local res,err=resume(loopThread)
|
||||||
|
if not res then
|
||||||
|
love.errorhandler(err)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
until status(loopThread)=="dead"
|
||||||
|
else
|
||||||
|
ms.setVisible(true)
|
||||||
|
love.audio.stop()
|
||||||
|
|
||||||
|
local err={"Error:"..msg}
|
||||||
|
local trace=debug.traceback("",2)
|
||||||
|
local c=2
|
||||||
|
for l in trace:gmatch("(.-)\n")do
|
||||||
|
if c>2 then
|
||||||
|
if not l:find("boot")then
|
||||||
|
err[c]=l:gsub("^\t*","")
|
||||||
|
c=c+1
|
||||||
|
end
|
||||||
|
else
|
||||||
|
err[2]="Traceback"
|
||||||
|
c=3
|
||||||
|
end
|
||||||
|
end
|
||||||
|
DBP(table.concat(err,"\n"),1,c-2)
|
||||||
|
gc.reset()
|
||||||
|
gc_setColor(1,1,1)
|
||||||
|
|
||||||
|
SFX.fplay("error",SETTING and SETTING.voc*.8 or 0)
|
||||||
|
|
||||||
|
local errorMsg=text and text.errorMsg or"An error has occurred during loading.\nError info has been created, and you can send it to the author."
|
||||||
|
return function()
|
||||||
|
love.event.pump()
|
||||||
|
for E,a,b in love.event.poll()do
|
||||||
|
if E=="quit"or a=="escape"then
|
||||||
|
destroyPlayers()
|
||||||
|
return 1
|
||||||
|
elseif E=="resize"then
|
||||||
|
SCR.resize(a,b)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
gc.clear(.3,.5,.9)
|
||||||
|
gc_push("transform")
|
||||||
|
gc.replaceTransform(xOy)
|
||||||
|
setFont(100)gc_print(":(",100,40,0,1.2)
|
||||||
|
setFont(40)gc.printf(errorMsg,100,200,SCR.w0-100)
|
||||||
|
setFont(20)
|
||||||
|
gc_print(SYSTEM.."-"..VERSION_NAME,100,660)
|
||||||
|
gc.printf(err[1],626,380,1260-626)
|
||||||
|
gc_print("TRACEBACK",626,450)
|
||||||
|
for i=4,#err-2 do
|
||||||
|
gc_print(err[i],626,400+20*i)
|
||||||
|
end
|
||||||
|
gc_pop()
|
||||||
|
gc_present()
|
||||||
|
love.timer.sleep(.26)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local errMes=table.concat(errData.mes,"\n",1,c-2)
|
|
||||||
DBP(errMes)
|
|
||||||
|
|
||||||
--Write messages to log file
|
|
||||||
love.filesystem.append("conf/error.log",
|
|
||||||
os.date("%Y/%m/%d %A %H:%M:%S\n")..
|
|
||||||
#ERRDATA.." crash(es) "..SYSTEM.."-"..VERSION_NAME.." scene: "..(SCN and SCN.cur or"NULL").."\n"..
|
|
||||||
errMes.."\n\n"
|
|
||||||
)
|
|
||||||
|
|
||||||
ins(ERRDATA,errData)
|
|
||||||
|
|
||||||
--Force quit if error too much
|
|
||||||
if #ERRDATA>=5 then return end
|
|
||||||
|
|
||||||
--Get screencapture
|
|
||||||
BG.set("none")
|
|
||||||
love.audio.stop()
|
|
||||||
gc.reset()
|
|
||||||
gc.captureScreenshot(function(_)errData.shot=gc.newImage(_)end)
|
|
||||||
gc.present()
|
|
||||||
|
|
||||||
--Create a new mainLoop thread to keep game alive
|
|
||||||
local status,resume=coroutine.status,coroutine.resume
|
|
||||||
local loopThread=coroutine.create(secondLoopThread)
|
|
||||||
repeat
|
|
||||||
local res,err=resume(loopThread)
|
|
||||||
if not res then
|
|
||||||
love.errorhandler(err)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
until status(loopThread)=="dead"
|
|
||||||
end
|
end
|
||||||
local WSnames={"app","user","chat","play","stream"}
|
local WSnames={"app","user","chat","play","stream"}
|
||||||
local WScolor={
|
local WScolor={
|
||||||
|
|||||||
Reference in New Issue
Block a user