Display get#s no longer updated (on iPhone device)

Hello!

I am currently checking the various font glyphs available on the iPhone by displaying them on the screen. While the following code runs fine in the Simulator, the actual iPhone stops displaying the current text during the process (while still continuing to run).

Here is the code:

--------------------------------------------------------------------------------
-- Copyright (c) 2010 Andreas Rozek
--
-- Permission is hereby granted, free of charge, to any person obtaining a copy
-- of this software and associated documentation files (the "Software"),to deal
-- in the Software without restriction, including without limitation the rights
-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-- copies of the Software, and to permit persons to whom the Software is fur-
-- nished to do so, subject to the following conditions:
--
-- The above copyright notice and this permission notice shall be included in
-- all copies or substantial portions of the Software.
--
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIA-
-- BILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-- THE SOFTWARE.
--
-- Additionally, any modifications to the original Software must be clearly
-- marked in a way, that the original author will never be considered as the
-- author of these modifications!
--------------------------------------------------------------------------------

--\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
--\* \*
--\* Console Output \*
--\* \*
--\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

 io.stdout:setvbuf("no");
 io.stderr:setvbuf("no");

--------------------------------------------------------------------------------
-- complain[ln] writes the given arguments onto stderr --
--------------------------------------------------------------------------------

 function complain (...)
 for i = 1,select('#',...) do -- even "nil" is handled properly
 io.stderr:write(tostring(select(i,...)));
 end;
 end;

 function complainln (...)
 for i = 1,select('#',...) do -- even "nil" is handled properly
 io.stderr:write(tostring(select(i,...)));
 end;
 io.stderr:write("\n");
 end;

--------------------------------------------------------------------------------
-- cry[ln] just synonyms for complain[ln] --
--------------------------------------------------------------------------------

 cry = complain;
 cryln = complainln;

--------------------------------------------------------------------------------
-- inform[ln] writes the given arguments onto stdout --
--------------------------------------------------------------------------------

 function inform (...)
 for i = 1,select('#',...) do -- even "nil" is handled properly
 io.stdout:write(tostring(select(i,...)));
 end;
 end;

 function informln (...)
 for i = 1,select('#',...) do -- even "nil" is handled properly
 io.stdout:write(tostring(select(i,...)));
 end;
 io.stdout:write("\n");
 end;

--------------------------------------------------------------------------------
-- say[ln] just synonyms for inform[ln] --
--------------------------------------------------------------------------------

 say = inform;
 sayln = informln;

 local StageWidth,StageHeight = display.stageWidth,display.stageHeight;

--------------------------------------------------------------------------------
-- CodeToUTF8 converts a (valid!) code point into a UTF-8 sequence --
--------------------------------------------------------------------------------

 function CodeToUTF8 (Unicode)
 if (Unicode \<= 0x7F) then return string.char(Unicode); end;

 if (Unicode \<= 0x7FF) then
 local Byte0 = 0xC0 + math.floor(Unicode / 0x40);
 local Byte1 = 0x80 + (Unicode % 0x40);
 return string.char(Byte0, Byte1);
 end;

 if (Unicode \<= 0xFFFF) then
 local Byte0 = 0xE0 + math.floor(Unicode / 0x1000);
 local Byte1 = 0x80 + (math.floor(Unicode / 0x40) % 0x40);
 local Byte2 = 0x80 + (Unicode % 0x40);
 return string.char(Byte0, Byte1, Byte2);
 end;

 return ""; -- ignore UTF-32 for the moment
 end;

