Advertisement



Go Back   Zune Boards > Zune Discussions > Zune Games > Development Discussions

New Member?



 
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Development Discussions All developers who are coding games may stop by here for any help, suggestions, and everything development related.

Reply
 
LinkBack Thread Tools
Old 07-12-2008, 04:34 PM   #1 (permalink)
Zuner
 
CouchPotato99's Avatar
 
Join Date: May 2008
Posts: 75
Reputation: 53
Default Album Art


Please help, this is really frustrating me. I'm working on a music component for my game and I want to include album art. If I use this code:
Code:
spriteBatch.Draw(album.GetAlbumArt(game.Services), new Rectangle(somewhere), Color.White);
I run out of memory eventually. I read this thread on the XNA forums, which says to dispose of the album art and then you won't run out of memory. That's all fine and dandy, but once I dispose of the album art I can't draw it the next time the draw method is called. I was using this code:
Code:
if (album.HasArt)
{
    Texture2D a = album.GetAlbumArt(game.Services);
    spriteBatch.Draw(a, new Rectangle(somewhere), Color.White);
    a.Dispose();
}
Anyways, how can I draw album art while not running out of memory? I want to be able to draw about 7 albums at a time. Any help is greatly appreciated.







CouchPotato99 is offline   Reply With Quote
Old 07-12-2008, 06:21 PM   #2 (permalink)
Jr. Member
 
Tiptup300's Avatar
 
Join Date: Apr 2008
Posts: 392
Reputation: 121
Default

GetAlbumArt() is a very intense method. You should do it once per album in the entire program. Doing it each frame just shows how terrible of a programmer you are.



Tiptup300 is offline   Reply With Quote
Old 07-12-2008, 06:29 PM   #3 (permalink)
Zuner
 
CouchPotato99's Avatar
 
Join Date: May 2008
Posts: 75
Reputation: 53
Default

Quote:
Originally Posted by Tiptup300 View Post
GetAlbumArt() is a very intense method. You should do it once per album in the entire program. Doing it each frame just shows how terrible of a programmer you are.
So then calling it for every single album at the start of my program is a better option? Won't I just end up with hundreds of textures then? That doesn't sound like it will help the memory problem. Is there another solution?




CouchPotato99 is offline   Reply With Quote
Old 07-12-2008, 07:38 PM   #4 (permalink)
Jr. Member
 
SimReality's Avatar
 
Join Date: May 2008
Posts: 410
Reputation: 60
Default

No, no, no. Misinformation abound here. GetAlbumArt being "intensive" has nothing to do with it. In fact, that method is really quick at doing what it does. What is relevant is that the texture it returns is not automatically disposed. This means that it doesn't ever unload the texture data without you manually unloading it. You can choose to load it all up front, but that's rather memory wasteful, especially if you only need to show a handful of art at a time.

What you want to do is keep a reference to the texture somewhere. So in whichever class you're wanting the art, put this:

Texture2D albumArt;

Then whenever you want to get the album art to draw (like when the user changes what is selected or whenever it is that this needs to change), you want to make sure to dispose of the old texture and then call the GetAlbumArt method:

if (albumArt != null && !albumArt.IsDisposed)
albumArt.Dispose();
albumArt = album.GetAlbumArt(Game.Services);

Then feel free to render it all you want. You might also want to safeguard your draw method to make sure the album is valid:

if (albumArt != null && !albumArt.IsDisposed)
spriteBatch.Draw(albumArt, ....);



SimReality is offline   Reply With Quote
Old 07-12-2008, 09:10 PM   #5 (permalink)
Zuner
 
CouchPotato99's Avatar
 
Join Date: May 2008
Posts: 75
Reputation: 53
Default

Quote:
Originally Posted by SimReality View Post
What you want to do is keep a reference to the texture somewhere. So in whichever class you're wanting the art, put this:

Texture2D albumArt;

Then whenever you want to get the album art to draw (like when the user changes what is selected or whenever it is that this needs to change), you want to make sure to dispose of the old texture and then call the GetAlbumArt method:

if (albumArt != null && !albumArt.IsDisposed)
albumArt.Dispose();
albumArt = album.GetAlbumArt(Game.Services);

Then feel free to render it all you want. You might also want to safeguard your draw method to make sure the album is valid:

if (albumArt != null && !albumArt.IsDisposed)
spriteBatch.Draw(albumArt, ....);
Thank you so much for the help. I've got it working now. You're really helpful! Microsoft should make you an MVP or something...




