Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
setTextureCoordinate() crashes after so many items in array — Gideros Forum

setTextureCoordinate() crashes after so many items in array

JohnJohn Member
edited January 16 in Bugs and issues
I'm writing one of those circular progress bars using mesh and it works fine until adding around 47th item. Each loop I call clearTextureCoordinateArray() before calling a series of setTextureCoordinate() which eventually crashes.

If I add resizeTextureCoordinateArray() after the clear then it all works fine.

self.m_timerMesh:clearTextureCoordinateArray()
self.m_timerMesh:resizeTextureCoordinateArray(200)


According to this page:https://wiki.giderosmobile.com/index.php/Mesh:setTextureCoordinate

Indices start from 1. If the texture coordinate array is not large enough, it is automatically expanded.

That does not seem to be the case here.

Comments

  • https://wiki.gideros.rocks/index.php/Mesh
    the Mesh class doesn't do bounds check: if an element at index array points to an non-existent vertex, the application may crash


    That may be the issue here?
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
  • JohnJohn Member
    If it was then I doubt self.m_timerMesh:resizeTextureCoordinateArray(200) would fix that particular problem. Also, if I don't use texture at all that too work fine and so the vertex and index are correct and it visually looks correct too without any crashes.
  • JohnJohn Member
    I'll post some code if it not reproducible - I am a little too busy at the moment and I need to extract it from full project with minimum amount of code / images.

    Likes: MoKaLux, hgy29

    +1 -1 (+2 / -0 )Share on Facebook
  • hgy29hgy29 Maintainer
    I reviewed current Gideros code and it could crash if:
    - you attempt to set texture coordinate at an index below 1 (I will add a check for this in the code, but I doubt this is your issue)
    - your indices array contains an index pointing outside your texture (or vertex, or color) array while rendering the frame. This is the case @MoKaLux mentionned.

    So since your clear your texture coordinates and fill them up afterwise, do you also clear your index array at the same time ?
  • JohnJohn Member
    I've managed to replicate it without texture being involved so there is no images required. If you run this code, it works first time and on the second attempt it crashes. It is probably something in my code, still you may want to check it out to make sure it isn't something else. I ended up doing it a different way without using mesh in the end.
    cSpawnPoint = Core.class(Sprite)
     
    function cSpawnPoint:init(screen)
        local mypixel = Pixel.new(0x0000FF, 1, 1024, 1024)
    	mypixel:setAnchorPoint(0.5, 0.5)
    	screen:addChild(mypixel)
     
        self:setAnchorPoint(0.5, 0.5)
     
    	self.m_textureTimerOffsetX = 0
    	self.m_textureTimerOffsetY = 0
     
        self.m_textureTimerW = 300
    	self.m_textureTimerH = 300
     
        self.m_timerMesh = Mesh.new()
        self.m_timerMesh:setAnchorPoint(0.5, 0.5)
        self.m_timerMesh:setPosition(0, 0)
        self:addChild(self.m_timerMesh)
     
    	self:setPosition(0, 0)
     
        screen:addChild(self)
     
        self.m_x = 0
        self.m_y = 0
     
    	self.m_tick = 0
     
    	self:addEventListener(Event.ENTER_FRAME, self.timer, self)
    end
     
    function cSpawnPoint:timer()
    	self.m_tick += (1 / 120)
    	if self.m_tick > 1 then
    		self.m_tick = 1
    		self:removeEventListener(Event.ENTER_FRAME, self.timer, self)
    	end
    	self:createTimerMesh(self.m_tick)
    end
     
    function cSpawnPoint:createTimerMesh(timer)
     
    	print("Processing timer:",timer)
        local xPos = 0
        local yPos = 0
     
        local outerRadius = (self.m_textureTimerW / 2)
        local innerRadius = outerRadius - 25
     
        local radius1 = innerRadius
        local radius2 = outerRadius
     
        local tau = math.pi * 2
     
        local segmentStart = 0.0
        local segmentEnd = tau * timer
        local quarterOfCircle = math.pi * 0.5
        local endOfCircle = tau
     
        segmentStart -= quarterOfCircle
        segmentEnd -= quarterOfCircle
        endOfCircle -= quarterOfCircle
     
        self.m_timerMesh:clearVertexArray()
        self.m_timerMesh:clearIndexArray()
     
        self:drawSegmentedCircle(0xffffff, xPos, yPos, segmentStart, segmentEnd, radius1, radius2)
     end
     
    function cSpawnPoint:drawSegmentedCircle(ARGB, xPos, yPos, segmentStart, segmentEnd, radius1, radius2)
        local tau = (math.pi * 2)
        local quadarantSmoothness = tau / 90
     
        self.m_meshIndex = 1
     
        self:addCircleVertextPoint(xPos, yPos, radius1, segmentStart)
        self:addCircleVertextPoint(xPos, yPos, radius2, segmentStart)
     
        local odd = false
     
        segmentStart += quadarantSmoothness
        local r
        while (segmentStart < segmentEnd) do
            r = odd and radius2 or radius1
     
            self:addCircleVertextPoint(xPos, yPos, r, segmentStart)
     
            segmentStart += quadarantSmoothness
            odd = not odd
        end
     
    	r = odd and radius2 or radius1
    	self:addCircleVertextPoint(xPos, yPos, r, segmentEnd)
     
    	r = odd and radius1 or radius2
    	self:addCircleVertextPoint(xPos, yPos, r, segmentEnd)
     
    	local z = 1
        for i = 1, self.m_meshIndex - 3 do
            self.m_timerMesh:setIndex(z, i)
            self.m_timerMesh:setIndex(z + 1, i + 1)
            self.m_timerMesh:setIndex(z + 2, i + 2)
    		print(z, i, self.m_timerMesh:getIndex(z), self.m_timerMesh:getIndex(z + 1), self.m_timerMesh:getIndex(z + 2))
    		z += 3
        end
        print("Setup complete: self.m_meshIndex=", self.m_meshIndex - 3, "m_timerMesh:getIndexArraySize()=", self.m_timerMesh:getIndexArraySize(), "m_timerMesh:getVertexArraySize()=", self.m_timerMesh:getVertexArraySize(), "(self.m_meshIndex - 3) * 3=", (self.m_meshIndex - 3) * 3)
    end
     
    function cSpawnPoint:addCircleVertextPoint(xPos, yPos, radius, radians)
        local x = xPos + math.cos(radians) * radius
        local y = yPos + math.sin(radians) * radius
     
     
        self.m_timerMesh:setVertex(self.m_meshIndex, x, y)
     
    	local vx, vy = self.m_timerMesh:getVertex(self.m_meshIndex)
     
    	print(self.m_meshIndex, vx, x, vy, y)
     
        self.m_meshIndex += 1
    end
     
    function main()
    	stage:setPosition( 1024 / 2, 768 / 2)
    	cSpawnPoint.new(stage)
    end
     
    main()

    Likes: MoKaLux

    +1 -1 (+1 / -0 )Share on Facebook
  • MoKaLuxMoKaLux Member
    edited January 19
    John said:

    If you run this code, it works first time and on the second attempt it crashes.

    I tried your code and it didn't crash even the second time (relaunched from Gideros Studio).

    There is also this one from hgy29 that may suit your needs?
    https://wiki.gideros.rocks/index.php/Ftf_snippets#CIRCULAR_PROGRESS_.40hgy29

    EDIT: I am on windows 11
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
  • JohnJohn Member
    I've already created an alternative solution for this progress bar - Ta. I've updated to latest Gideros and it still crashes. This is on the Mac by the way so maybe this may explain why it works for you if you are on a different OS and not for me? I'll post the crash report if the popup reappear. At the moment it doesn't show anything - probably due to crashing too many times.
Sign In or Register to comment.