From 0e0d88d75595f8eb6c264c69437b6f631ebb47d5 Mon Sep 17 00:00:00 2001 From: MrZ626 <1046101471@qq.com> Date: Fri, 19 Mar 2021 01:24:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=83=A8=E5=88=86=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E7=9E=AC=E9=97=B4=E6=8A=A5=E9=94=99=E4=BC=9A=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E9=97=AA=E9=80=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Zframework/init.lua | 141 ++++++++++++++++++++++++++++++-------------- 1 file changed, 97 insertions(+), 44 deletions(-) diff --git a/Zframework/init.lua b/Zframework/init.lua index e0b948d7..0258b71f 100644 --- a/Zframework/init.lua +++ b/Zframework/init.lua @@ -356,53 +356,106 @@ local function secondLoopThread() repeat yield()until mainLoop() end function love.errorhandler(msg) - --Generate error message - local errData={} - errData.mes={"Error:"..msg} - local c=2 - for l in debug.traceback("",2):gmatch("(.-)\n")do - if c>2 then - if not l:find("boot")then - errData.mes[c]=l:gsub("^\t*","") - c=c+1 + if LOADED then + --Generate error message + local errData={} + errData.mes={"Error:"..msg} + local c=2 + for l in debug.traceback("",2):gmatch("(.-)\n")do + if c>2 then + if not l:find("boot")then + errData.mes[c]=l:gsub("^\t*","") + c=c+1 + end + else + errData.mes[2]="Traceback" + c=3 end - else - errData.mes[2]="Traceback" - c=3 + 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" + 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 - 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 local WSnames={"app","user","chat","play","stream"} local WScolor={