Skip to content

Commit 62f8d6a

Browse files
committed
Attempt to fix MOAIImageTexture reallocated on each new glyph rendered
1 parent c4c6680 commit 62f8d6a

File tree

7 files changed

+111
-2
lines changed

7 files changed

+111
-2
lines changed
44.2 KB
Binary file not shown.

Diff for: samples/test/textbox-dynamic-cache-allocs/main.lua

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
----------------------------------------------------------------
2+
-- Copyright (c) 2010-2011 Zipline Games, Inc.
3+
-- All Rights Reserved.
4+
-- http://getmoai.com
5+
----------------------------------------------------------------
6+
7+
MOAISim.openWindow ( "test", 320, 480 )
8+
9+
viewport = MOAIViewport.new ()
10+
viewport:setSize ( 320, 480 )
11+
viewport:setScale ( 320, 480 )
12+
13+
layer = MOAILayer2D.new ()
14+
layer:setViewport ( viewport )
15+
MOAISim.pushRenderPass ( layer )
16+
17+
font = MOAIFont.new ()
18+
font:load ( 'arial-rounded.TTF' )
19+
20+
function glyphAlloc ()
21+
text = "Hello 123456789 qwertyuiopasdfghjklzxcvbnm QWERTYUIOPASDFGHJKLZXCVBNM"
22+
local textbox = MOAITextBox.new ()
23+
textbox:setFont ( font )
24+
textbox:setString ( "as" )
25+
textbox:setTextSize ( 64 )
26+
textbox:setWordBreak ( MOAITextBox.WORD_BREAK_CHAR )
27+
textbox:setRect ( -160, -240, 160, 240 )
28+
textbox:setYFlip ( true )
29+
layer:insertProp ( textbox )
30+
31+
for i = 1, #text do
32+
textbox:setString ( text:sub ( 1, i ))
33+
coroutine.yield ()
34+
end
35+
end
36+
37+
thread = MOAICoroutine.new ()
38+
thread:run ( glyphAlloc )

Diff for: samples/test/textbox-dynamic-cache-allocs/run.bat

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
::----------------------------------------------------------------::
2+
:: Copyright (c) 2010-2011 Zipline Games, Inc.
3+
:: All Rights Reserved.
4+
:: http://getmoai.com
5+
::----------------------------------------------------------------::
6+
7+
@echo off
8+
9+
:: verify paths
10+
if not exist "%MOAI_BIN%\moai.exe" (
11+
echo.
12+
echo --------------------------------------------------------------------------------
13+
echo ERROR: The MOAI_BIN environment variable either doesn't exist or it's pointing
14+
echo to an invalid path. Please point it at a folder containing moai.exe.
15+
echo --------------------------------------------------------------------------------
16+
echo.
17+
goto end
18+
)
19+
20+
if not exist "%MOAI_CONFIG%" (
21+
echo.
22+
echo -------------------------------------------------------------------------------
23+
echo WARNING: The MOAI_CONFIG environment variable either doesn't exist or it's
24+
echo pointing to an invalid path. Please point it at a folder containing config.lua.
25+
echo -------------------------------------------------------------------------------
26+
echo.
27+
)
28+
29+
:: run moai
30+
"%MOAI_BIN%\moai" "%MOAI_CONFIG%\config.lua" "main.lua"
31+
32+
:end
33+
pause

Diff for: samples/test/textbox-dynamic-cache-allocs/run.sh

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/sh
2+
#--------------------------------------------------------------------------------------
3+
# Copyright (c) 2010-2013 Zipline Games, Inc.
4+
# All Rights Reserved.
5+
# http://getmoai.com
6+
#--------------------------------------------------------------------------------------
7+
8+
cd `dirname $0`
9+
10+
# Verify paths
11+
if [ ! -f "$MOAI_BIN/moai" ]; then
12+
echo "---------------------------------------------------------------------------"
13+
echo "Error: The MOAI_BIN environment variable doesn't exist or its pointing to an"
14+
echo "invalid path. Please point it at a folder containing moai executable"
15+
echo "---------------------------------------------------------------------------"
16+
exit 1
17+
fi
18+
19+
if [ ! -f "$MOAI_CONFIG/config.lua" ]; then
20+
echo "---------------------------------------------------------------------------"
21+
echo "WARNING: The MOAI_CONFIG environment variable either doesn't exist or it's"
22+
echo "pointing to an invalid path. Please point it at a folder containing config.lua"
23+
echo "---------------------------------------------------------------------------"
24+
exit 1
25+
fi
26+
27+
# Run moai
28+
$MOAI_BIN/moai $MOAI_CONFIG/config.lua main.lua

Diff for: src/moai-sim/MOAIGfxResource.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,15 @@ void MOAIGfxResource::Invalidate () {
144144
}
145145
}
146146

147+
//----------------------------------------------------------------//
148+
void MOAIGfxResource::InvalidateContents () {
149+
150+
if ( this->mState != STATE_ERROR ) {
151+
152+
this->mState = STATE_PRECREATE;
153+
}
154+
}
155+
147156
//----------------------------------------------------------------//
148157
void MOAIGfxResource::Load () {
149158

Diff for: src/moai-sim/MOAIGfxResource.h

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class MOAIGfxResource :
7575
void Clear ();
7676
void Destroy ();
7777
void Invalidate ();
78+
void InvalidateContents ();
7879
virtual bool IsValid () = 0; // return 'true' if the handle to the GPU-side resource is valid (or initialized) - GRAPHICS THREAD
7980
void Load ();
8081
MOAIGfxResource ();

Diff for: src/moai-sim/MOAIImageTexture.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ int MOAIImageTexture::_invalidate ( lua_State* L ) {
4444
void MOAIImageTexture::InvalidateAll () {
4545

4646
this->mStatus = INVALID;
47-
this->MOAIGfxResource::Load ();
47+
this->MOAIGfxResource::InvalidateContents ();
4848
}
4949

5050
//----------------------------------------------------------------//
@@ -63,7 +63,7 @@ void MOAIImageTexture::Invalidate ( ZLIntRect rect ) {
6363
}
6464
this->mStatus = INVALID_REGION;
6565

66-
this->MOAIGfxResource::Load ();
66+
this->MOAIGfxResource::InvalidateContents ();
6767
}
6868

6969
//----------------------------------------------------------------//

0 commit comments

Comments
 (0)