Skip to content

Commit b650999

Browse files
committed
修复快速设置语言产生大量内存垃圾并在返回主菜单时卡顿 close #118
1 parent 9c2974e commit b650999

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

Zframework/languages.lua

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@ function LANG.init(langList,publicText)--Attention, calling this will destory al
3434
LANG.init,LANG.setLangList,LANG.setPublicText=nil
3535

3636
function LANG.set(l)
37-
text=langList[l]
38-
WIDGET.setLang(text.WidgetText)
39-
for k,v in next,drawableText do
40-
if text[k]then
41-
v:set(text[k])
37+
if text~=langList[l]then
38+
text=langList[l]
39+
WIDGET.setLang(text.WidgetText)
40+
for k,v in next,drawableText do
41+
if text[k]then
42+
v:set(text[k])
43+
end
4244
end
4345
end
4446
end

parts/scenes/lang.lua

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ function scene.sceneBack()
1515
FILE.save(SETTING,'conf/settings')
1616
end
1717

18-
local function setLang(n)
19-
SETTING.lang=n
20-
LANG.set(n)
21-
TEXT.show(langList[n],640,500,100,'appear',.626)
18+
local function _setLang(n)
19+
return function()
20+
SETTING.lang=n
21+
LANG.set(n)
22+
TEXT.show(langList[n],640,500,100,'appear',.626)
23+
collectgarbage()
24+
end
2225
end
23-
local function _setLang(n)return function()setLang(n)end end
2426
scene.widgetList={
2527
WIDGET.newButton{x=200,y=100,w=200,h=120,fText=langList[1],color='R',font=35,code=_setLang(1)},
2628
WIDGET.newButton{x=420,y=100,w=200,h=120,fText=langList[2],color='dR',font=35,code=_setLang(2)},

0 commit comments

Comments
 (0)