Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
eockh
Visitor

calling Remove on a sprite

So I think I'm missing something here, but I'm calling remove on a sprite and then telling the compositor to draw but it appears that the sprite I just removed is still being drawn by the compositor. What are the standard steps for removing a sprite from the screen? Thanks!
0 Kudos
17 REPLIES 17
RokuJoel
Binge Watcher

Re: calling Remove on a sprite

I'm wondering, are you calling compositor.drawall() and calling swapbuffers() or finish() at the end of each iteration?

- Joel
0 Kudos
eockh
Visitor

Re: calling Remove on a sprite

Yes..so in pseudo code

sprite = compositor.newsprite
compositor.draw
screen.swapbuffers
sprite.remove
compositor.draw
screen.swapbuffers

I will still see what the original sprite drew.
0 Kudos
eockh
Visitor

Re: calling Remove on a sprite

also to note, I have other sprites still in the compositor if that makes a difference.
0 Kudos
RokuJoel
Binge Watcher

Re: calling Remove on a sprite

try drawall() instead of draw() ?

- Joel
0 Kudos
MazeWizzard
Visitor

Re: calling Remove on a sprite

Hmmm...no reply yet. So...

How about:

Are you regenerating the entire frame each time? You should either clear the screen and draw, or fill it with a background bitmap and then draw. The "old" sprite shouldn't be there. If it still is...maybe the remove failed?
0 Kudos
RokuJoel
Binge Watcher

Re: calling Remove on a sprite

Here's a little example of removing a sprite. Mind you, I'm not invalidating the underlying region and bitmap here, which you might need to do if you run out of video memory, but I don't think that is an issue with the way I'm doing this:

https://www.box.com/shared/jbetbkjcus4iyw25uejb

sub main()

l=listdir("pkg:/images")
regarray=[]
for each item in l
bmp=createobject("robitmap","pkg:/images/"+item)
reg=createobject("roregion",bmp,0,0,bmp.getwidth(),bmp.getheight())
regarray.push(reg)
end for

screen=createobject("roscreen",true)
compositor=createobject("rocompositor")
compositor.setdrawto(screen,&h000000FF)
timer=createobject("rotimespan")
timer.mark()
i=0
spr=compositor.newsprite(100+rnd(300),100+rnd(300),regarray[0])
while true
screen.clear(&h000000FF)
if timer.totalseconds() > 5 then
i=i+1
if i > regarray.count()-1 then i=0
spr.remove()
spr=compositor.newsprite(100+rnd(300),100+rnd(300),regarray[i])
timer.mark()
end if
compositor.drawall()
screen.swapbuffers()
end while

end sub
0 Kudos
eockh
Visitor

Re: calling Remove on a sprite

RokuJoel,

Thanks for the response. Turns out I was calling draw() on the compositor at the wrong time which was causing artifacts. Removing that and enforcing a drawall call made it work properly.
0 Kudos
olarurazvan
Visitor

Re: calling Remove on a sprite

Hi everyone,

I'm currently trying to create an app which has a vast list of items represented by sprites (about 1000). In order to avoid video memory depletion I keep only 6 sprites drawn on the screen at a time. When scrolling the list, the last item (from those 6 drawn) is deleted and the next item is drawn and so on. I delete the sprites using sprite.remove() method and then assigning the sprite an invalid value (and also invalidate the related region and bitmap) but it still seems that after scrolling about 400 items the memory gets depleted.

"RokuJoel" wrote:
Mind you, I'm not invalidating the underlying region and bitmap here, which you might need to do if you run out of video memory, but I don't think that is an issue with the way I'm doing this


Here is how I invalidate the sprite and the related region and bitmap:

purgeSprite: function(sprite as Object) as Void

if type(sprite) = "roSprite"

' Get the region and bitmap of the sprite
region = sprite.getRegion()
bitmap = region.getBitmap()

' Remove the sprite and invalidate it
sprite.remove()
sprite = invalid

' Invalidate the region and bitmap
region = invalid
bitmap = invalid

print "| Sprite purged!"
end if

' After exiting this method, the memory that the sprite used
' (altogether with the bitmap and region) should be removed.

end function


Could you please tell me why the memory still gets depleted?
0 Kudos
NewManLiving
Visitor

Re: calling Remove on a sprite

look at what your doing. Creating a local variable to reference other objects then setting the local variable back to invalid does not remove the original bitmap.
l_b = createobject("roBitmap", ...)
l_a = l_b
Two references
L_a = invalid
One reference
Has no effect on l_b. It still exists
My Channels: 2D API Framework Presentation: https://owner.roku.com/add/2M9LCVC
Updated: 11-11-2015 - Completed Keyboard interface
The Joel Channel ( Final Beta )
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.