From fb55857f1ed290bb0d2cb5782d9fc6e418f889c6 Mon Sep 17 00:00:00 2001 From: benfry Date: Thu, 16 Oct 2008 19:30:08 +0000 Subject: [PATCH] fix for bug #246 and bug #462, AIOOBE when drawing lines in P3D --- build/shared/revisions.txt | 3 ++ core/src/processing/core/PLine.java | 74 ++++++++++++++++------------- core/todo.txt | 32 +++++++------ todo.txt | 1 + 4 files changed, 61 insertions(+), 49 deletions(-) diff --git a/build/shared/revisions.txt b/build/shared/revisions.txt index 277639084..f0dd40d3e 100644 --- a/build/shared/revisions.txt +++ b/build/shared/revisions.txt @@ -52,6 +52,9 @@ a couple bug fixes. example for those wanting to do their own thick line code: http://dev.processing.org/bugs/show_bug.cgi?id=123 ++ Removed the error dialog that popped up to nag about sketch naming, + now we're only writing it to the console. + + Library authors note that the dimensional() method in PGraphics has been split into is2D() and is3D() for better congruence with use. diff --git a/core/src/processing/core/PLine.java b/core/src/processing/core/PLine.java index 9ea2732b7..0a9f45f16 100644 --- a/core/src/processing/core/PLine.java +++ b/core/src/processing/core/PLine.java @@ -763,9 +763,11 @@ public class PLine implements PConstants length += y0; for (int j = 0x8000 + (x0<<16); y0 <= length; ++y0) { offset = y0 * SCREEN_WIDTH + (j>>16); - if (iz <= m_zbuffer[offset]) { - m_pixels[offset] = m_stroke; - m_zbuffer[offset] = iz; + if (offset < m_pixels.length) { + if (iz <= m_zbuffer[offset]) { + m_pixels[offset] = m_stroke; + m_zbuffer[offset] = iz; + } } iz+=dz; j+=dt; @@ -775,9 +777,11 @@ public class PLine implements PConstants length += x0; for (int j = 0x8000 + (y0<<16); x0 <= length; ++x0) { offset = (j>>16) * SCREEN_WIDTH + x0; - if (iz <= m_zbuffer[offset]) { - m_pixels[offset] = m_stroke; - m_zbuffer[offset] = iz; + if (offset < m_pixels.length) { + if (iz <= m_zbuffer[offset]) { + m_pixels[offset] = m_stroke; + m_zbuffer[offset] = iz; + } } iz+=dz; j+=dt; @@ -801,20 +805,21 @@ public class PLine implements PConstants length += y0; for (int j = 0x8000 + (x0<<16); y0 <= length; ++y0) { offset = y0 * SCREEN_WIDTH + (j>>16); + if (offset < m_pixels.length) { + if (iz <= m_zbuffer[offset]) { + int alpha = ia >> 16; + int r0 = m_pixels[offset]; + int g0 = r0 & 0xFF00; + int b0 = r0 & 0xFF; + r0 &= 0xFF0000; + r0 = r0 + (((pr - r0) * alpha) >> 8); + g0 = g0 + (((pg - g0) * alpha) >> 8); + b0 = b0 + (((pb - b0) * alpha) >> 8); - if (iz <= m_zbuffer[offset]) { - int alpha = ia >> 16; - int r0 = m_pixels[offset]; - int g0 = r0 & 0xFF00; - int b0 = r0 & 0xFF; - r0 &= 0xFF0000; - r0 = r0 + (((pr - r0) * alpha) >> 8); - g0 = g0 + (((pg - g0) * alpha) >> 8); - b0 = b0 + (((pb - b0) * alpha) >> 8); - - m_pixels[offset] = 0xFF000000 | - (r0 & 0xFF0000) | (g0 & 0xFF00) | (b0 & 0xFF); - //m_zbuffer[offset] = iz; + m_pixels[offset] = 0xFF000000 | + (r0 & 0xFF0000) | (g0 & 0xFF00) | (b0 & 0xFF); + //m_zbuffer[offset] = iz; + } } iz +=dz; ia += da; @@ -826,19 +831,21 @@ public class PLine implements PConstants for (int j = 0x8000 + (y0<<16); x0 <= length; ++x0) { offset = (j>>16) * SCREEN_WIDTH + x0; - if (iz <= m_zbuffer[offset]) { - int alpha = ia >> 16; - int r0 = m_pixels[offset]; - int g0 = r0 & 0xFF00; - int b0 = r0 & 0xFF; - r0&=0xFF0000; - r0 = r0 + (((pr - r0) * alpha) >> 8); - g0 = g0 + (((pg - g0) * alpha) >> 8); - b0 = b0 + (((pb - b0) * alpha) >> 8); + if (offset < m_pixels.length) { + if (iz <= m_zbuffer[offset]) { + int alpha = ia >> 16; + int r0 = m_pixels[offset]; + int g0 = r0 & 0xFF00; + int b0 = r0 & 0xFF; + r0&=0xFF0000; + r0 = r0 + (((pr - r0) * alpha) >> 8); + g0 = g0 + (((pg - g0) * alpha) >> 8); + b0 = b0 + (((pb - b0) * alpha) >> 8); - m_pixels[offset] = 0xFF000000 | - (r0 & 0xFF0000) | (g0 & 0xFF00) | (b0 & 0xFF); - //m_zbuffer[offset] = iz; + m_pixels[offset] = 0xFF000000 | + (r0 & 0xFF0000) | (g0 & 0xFF00) | (b0 & 0xFF); + //m_zbuffer[offset] = iz; + } } iz += dz; ia += da; @@ -1017,9 +1024,8 @@ public class PLine implements PConstants m_zbuffer[offset] = iz; } - // this if() makes things slow. there shoudl be - // a better way to check if the second pixel is - // withing the image array [rocha] + // this if() makes things slow. there should be a better way to check + // if the second pixel is within the image array [rocha] temp = ((xi>>16)+1); if (temp >= SCREEN_WIDTH) { xi += dt; diff --git a/core/todo.txt b/core/todo.txt index 67daa6570..4e1bf0ad6 100644 --- a/core/todo.txt +++ b/core/todo.txt @@ -12,7 +12,13 @@ X probably the pixel flipping code (and endian sorting) not happening X because the blue comes from the byte order flip X http://processing.org/discourse/yabb_beta/YaBB.cgi?board=OpenGL;action=post;num=1219196429 -earlier +X ArrayIndexOutOfBoundsException in PLine +X http://dev.processing.org/bugs/show_bug.cgi?id=246 +X http://dev.processing.org/bugs/show_bug.cgi?id=462 +X random AIOOBE with P3D and points +X http://dev.processing.org/bugs/show_bug.cgi?id=937 + +cleanup X alter bezier and curve matrices to use PMatrix X float array stuff is redundant with code that's in PMatrix X and PMatrix has to be included even w/o P3D so... @@ -26,6 +32,8 @@ o gl smoothing.. how to disable polygon but keep line enabled o or at least make a note of this? o leave smooth off, get the gl object, then enable line smooth X don't bother, this is a workaround for another bug +o PPolygon no longer in use and PLine is a mess +o make a version of PGraphics3 that uses it for more accurate rendering? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . @@ -84,10 +92,11 @@ _ or it's the PGraphics object, which does an updatePixels() immediately _ if (modified) don't loadPixels again, just ignore it _ make a note that updatePixels() only sets a flag in PImage _ (but not PGraphics, which does it immediately) -_ filter() doesn't need a loadPixels -_ but if you want to filter *and* mess w/ pixels (avoid double load) -_ then do loadPixels() /before/ filter, and updatePixels after messing -_ same will go for blend() +o filter() doesn't need a loadPixels +o but if you want to filter *and* mess w/ pixels (avoid double load) +o then do loadPixels() /before/ filter, and updatePixels after messing +o same will go for blend() +_ make sure that filter, blend, copy, etc say that no loadPixels necessary rework some text/font code [1.0] @@ -100,6 +109,7 @@ _ perhaps also DEL or other nonprintables? _ book example 25-03 _ when using createFont("xxxx.ttf"), should use textMode(SHAPE) with PDF _ because ttf files will not be installed on the system when opening pdf +_ maybe just add this to the reference so that people know _ text position is quantized in JAVA2D _ http://dev.processing.org/bugs/show_bug.cgi?id=806 _ accessors inside PFont need a lot of work @@ -115,9 +125,9 @@ _ http://dev.processing.org/bugs/show_bug.cgi?id=466 _ textAlign(CENTER) with P3D and OPENGL produces messy result _ probably rounding error with the images _ http://dev.processing.org/bugs/show_bug.cgi?id=475 -_ textures truly did get worse in P3D +X textures truly did get worse in P3D _ problem is that bilinear is turned on by default starting in 0124(?) -_ http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Programs;action=display;num=1205171649 +X http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Programs;action=display;num=1205171649 _ when turning smoothing on, internal lines of shapes are visible _ add an edge flag when tesselating _ mind the opengl tesselation flags @@ -127,8 +137,6 @@ _ in opengl mode, use its tesselator _ because the vertex calls can just come right back to regular vertex calls _ this way we can also implement breakShape() for opengl _ http://dev.processing.org/bugs/show_bug.cgi?id=947 -_ PPolygon no longer in use and PLine is a mess -_ make a version of PGraphics3 that uses it for more accurate rendering? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . @@ -159,10 +167,6 @@ _ when closing a sketch via the close box, make sure stop() getting called X found a problem for release 0133 _ test to see if it's working -_ ArrayIndexOutOfBoundsException in PLine -_ http://dev.processing.org/bugs/show_bug.cgi?id=246 -_ http://dev.processing.org/bugs/show_bug.cgi?id=462 - _ STROKE_WEIGHT field in PGraphics3 is a disaster, because it's an int _ use the SW from vertex instead.. why set stroke in triangle vars at all? _ currently truncating to an int inside add_line_no_clip @@ -354,8 +358,6 @@ CORE / PGraphics3D _ make thick lines draw perpendicular to the screen with P3D _ http://dev.processing.org/bugs/show_bug.cgi?id=956 -_ random AIOOBE with P3D and points -_ http://dev.processing.org/bugs/show_bug.cgi?id=937 _ ortho() behaving differently in P3D vs OPENGL _ http://dev.processing.org/bugs/show_bug.cgi?id=100 _ shows a blank canvas diff --git a/todo.txt b/todo.txt index 68d68c391..9d876fdf8 100644 --- a/todo.txt +++ b/todo.txt @@ -2,6 +2,7 @@ o Fix error message spew on Linux when using "Save As" X http://dev.processing.org/bugs/show_bug.cgi?id=951 X can't fix, it's a sun bug +X Change sketch naming error to only print to the console thread hang/block problem