Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Line:Append Broken :(
Started by Ninja Pig Studios Oct 17 2013 03:58 PM

18 replies to this topic
line:append append line drawing
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

Ninja Pig Studios

[GLOBAL: userInfoPane.html]
Ninja Pig Studios
  • Contributor

  • 572 posts
  • Corona SDK

Hello Corona Team,

 

Line:Append seems to be broken with the new graphics engine.  When your drawing and appending the line in real time, the line turns all different colors which flashing and glitching.  Could you please look at this and try to fix this issue :D

 

Thanks <3



[TOPIC: post.html]
#2

Bryan01

[GLOBAL: userInfoPane.html]
Bryan01
  • Enthusiast

  • 95 posts
  • Corona Staff

@ninjapig We will look into this - do you have some sample project you can send myself or Walter?



[TOPIC: post.html]
#3

Ninja Pig Studios

[GLOBAL: userInfoPane.html]
Ninja Pig Studios
  • Contributor

  • 572 posts
  • Corona SDK

@ninjapig We will look into this - do you have some sample project you can send myself or Walter?

local localGroup = display.newGroup()
local backback = display.newGroup()
local backback2 = display.newGroup()
local randomGroup = display.newGroup()
circleGroup = display.newGroup()
 
localGroup:insert(backback2)
localGroup:insert(backback)
localGroup:insert( circleGroup )
 
-------------------------------------
----Have user draw then send data----
-------------------------------------
local endPoint, startPoint
local lines, line, lx, ly, sx, sy = {}
local points = {}
--r,g,b = 255,0,0
lineWidth = 2
local drawPacket
 
local odd = true
 
local function draw(event)
    if event.phase == "began" then
        --Create the startpoint and endpoint of the line
        startPoint = display.newCircle(0,0,lineWidth/2)
        startPoint.x, startPoint.y = event.x, event.y
        startPoint:setFillColor(r,g,b) 
 
        endPoint = display.newCircle(-100,0,lineWidth/2) 
        endPoint:setFillColor(r,g,b)
 
        circleGroup:insert(startPoint)
        circleGroup:insert(endPoint)
 
    elseif event.phase == "moved" then
        if not line then
            if startPoint ~= nil then
            print "I am now drawing the line"
              
            --Append every point on the line depending one where the users finger is
            line = display.newLine(startPoint.x, startPoint.y, event.x, event.y)
            lines[ #lines + 1 ] = line
            line.width = lineWidth
            line:setColor(r,g,b)
 
            lx,ly = startPoint.x , startPoint.y
            sx,sy = event.x, event.y
 
            circleGroup:insert(line)
        end
        else
            if math.sqrt((lx-event.x)^2+(ly-event.y)^2) > 5 then
                --print "I am now appending the line"
                line:append( event.x, event.y)
                lx, ly = event.x, event.y
                local dumb = display.newLine(-10,-10,-100,-100) --Create some **** that is a corona bug
                display.remove( dumb )
 
            end
 
            endPoint.x = event.x
            endPoint.y = event.y
 
            if odd then
 
                points[#points+1] = event.x
                points[#points+1] = event.y
 
            end
            odd = not odd
        end
    elseif event.phase == "ended" then
        if endPoint ~= nil then
        line = nil
        endPoint.x, endPoint.y = event.x, event.y
        print "I have ended my touch, sending data"
 
 
        points = {} --Reset Points table
        print "Points table reset"
        end
    end
end
 
Runtime:addEventListener("touch", draw)


[TOPIC: post.html]
#4

Fat Red Couch

[GLOBAL: userInfoPane.html]
Fat Red Couch
  • Enthusiast

  • 34 posts
  • Corona SDK

I'm experiencing the same thing as well. Also: are image stroke and fills supposed to work with lines as they do with circles, rectangles, and polygons?



[TOPIC: post.html]
#5

rakoonic2

[GLOBAL: userInfoPane.html]
rakoonic2
  • Contributor

  • 503 posts
  • Corona SDK

I've just used line:append without problem in my JSON importer - note this is version 2013.2018.

I add a ton of points to a line with the following code:

line:append( unpack( points ) )

I have not worked with anything except lines and polygons, but I did note that in the case of the line, the line itself IS the stroke, so to make a fatter line or to colour it you use .strokeWidth and :setStrokeColor() which stumped me for a bit when I first tried using other properties and the :setFillColor() function instead.



[TOPIC: post.html]
#6

scott0

[GLOBAL: userInfoPane.html]
scott0
  • Enthusiast

  • 79 posts
  • Corona SDK

+1 on this.  My code which implements finger drawing (basically line:append as the touch move events are fired) behaves like ninjapig describes.   Colors are constantly changing, and include gradients.  It also appears to behave like a polygon -- Corona is rendering a line segment between the first and last point on the line.  I believe the mitigating factor is that we're calling line:append across frames.



[TOPIC: post.html]
#7

Ninja Pig Studios

[GLOBAL: userInfoPane.html]
Ninja Pig Studios
  • Contributor

  • 572 posts
  • Corona SDK

Wanted to let you know that I got an email from the Corona Bugs team and they apparently fixed it in the most recent daily build. I haven't gotten to test it for myself yet.

+1 on this.  My code which implements finger drawing (basically line:append as the touch move events are fired) behaves like ninjapig describes.   Colors are constantly changing, and include gradients.  It also appears to behave like a polygon -- Corona is rendering a line segment between the first and last point on the line.  I believe the mitigating factor is that we're calling line:append across frames.



[TOPIC: post.html]
#8

scott0

[GLOBAL: userInfoPane.html]
scott0
  • Enthusiast

  • 79 posts
  • Corona SDK

It doesn't appear to be fixed in 2076, which is today's public g2.0 release.



[TOPIC: post.html]
#9

StarCrunch

[GLOBAL: userInfoPane.html]
StarCrunch
  • Contributor

  • 817 posts
  • Corona SDK

I also just ran into this... and of course in the project you're following a line around. :/

 

The "real time" part seems to be key. Some tests seem to show that lines work okay if you make them, do all your appends, and never touch them again (which should account for rakoonic's case). But if the append() calls are distributed across frames, something goes awry.

 

I'm seeing the polygon-ish thing scott0 mentions too, but I wonder if it isn't just undefined behavior. I almost suspect the VBO for the line mesh is being generated on demand before the render call, but only the first time, and then is missing a check to see if it grew on the next frame... and then glBufferSubData() happily stomps on unallocated memory.

 

On that note, is anybody else running out of memory or seeing it lock up?

 

(As a workaround I'll probably just hold onto the most recent vertices and rebuild the line each frame, maybe baking it every now and then so the list doesn't grow huge.)



[TOPIC: post.html]
#10

scott0

[GLOBAL: userInfoPane.html]
scott0
  • Enthusiast

  • 79 posts
  • Corona SDK

I submitted a bug report for this, and included the code below which demonstrates the problem.

 

local myline = display.newLine(160,240,170,250)
myline.strokeWidth=5
myline:setStrokeColor(1,1,1)
 
local function append1()
    myline:append(190,250)
end
 
local function append2()
    myline:append(190,300)
end
 
 
timer.performWithDelay(1000,append1)
timer.performWithDelay(2000,append2)


[TOPIC: post.html]
#11

Stephen Lewis

[GLOBAL: userInfoPane.html]
Stephen Lewis
  • Contributor

  • 716 posts
  • Enterprise

I'm trying to convert a project to G2.0 and I'm now seeing the line:append causing a rainbow of colors effect.  Any news on a fix for this?  



[TOPIC: post.html]
#12

Stephen Lewis

[GLOBAL: userInfoPane.html]
Stephen Lewis
  • Contributor

  • 716 posts
  • Enterprise

After more testing of my particular usage, I see the rainbow color bug simply by changing a line's width using a transition.  Here's a simple test case demoing the problem.  Run it on G2.0/daily2076 to see the rainbow:

 

local testline = display.newLine(50,50, 300,400)
testline.width = 50
transition.to(testline, {time = 5000, width = 1})   --This causes rainbow G2.0 bug
 

 

  I filed a new bug, case 28115, since this version has nothing to do with line:append


[TOPIC: post.html]
#13

StarCrunch

[GLOBAL: userInfoPane.html]
StarCrunch
  • Contributor

  • 817 posts
  • Corona SDK

 
 I see the rainbow color bug simply by changing a line's width using a transition. 

 

That might just be because of the "width" field, which has since become "strokeWidth". Otherwise, it seems to invalidate my earlier theory.  :)

 

As for the workaround I mentioned, it did seem to work in my own case, though it's pretty craptacular, only handles one line, and I'm sure it would be a hassle if you need to maintain "old" parts of the line that have broken off.

 

local LINE, POINTS, N

local function Append (group, x, y)
	if N < 50 then
	display.remove(LINE)
		POINTS[N+1], POINTS[N+2] = x, y
		N = N + 2
	else
		POINTS[1], POINTS[2], POINTS[3], POINTS[4] = POINTS[49], POINTS[50], x, y
		N=4
	end
 
	LINE = display.newLine(group, POINTS[1], POINTS[2], POINTS[3], POINTS[4])
	if N > 4 then
		LINE:append(unpack(POINTS, 5, N))
	end

	LINE:setStrokeColor(1, 0, 0)

	LINE.strokeWidth = 4
end

-- Somewhere below, level setup:
POINTS, N, LINE = {}, 0


[TOPIC: post.html]
#14

Stephen Lewis

[GLOBAL: userInfoPane.html]
Stephen Lewis
  • Contributor

  • 716 posts
  • Enterprise

@StarCrunch,  I tested with width and strokeWidth and both "work" in the sense that they both change the width of the line and have the rainbow defect.  

 

Since we're all finding multiple ways to see the rainbow it must be a deeper issue with line rendering. I'm concerned that this has been known about for at least a month and made it into the public release without a peep of acknowledgement from the Corona folks.  

 

 

-Stephen



[TOPIC: post.html]
#15

ksan

[GLOBAL: userInfoPane.html]
ksan
  • Corona Geek

  • 2,795 posts
  • Corona SDK

Here's an ironic throwback... Almost 18 months to the day...

 

http://www.coronalabs.com/blog/2012/05/15/corona-engineering-next-release-and-more/

 

Read midway in reader comments and you will see @Ninja Pig Studios talking about the same issue... 

 

 



[TOPIC: post.html]
#16

Ninja Pig Studios

[GLOBAL: userInfoPane.html]
Ninja Pig Studios
  • Contributor

  • 572 posts
  • Corona SDK

Here's an ironic throwback... Almost 18 months to the day...

 

http://www.coronalabs.com/blog/2012/05/15/corona-engineering-next-release-and-more/

 

Read midway in reader comments and you will see @Ninja Pig Studios talking about the same issue... 

 

The funny thing is ksan is they fixed it, then with graphics 2.0 it broke again.  Now that I addressed the issue it works fine :D funny how the same bugs can happen again with a new engine in place :D



[TOPIC: post.html]
#17

walter

[GLOBAL: userInfoPane.html]
walter
  • Moderator

  • 726 posts
  • Alumni

Thanks all for the info, we're looking into this.



[TOPIC: post.html]
#18

Stephen Lewis

[GLOBAL: userInfoPane.html]
Stephen Lewis
  • Contributor

  • 716 posts
  • Enterprise

Seems to be fixed for me in daily build 2082.  Thanks, Walter et al.



[TOPIC: post.html]
#19

scott0

[GLOBAL: userInfoPane.html]
scott0
  • Enthusiast

  • 79 posts
  • Corona SDK

ditto - working as it should in 2085 for me.

Thanks




[topic_controls]
[/topic_controls]