CouchPotato99 is offline   Reply With Quote
Old 07-12-2008, 09:19 PM   #6 (permalink)
Jr. Member
 
SimReality's Avatar
 
Join Date: May 2008
Posts: 410
Reputation: 60
Default

Quote:
Originally Posted by CouchPotato99 View Post
Thank you so much for the help. I've got it working now. You're really helpful! Microsoft should make you an MVP or something...



SimReality is offline   Reply With Quote
Old 07-12-2008, 11:30 PM   #7 (permalink)
Jr. Member
 
Tiptup300's Avatar
 
Join Date: Apr 2008
Posts: 392
Reputation: 121
Default

Quote:
Originally Posted by SimReality View Post
No, no, no. Misinformation abound here. GetAlbumArt being "intensive" has nothing to do with it. In fact, that method is really quick at doing what it does. What is relevant is that the texture it returns is not automatically disposed. This means that it doesn't ever unload the texture data without you manually unloading it. You can choose to load it all up front, but that's rather memory wasteful, especially if you only need to show a handful of art at a time.

What you want to do is keep a reference to the texture somewhere. So in whichever class you're wanting the art, put this:

Texture2D albumArt;

Then whenever you want to get the album art to draw (like when the user changes what is selected or whenever it is that this needs to change), you want to make sure to dispose of the old texture and then call the GetAlbumArt method:

if (albumArt != null && !albumArt.IsDisposed)
albumArt.Dispose();
albumArt = album.GetAlbumArt(Game.Services);

Then feel free to render it all you want. You might also want to safeguard your draw method to make sure the album is valid:

if (albumArt != null && !albumArt.IsDisposed)
spriteBatch.Draw(albumArt, ....);
GetAlbumArt() takes about a second to work, well on my zune it does.



Tiptup300 is offline   Reply With Quote
Old 07-12-2008, 11:38 PM   #8 (permalink)
Jr. Member
 
SimReality's Avatar
 
Join Date: May 2008
Posts: 410
Reputation: 60
Default

Well I guess I don't think of that as that long. Either way, his issue was memory. How long that method takes to do its job has no affect on memory usage.



SimReality is offline   Reply With Quote
Old 07-12-2008, 11:45 PM   #9 (permalink)
Jr. Member
 
Tiptup300's Avatar
 
Join Date: Apr 2008
Posts: 392
Reputation: 121
Default

Yeah, it's still terrible to use it every frame! The problem wasn't directly related to the question.

Heres a quote to better explain:
Quote:
<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"
<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers



Tiptup300 is offline   Reply With Quote
Old 07-12-2008, 11:59 PM   #10 (permalink)
Jr. Member
 
SimReality's Avatar
 
Join Date: May 2008
Posts: 410
Reputation: 60
Default

Hehe. Point taken.



SimReality is offline   Reply With Quote
Old 07-13-2008, 12:13 PM   #11 (permalink)
Experienced Zuner
 
Join Date: Nov 2007
Posts: 112
Reputation: 38
Default

Quote:
Originally Posted by Tiptup300 View Post
GetAlbumArt() is a very intense method. You should do it once per album in the entire program. Doing it each frame just shows how terrible of a programmer you are.
... that was totally unnecessary, I think a lot of people made that mistake when they first tried using it. It's not immediately obvious that the zune wouldn't already have the album art in memory and would have to go to the harddrive every time. Jeeze, no need to insult the guy.
__________________
-Mark
Check out my new game, "Squadron Z":
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


Check out my version of pong with multiplayer:
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.



MarcusMaximus is offline   Reply With Quote
Old 07-13-2008, 09:31 PM   #12 (permalink)
Jr. Member
 
Tiptup300's Avatar
 
Join Date: Apr 2008
Posts: 392
Reputation: 121
Default

Yeah I guess I was being a douche. Sorry



Tiptup300 is offline   Reply With Quote
Old 07-13-2008, 11:08 PM   #13 (permalink)
Zuner
 
CouchPotato99's Avatar
 
Join Date: May 2008
Posts: 75
Reputation: 53
Default

Quote:
Originally Posted by Tiptup300 View Post
Yeah I guess I was being a douche. Sorry
No worries. Just remember...



kthxbai




CouchPotato99 is offline   Reply With Quote
Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT -8. The time now is 08:34 PM.

 
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.2.0 RC8
vB Ad Management by =RedTyger=
(C) ZuneBoards 2006-2007
Copyright © 2006 - 2008 Zune Boards | About Zune Boards | Legal | A member of the Crowdgather Forum Community