 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
alinear
Joined: 06 Sep 2005 Posts: 5 Location: Brooklyn, NY, USA
|
Posted: Fri Sep 09, 2005 6:36 pm Post subject: Can't Create Image Bug? |
|
|
Hello, when I run the following code in PC lua player alpha it runs reasonably, but when I run it on PSP luaplayer it quite often encounters the error:
error: script.lua:61: can't create image
Here is the script...
| Code: |
-- USB DISK MODE ACTIVATED FOR DEVELOPMENT
System.usbDiskModeActivate();
-- CLEAR THE SCREEN ON INIT
screen:clear();
-- GENERATE SCREEN BUFFER IMAGE
sBuffer = Image.createEmpty(480, 272);
-- GAP SPACING PARAMS
function init()
--sBuffer:clear();
rSeed = math.random(1, 100);
if rSeed < 50 then
gapW = math.random(1, 480);
gapH = math.random(1, 10);
else
gapW = math.random(1, 10);
gapH = math.random(1, 272);
end;
bW = math.floor(480 / gapW);
bH = math.floor(272 / gapH);
colorRange = 255 / bW;
max = bW * bH;
plots = {};
p = 0;
offsetX = 0;
offsetY = 0;
end;
-- CALL INIT
init();
-- MAIN LOOP
while true do
if p < max then
for p = p, p + bW do
stretch = 272 - offsetY;
if stretch < 1 then stretch = 1; end;
if stretch > 255 then stretch = 255; end; -- !!! WEIRD OPTIMIZATION, > 255 CHOKES UP !!!
colorMax = (p + 1) * colorRange;
rr = math.random(0, colorMax);
rg = math.random(0, colorMax);
rb = math.random(0, colorMax);
--plots[p] = Image.createEmpty(1, stretch);
--plots[p]:fillRect(0, 0, 1, stretch, Color.new(rr, rg, rb));
plots[p] = Image.createEmpty(gapW, stretch);
plots[p]:fillRect(0, 0, gapW, stretch, Color.new(rr, rg, rb));
--plots[p]:clear(Color.new(rr, rg, rb));
sBuffer:blit(offsetX, offsetY, plots[p]);
offsetX = offsetX + gapW;
if offsetX > 480 then
offsetX = 0;
offsetY = offsetY + gapH;
end;
end;
end;
screen:blit(0, 0, sBuffer, 0, 0, 480, 272, false);
screen.waitVblankStart();
screen.flip();
-- READ CONTROLS TO OBJECT 'INPUT'
input = Controls.read();
-- PAD MOVEMENT RE-INITS
if input:up() then init(); end;
if input:down() then init(); end;
if input:left() then init(); end;
if input:right() then init(); end;
-- TERMINATE ON START BUTTON
if input:start() then
break;
end;
-- SAVE SCREENSHOT ON SELECT BUTTON
if input:select() then
Image:save("screen_noise.png");
end;
end;
|
and here is line 61...
| Code: |
plots[p] = Image.createEmpty(gapW, stretch);
|
Is there some kind of issue with generating a large number of dynamic images in this manner... and if so is there a better way to do this in lua?
Also noticed a funny glitch on the PC lua player... if you alternate these lines (alternate which one is commented out):
| Code: |
plots[p]:fillRect(0, 0, gapW, stretch, Color.new(rr, rg, rb));
--plots[p]:clear(Color.new(rr, rg, rb));
|
Presumably, visually, both lines should sorta 'do' the same thing. But on PC lua player the fill method looks proper, whereas the clear method gets a very unusual color value and appears to have mucked up alpha values (looks like the color assignment has actually somehow bitshifted rrggbb to something like *rggbba* or something screwy like that...).
Any insight is appreciated. |
|
| Back to top |
|
 |
alinear
Joined: 06 Sep 2005 Posts: 5 Location: Brooklyn, NY, USA
|
Posted: Fri Sep 09, 2005 6:51 pm Post subject: |
|
|
I removed the incremental image name handles, they were a holdover from some other experimenting I was doing... since the pass render is being blitted to a sort of snapshot buffer I didn't need to inc. the image name -- just stamp each pass and move on:
| Code: |
plot = Image.createEmpty(gapW, stretch);
plot:fillRect(0, 0, gapW, stretch, Color.new(rr, rg, rb));
--plot:clear(Color.new(rr, rg, rb));
sBuffer:blit(offsetX, offsetY, plot);
|
BUT even with this change I still get the same line 61 can't create image error...
Still scratching my head... |
|
| Back to top |
|
 |
Shine
Joined: 03 Dec 2004 Posts: 728 Location: Germany
|
Posted: Fri Sep 09, 2005 8:38 pm Post subject: |
|
|
| I don't understand your code, looks like it allocates new images forever and stores it in the array at position 0 and 1. This should be no problem, because the old image would be GC'ed, but there is a bug in version 0.9 of Lua Player, add "collectgarbage()" in your loop. |
|
| Back to top |
|
 |
