XNA Game Development Forums
2012/02/05 10:51:04 *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Search Calendar Login Register  
Pages: [1]
  Print  
Author Topic: Tutorial 6 :: Getting a Model on Screen  (Read 5360 times)
mikeschuld
Administrator
Sr. Member
*****
Offline Offline

Posts: 389


View Profile WWW
« on: 2006/11/30 05:57:14 »

Same as always
« Last Edit: 2007/01/07 03:34:50 by mikeschuld » Logged
DarkSabre
Newbie
*
Offline Offline

Posts: 2


View Profile
« Reply #1 on: 2007/01/15 10:22:16 »

hey got a question about this tut.  I went ahead and did the whole tutorial and copied the tiger.x and bmp over and when i try to compile my project it give me an error saying "More than one output asset is named "bin/x86/Debug/Content/Models/tiger.xnb". you must explicitly specify asset names to resolve this conflict? did i miss something? thought i did everything right lemme go back and check my work.  just wondering cause the error keeps popping to the tiget.x file
Logged
mikeschuld
Administrator
Sr. Member
*****
Offline Offline

Posts: 389


View Profile WWW
« Reply #2 on: 2007/01/15 10:36:09 »

thats because when you auto import files into the Content folder in visual studio, it names them based on the file name minus the extension. Just remove the texture from the content folder in the project, it only has to be physically in the same folder as the .x file and not included in the project itself.
Logged
DarkSabre
Newbie
*
Offline Offline

Posts: 2


View Profile
« Reply #3 on: 2007/01/15 14:02:44 »

OH thanx i got it!
Logged
nkr
Newbie
*
Offline Offline

Posts: 6


View Profile
« Reply #4 on: 2007/01/31 02:30:59 »

Mike,

I have a problem Sad

My model is appearing semi-transparent... how can I fix that?

See image below



Thanks a lot,

Marcelo
Logged
Nemo Krad
Global Moderator
Hero Member
*****
Offline Offline

Posts: 512


I have seen the fnords


View Profile WWW
« Reply #5 on: 2007/01/31 02:38:19 »

It look to me that your camera is inside the model. Have you moved the camera away from the model as much as you can?
Logged
nkr
Newbie
*
Offline Offline

Posts: 6


View Profile
« Reply #6 on: 2007/01/31 02:43:30 »

Oh thats right... Thanks Cheesy
Logged
loki
Newbie
*
Offline Offline

Posts: 5


View Profile
« Reply #7 on: 2007/02/13 16:29:59 »

Hi All!

First of all, thanx a lot for the insights in these tutors... you gotta love it! ;-)

straight to the point now:
I noticed (while keeping an eye on memory consumption of a running test with around 100 models, tutorial 6 models, that is) that the memory consumption gradually goes up, every time the model's RenderChildren() method is called.  Gradually, it consumes more and more memory, looking like a memory leak.
I couldn't directly figure out what was causing it, so I started outcommenting specific parts of the engine to narrow down the problem area.  I quickly found the the following piece of code (tutorial 6) is causing the problem:


            // Make sure we use the texture for the current part also
            myDevice.Textures[0] = ((BasicEffect)part.Effect).Texture;

            // Finally draw the actual triangles on the screen
            myDevice.DrawIndexedPrimitives(
               PrimitiveType.TriangleList,
               part.BaseVertex, 0,
               part.NumVertices,
               part.StartIndex,
               part.PrimitiveCount
            );

to be more precise: the line
myDevice.Textures[0] = ((BasicEffect)part.Effect).Texture;

I guess this is because of the cast...

I changed it to a fix with the 'using' statement, thus forcing object disposal, as such:

                            using (Texture2D tex = ((BasicEffect)part.Effect).Texture)
                            {
                                gfxdevice_p.Textures[0] = tex;

                                // Finally draw the actual triangles on the screen
                                gfxdevice_p.DrawIndexedPrimitives(PrimitiveType.TriangleList,
                                                                part.BaseVertex,
                                                                0,
                                                                part.NumVertices,
                                                                part.StartIndex,
                                                                part.PrimitiveCount);
                            }

which seems to do the trick...

What precisely is going on under the hood to cause this memory-leak-like behaviour? or is it just the Garbage Collector _not_ kicking in early enough?  After a while, the memory consumption became so huge, that the complete game was stuttering.  To be avoided, definitely ;-)

keep up the good work!

I noticed a brand new tutorial was added today, tutor 12.. great!  Will read that one right now, and post you some code in the 'showoff' section too.

greetz,
Frank Verheyen
Logged
mikeschuld
Administrator
Sr. Member
*****
Offline Offline

Posts: 389


View Profile WWW
« Reply #8 on: 2007/02/13 17:26:32 »

You are most likely right in guessing that the garbage collector is the problem. This becomes an even bigger issue when the code is running on the .NET CF on the Xbox. Nice work catching the 'leaks'.

BTW what tool are you using to diagnose these things?
Logged
loki
Newbie
*
Offline Offline

Posts: 5


View Profile
« Reply #9 on: 2007/02/14 02:33:47 »