--------------------------------------------------------------------------------
-- CodeFromUTF8 converts a (valid!) UTF-8 sequence into a Unicode code point --
--------------------------------------------------------------------------------

 function CodeFromUTF8 (UTF8)
 local Byte0 = string.byte(UTF8,1);
 if (math.floor(Byte0 / 0x80) == 0) then return Byte0; end;

 local Byte1 = string.byte(UTF8,2) % 0x40;
 if (math.floor(Byte0 / 0x20) == 0x06) then
 return (Byte0 % 0x20)\*0x40 + Byte1;
 end;

 local Byte2 = string.byte(UTF8,3) % 0x40;
 if (math.floor(Byte0 / 0x10) == 0x0E) then
 return (Byte0 % 0x10)\*0x1000 + Byte1\*0x40 + Byte2;
 end;

 local Byte3 = string.byte(UTF8,4) % 0x40;
 if (math.floor(Byte0 / 0x08) == 0x1E) then
 return (Byte0 % 0x08)\*0x40000 + Byte1\*0x1000 + Byte2\*0x40 + Byte3;
 end;
 end;

 function showCharacter (Event)
 repeat
 TextObject.text = CodeToUTF8(Unicode);

 if (TextObject.stageWidth \> 0) and (TextObject.stageHeight \> 0) then
 local StageBounds = TextObject.stageBounds;

 display.getCurrentStage():remove(FrameObject);

 FrameObject = display.newRect(
 StageBounds.xMin,StageBounds.yMin,
 StageBounds.xMax-StageBounds.xMin,StageBounds.yMax-StageBounds.yMin
 );
 FrameObject.strokeWidth = 1;
 FrameObject:setStrokeColor(255,0,0);
 end;

 Unicode = Unicode+1;
 until (TextObject.stageWidth \> 0) or (Unicode \> 65535);

 if (Unicode \<= 65536) then
 GlyphCount = GlyphCount+1;

 minWidth = math.min (minWidth,TextObject.stageWidth);
 maxWidth = math.max (maxWidth,TextObject.stageWidth);
 minHeight = math.min(minHeight,TextObject.stageHeight);
 maxHeight = math.max(maxHeight,TextObject.stageHeight);
 end;

 if (Unicode \<= 65535) then
 timer.performWithDelay(1,showCharacter);
 else
 sayln("Statistics:");
 sayln(" - ",GlyphCount," glyphs shown (out of 65536)");
 sayln(" - glyph widths = ",minWidth,"...",maxWidth);
 sayln(" - glyph heights = ",minHeight,"...",maxHeight);
 end;
 end;

--------------------------------------------------------------------------------
-- Display Elements --
--------------------------------------------------------------------------------

 local TitleLabel = display.newText("Bitmap Font Test", 0,0, nil, 14);
 TitleLabel:setReferencePoint(display.CenterReferencePoint);
 TitleLabel.x = StageWidth/2;
 TitleLabel.y = 20;
 TitleLabel:setTextColor(222,222,222);

 Unicode,GlyphCount = 0,0;
 minWidth,maxWidth,minHeight,maxHeight = 1000,0,1000,0;

 TextObject = display.newText(CodeToUTF8(Unicode), 0,0, nil, 128);
 TextObject:setReferencePoint(display.CenterReferencePoint);
 TextObject.x = StageWidth/2;
 TextObject.y = StageHeight/2;
 TextObject:setTextColor(255,255,255);

 FrameObject = display.newRect(0,0, 1,1); -- will be renewed later

 showCharacter(0)

Kind regards,

Andreas Rozek [import]uid: 4331 topic_id: 852 reply_id: 300852[/import]

Hi, Andreas. I’m pretty sure you’re running out of texture memory on the iPhone! Recall that it only has 10MB of texture memory, whereas the Mac has a lot more, so that’s probably why you’re seeing the iPhone stop drawing much earlier.

Having said that, we’re not sure why you’re out of memory. We’ve logged this as a bug, because it’s not clear yet whether it should be possible on the iPhone – it could be some kind of subtle memory leak, or the case might just be impossible on iPhone hardware. We’ll figure out which it is.

In the meantime, you might try either slowing it down (in case there’s some latency in freeing resources) or testing the character set in smaller chunks. [import]uid: 3007 topic_id: 852 reply_id: 1953[/import]