alinear
Joined: 06 Sep 2005 Posts: 5 Location: Brooklyn, NY, USA
|
Posted: Sat Sep 10, 2005 2:17 am Post subject: |
|
|
Here is the final code with a lot of comments
| Code: |
-- USB DISK MODE ACTIVATED FOR DEVELOPMENT
System.usbDiskModeActivate();
-- CLEAR THE SCREEN ON START
screen:clear();
-- GENERATE SECONDARY SCREEN BUFFER IMAGE
sBuffer = Image.createEmpty(480, 272);
-- INIT FUNCTION, ESTABLISHES PATTERN PROPERTIES
function init()
-- CLEAR OLD IMAGE BUFFERS
sBuffer:clear();
screen:clear();
-- FORCE GARBAGE COLLECTION
collectgarbage();
-- BRANCH TO SEMI RANDOMLY DECIDE IF PATTERN IS WIDER OR TALLER
-- DEFINES PATTERN GRID GAP SIZES
rSeed = math.random(1, 100);
-- GREATER CHANCE OF WIDER LINES VS TALLER LINES
if rSeed < 75 then
gapW = math.random(10, 480);
gapH = math.random(1, 10);
else
gapW = math.random(1, 10);
gapH = math.random(10, 272);
end;
-- CALC RATIOS OF SCREEN TO GRID GAP SIZES
bW = math.floor(480 / gapW);
bH = math.floor(272 / gapH);
-- COLOR RANGE SCALAR
colorRange = 255 / bW;
-- DETERMINE MAX NUMBER OF ITERATIONS NEEDED TO FILL SCREEN
max = bW * bH;
-- INIT VARS
p = 0;
offsetX = 0;
offsetY = 0;
end;
-- CALL INIT
init();
-- MAIN LOOP
while true do
-- LOOP THROUGH ALL ITERATIONS
if p < max then
-- ITERATE BY FULL ROWS
for p = p, p + bW do
-- DETERMINE REMAINING HEIGHT IN CANVAS FROM CURRENT ITERATION
stretch = 272 - offsetY;
-- LIMIT V STRETCH RANGES
if stretch < 1 then stretch = 1; end;
-- if stretch > 255 then stretch = 255; end; -- !!! LUAPLAYER WIN OPTIMIZATION !!!
-- DEFINE RANGE OF RANDOMNESS OF COLOR BASED ON COLUMN ITERATION
colorMax = (p + 1) * colorRange;
-- GENERATE RANDOM R G B VALUES
rr = math.random(0, colorMax);
rg = math.random(0, colorMax);
rb = math.random(0, colorMax);
-- DRAW AN IMAGE TO PLOT THE CURRENT ITERATION
plot = Image.createEmpty(gapW, stretch);
-- SWAPPING THESE FILL METHODS SEEMS TO PRODUCE DIFFERENT VISUAL RESULTS
-- IN LUAPLAYER/WIN, PRODUCE SAME VISUAL RESULTS IN LUAPLAYER/PSP
-- plot:fillRect(0, 0, gapW, stretch, Color.new(rr, rg, rb));
plot:clear(Color.new(rr, rg, rb));
-- STAMP THE ITERATION TO THE SECONDARY SCREEN BUFFER
sBuffer:blit(offsetX, offsetY, plot);
-- FORCE GARBAGE COLLECTION
collectgarbage();
-- INC THE COLUMN POSITION (H)
offsetX = offsetX + gapW;
-- LOOP THE COLUMN POSITION, INC THE ROW POSITION (V)
if offsetX > 480 then
offsetX = 0;
offsetY = offsetY + gapH;
end;
end;
end;
-- ^^ END ITERATIONS (UNTIL RE-INITIALIZED)
-- BLIT THE SECONDARY SCREEN BUFFER TO THE STANDARD OFF-SCREEN BUFFER
screen:blit(0, 0, sBuffer, 0, 0, 480, 272, false);
-- WAIT FOR VBLANK SYNC
screen.waitVblankStart();
-- FLIP OFF-SCREEN BUFFER TO VISIBLE SCREEN
screen.flip();
-- READ CONTROLS TO OBJECT 'INPUT'
input = Controls.read();
-- PAD MOVEMENT RE-INITS
if input:up() then init(); end;
if input:down() then init(); end;
if input:left() then init(); end;
if input:right() then init(); end;
-- TERMINATE ON START BUTTON
if input:start() then
break;
end;
-- SAVE SCREENSHOT ON SELECT BUTTON
if input:select() then
Image:save("screen_noise.png");
end;
end;
|
The forced garbage collection appears to have gotten rid of the image allocation problem... also, as I posted above I got rid of it using an array to allocate the image iterations in favor of just using a single image that gets reinit each pass...
I just made this little noise/pattern generation thing, mainly to understand how to manipulate blits and mess with lua, and to stress luaplayer a bit to see how it performs...
What I've found is...
- Seems to obviously perform a lot better drawing horizontal lines (across rasterlines) vs. vertical (against rasterlines).
- Has an unusual behavior in luaplayer pc where if you, for example, are drawing solid boxes dynamically and you decide to just create an image of your boxes x/y size then clear it with a color to fill it, vs. if you create the image then draw a rectangle in it... the performance visually looks about the same, visually looks the same on PSP luaplayer, but on PC (win) luaplayer the 2 different methods produce visually different results... The 'clear' method looks like it screws up the clear fill color, transposing the color values and even affecting the alpha (t/f) even when it is undefined...
| Code: |
-- SWAPPING THESE FILL METHODS SEEMS TO PRODUCE DIFFERENT VISUAL RESULTS
-- IN LUAPLAYER/WIN, PRODUCE SAME VISUAL RESULTS IN LUAPLAYER/PSP
-- plot:fillRect(0, 0, gapW, stretch, Color.new(rr, rg, rb));
plot:clear(Color.new(rr, rg, rb));
|
- On PSP luaplayer when you draw vert lines (boxes, fills) the performance is generally slow unless the lines are not very many rasterlines tall (a bit less than 100 pixels). On PC luaplayer, when you draw vert lines (boxes, fills) the performance is great up until it reaches 255 pixels high, then it suddenly gets very slow (very big diff. between iterating >= 255 pixels high vs. < 255 pixels high).
Thanks for pointing out the garbage collection thing! |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|