I don't really use special tools to catch leaks like this...  I just stumbled upon it when I saw the memory footprint go up, although I was not doing anything like moving the camera.  I thought it would settle after a while, but the memory use kept going up.
Since I'm terrified by memory leaks from years of C++ coding, I started looking on the internet for ways where .net might also have leaks, although there is the magic Garbage Collector.  It's very handy, but it also takes away our awareness of leaks and garbage, which might bite you in the back in games...

As it turns out, there are some things recommended in several texts that you should do or not do in games:

- don't use use foreach in tight rendering loops, because alledgedly is spwans an iterator each time, which needs to be garbage collected
- don't use use of lot of on-the-fly 'new', where you could also allocate objects at the start of object existence, and then just fill in their values later (like a Vector3, etc. ?), keeping the same object alive, instead of allocating a fresh one every time
- do recycle objects instead of re-allocating them each time, if possible.  I always use an 'active' and a 'recycled' collection for this purpose, in my classes, between which I actively recycle objects so that they stay out of reach from the Garbage Collector.  An old PocketPC development habit, I guess.
- do use the 'using' statement at specific points, for making sure an object is deleted straight after using it
- watch out for hidden 'boxing' of objects (which what I think is going on in the tutor 6 leak, right?)

the rest is a matter of memory-leak-allergy and trying to weed out the possible culprits like a honeybadger that doesn't want to let go of his victim. (honeybadgers are known to do that, I read while hunting for memory-leak-tips on the net  Tongue
As a debugging strategy, I use an approach (very simple, really) that always worked for me, and is based on narrowing down the lines of code where stuff might happen: (like probably every coder has his or her own habits in this way)

- make a LOT of the objects you want to test for leaking, so leaks show up bigger and faster
- if you see a leak, keep an eye on the memory use in Task Manager or similar memory-tools... if it goes up even if you don't do a thing, and doesn't settle after a while, it's definitely leaky.
- next, I usually outcomment pieces of code, until I see different behaviour... starting with a big piece, then less and less, until I get around to the line of code that seems to do it.

so far for my 'tools' of pigeon logic ;-)

any chance that the tutor might be fixed for this little adaptation, as it's a bit a nasty one?
I don't know if the solution with the 'using' statement is the only/best one, but it worked here.
I also tried calling the garbage collector on a regular basis.. every 5 seconds or so, on all GC generations (which is definitely a bad way of doing it, if I read the XNA blogs, because it throws away performance, also when it collects nothing) but that doesn't even make a difference for this leak... rather peculiar, no?

kind regards!
loki
Logged
mikeschuld
Administrator
Sr. Member
*****
Offline Offline

Posts: 389


View Profile WWW
« Reply #10 on: 2007/02/14 16:21:31 »

I have discussed doing an optimizations tutorial in the future, but I want to get some more of the general functionality into the engine as that is what people are actually here to learn, not how to optimize their code. There is definately a need to do this at some point; however, it simply might not be neccesary for the tutorial engine itself as it was never intended to create anything too intense (except everyones personal iterations of it of course.) For this reason, their may be a short tutorial on optimization techniques within the engine framework that doesn't cover ALL the little teaks, but gives the general idea leaving the tracking work up to the people who need to get moore performance out.
Logged
Iarus
Newbie
*
Offline Offline

Posts: 6


View Profile
« Reply #11 on: 2007/02/18 10:35:28 »

the tutorials are great

I've tried the memory-leak fix and it seams to fix the problem, but not totally, there must be other leaks elsewhere.

the memory usage with 20-ish tigers is really fast without the using statement, with it, it still go up, but slower.

an optimization tutorial would be useful.
Logged
Pages: [1]
  Print  
 
Jump to:  

Related Topics
Subject Started by Replies Views Last post
Tut 6: Model Class Hazy Mind XNA Engine MicahN 2 2205 Last post 2006/11/15 09:43:47
by MicahN
How To: Render a model with a texture?? Hazy Mind XNA Engine Quinn 6 2244 Last post 2007/01/07 00:33:58
by mikeschuld
Screen Flickering problem... Hazy Mind XNA Engine simpson.jon 4 1614 Last post 2007/02/25 17:09:05
by simpson.jon
Question about Getting 2D screen coordinates General Discussion DaphydTheBard 6 2363 Last post 2007/02/27 03:23:36
by DaphydTheBard
Detecting Model Collision...? General Discussion « 1 2 » DaphydTheBard 15 4122 Last post 2007/03/27 01:29:52
by Nemo Krad
Model exporters General Discussion EclipsE 13 3599 Last post 2007/04/26 12:25:03
by EclipsE
Loading a model in runtime? General Discussion XNASorcerer 10 3167 Last post 2007/05/06 21:22:42
by XNASorcerer
Tranforming a model's vertices Hazy Mind XNA Engine « 1 2 » DoomMarine 29 6648 Last post 2007/08/28 05:15:34
by DoomMarine
Game-ready model shops General Discussion Balosh 0 1561 Last post 2009/07/10 02:37:54
by Balosh
Adding in a Screen Manager Hazy Mind XNA Engine mimminito 1 1574 Last post 2010/02/20 23:59:09
by Jeff Lamoureux
Game- ready model shops Hazy Mind 3D Engine Tinlau 0 1125 Last post 2010/02/03 20:23:12
by Tinlau
Powered by MySQL Powered by PHP Powered by SMF 1.1.12 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 1.549 seconds with 20 queries.