Search Home Members Contacts
About Us
Products
Downloads
Community
Support
Pages: [1]
  Print  
Author Topic: Memory Error !!! Help Please  (Read 1536 times)
harikumar001
Customers
Community Member
*****
Posts: 65


« on: September 27, 2010, 08:04:08 AM »

Hey Guys,

Need to deliver my application in a week or so and my application has started crashing with exceptions that my applications can't even handle.

My application allows users to add furniture in a room. There are a number of models available to choose from. There are a few highly detailed models which are over 4MB in size. When I load a couple of these into my room, they load and render perfectly. But after a while (like 10-20s) when I try to select the meshes and move them around I get the following error:

"An unhandled exception of type 'System.StackOverflowException' occurred in MTV3D65.dll"

This error I get from the line:
CollisionResult = Scene.MousePick((int)mouseX, (int)mouseY, (int)CONST_TV_OBJECT_TYPE.TV_OBJECT_MESH, CONST_TV_TESTTYPE.TV_TESTTYPE_BOUNDINGBOX);

When I click on View Details in the exception window, I get the following message:

"Cannot evaluate expression because the current thread is in a Stack Overflow state"

The bad thing is I can't even handle the error. The code runs within a try catch block but still crashing.

I check the resource usage of my PC and over 1GB of RAM is still available. Is there a certain max size of a mesh that TV3D can handle. I am getting the same error with a couple of other models of size around 700KB, but in that case the application runs for a longer time before crashing.

I am sitting in front of my PC for hours now with this message. Please help guys. I am clueless. Donno what to do? Sad

Regards

EDIT:FYI I am using .X files and I am using the Timer Control for my main loop execution
« Last Edit: September 27, 2010, 08:12:03 AM by harikumar001 » Logged
jviper
Community Member
*
Posts: 2130

Discipline in training


« Reply #1 on: September 27, 2010, 04:08:59 PM »

Sounds like you got your code tangled up somehow. This happens alot when you write a recursive function, but that recursion cannot find a way out. Assuming are not trying to write recursive functions, there is a way that could happen if you have alot of functions calling each other, and somehow you get stuck in a calling in circles. The DoEvents, or handling events or delegates could also play a hand in this as the program flow may not be as obvious. If this is what the problem is, it could be time-consuming to troubleshoot.

I know there may be a limit of 64k tris, but that's per mesh, not total, so it can't be that, unless you have meshes over 64k tris. I'm not sure what else it could be actually, without seeing any code.
Logged

JAbstract.....Don't just imagine, make it happen!
harikumar001
Customers
Community Member
*****
Posts: 65


« Reply #2 on: September 27, 2010, 10:34:24 PM »

Thank you jviper

There is the main block which gets called by the timer tick event of the timer control. So I believe that is causing the recursive calls. My meshes do not exceed the 64k triangle limit.

I changed the timer control tick with the while loop and so far I have not found any errors. Need more testing. Will confirm after that.

Its interesting that the processor usage has now gone up considerably after I use the while loop. I'll have to play around with threads to improve performance.

Regards
Logged
arnienet
Customers
Community Member
*****
Posts: 263


WWW
« Reply #3 on: September 28, 2010, 06:38:22 PM »

There is a coding optimisation which may help with this problem.

I've seen a couple of examples which 1st tests for a mouse button click and if so then performs the mouse pick test. The problem occurs where the mouse button is tested for every game loop after the initial test on mouse click. This would cause the mouse pick function to be effectively called recursively while the mouse button is pressed. If the GPU component of the mousepick function could not complete before the next call, then problems would arise. I always use a boolean value to detect the initial test and prevent further tests until the button is released and repressed. You could also limit the amount of tests per second.
Logged

Total Dev time = 50% to code, 50% to test, 50% to find errors, 50% to fix, that's why it takes twice as long.

Dawn World MMO
harikumar001
Customers
Community Member
*****
Posts: 65


« Reply #4 on: September 28, 2010, 10:44:30 PM »

Thank you arnienet

I am employing similar checks to minimize my update calculations. But the problem I found out was the Timer Control which was set at a very small interval of 10ms. So it kept calling the main block every 10ms regardless of whether it had finished executing or not.

Replaced that with the while loop and its fine now.

Regards
Logged
arnienet
Customers
Community Member
*****
Posts: 263


WWW
« Reply #5 on: September 29, 2010, 10:05:22 AM »

No problem, glad we could help. I would also mention (you probably already know) that the timer control (dot net, windows api) is not very accurate, so if you start to experience jerkiness in your scene as your app grows, you could use the TV3D TimeElapsed function to return a much more accurate time interval between loops.
Logged

Total Dev time = 50% to code, 50% to test, 50% to find errors, 50% to fix, that's why it takes twice as long.

Dawn World MMO
TecnoBacon
Customers
Community Member
*****
Posts: 305


WWW
« Reply #6 on: September 29, 2010, 11:24:21 AM »

best way we found with TV elepsed is to have a tick timer that sets flags for each time increment, ie

with time
   if 1ms     msFlag = true
   if 10ms    tmsFlag = true
etc...

in your effects/ai you set them back to false when used or discarded,
works well with threads as they just have to watch for the flags to decide when they should run and when they should abort, leaving the results in apropriate registers

lot of work but eliminates thread sync which causes stuttering and tearing.
Logged

www.TecnoBacon.com - the other side of the Bacon family! 3D Development, Music and more.
arnienet
Customers
Community Member
*****
Posts: 263


WWW
« Reply #7 on: September 29, 2010, 11:30:16 AM »

Thanks TecnoBacon, I'll look out for that when I start using threads.
Logged

Total Dev time = 50% to code, 50% to test, 50% to find errors, 50% to fix, that's why it takes twice as long.

Dawn World MMO
Shadowsong
Customers
Community Member
*****
Posts: 328


« Reply #8 on: October 01, 2010, 11:03:28 AM »

Hm this might not be a relevant post but in general I would never recommend using timers for realtime applications.
Even when using .Net apps with windows forms and GUIs, I would still use a simple single thread running inside a traditional while(true) loop.
That is a lot more stable and thread-safe than a 10ms-timer. I have lots of windows GUI .Net apps and with my method I never had any stability problems.
Logged
TecnoBacon
Customers
Community Member
*****
Posts: 305


WWW
« Reply #9 on: October 01, 2010, 11:57:24 AM »

not timer, each loop i check the time

        public static void TimersUpdate()
        {
            float mills = 0f;
            float hundreths = 0f;
            float tenths = 0f;
            DateTime SysTime = DateTime.Now;
            mills = SysTime.Millisecond;
            hundreths = (float)Math.Truncate(mills * 0.1);
            tenths = (float)Math.Truncate(mills * 0.01);
            if (SysTimeDivs.hundreths != hundreths)
            {
                TBTimer.isHundredthsChanged = true;
                //TB3DInput.InputCheckKeys(Engine.TB_Engine, Engine.MainViewport, Engine.TB_Scene); //provides for debounce
            }
            if (SysTimeDivs.tenths != tenths)
            {
                TBTimer.isTenthsChanged = true;
                TBTimer.isTrigger1 = true;
            }
            if (LastSysTime.Hour != SysTime.Hour) TBTimer.isHourChanged = true;
            if (LastSysTime.Minute != SysTime.Minute)
            {
                TBTimer.isMinutesChanged = true;
                if (LastSysTime.Minute * 0.1 != SysTime.Minute * 0.1) TBTimer.isTenMinutesChanged = true;
            }
            if (LastSysTime.Second != SysTime.Second)
            {
                TBTimer.isSecondsChanged = true;
                TBTimer.SecCounter += 1;
                if (TBTimer.SecCounter > 9) TBTimer.SecCounter = 0;
            }
            TBTimer.TV3Delapsed = (long)(TB_Engine.AccurateTimeElapsed() * 10000); //tv render scene cunsumption, main VP only
            TBTimer.TBelapsed = SysTime.Ticks - LastSysTime.Ticks;
            TBTimer.ActorSync = TB3DMath.Double2Float(TBTimer.TBelapsed * 0.001);
            TBTimer.EnvSync = TB3DMath.Double2Float(TBTimer.TBelapsed * 0.0000001); //real time divided by 100th second
            TBTimer.Sine10 = TB3DMath.TB_Math.ASin(tenths - 5);
            TBTimer.Sine100 = TB3DMath.TB_Math.ASin(hundreths - 50);
            LastSysTime = SysTime;
            SysTimeDivs.hundreths = hundreths;
            SysTimeDivs.tenths = tenths;
        }

i use the flags like this, (excess code removed for sample)

        private static void RenderEffects()
        {
            TB3DCamera.ActiveCamera.Rotate.Time += (float)(TBTimer.ActorSync * TB3DCamera.ActiveCamera.Rotate.Speed);

            if (TBTimer.isHundredthsChanged)
            {
                TBTimer.isHundredthsChanged = false;
            }

            if (TBTimer.isTenthsChanged) //10 times a second
            {
                TBTimer.isTenthsChanged = false;
                if (TB3DRegion.TBRegion.isOceanEnabled && TB3DRegion.TBRegion.isWaveEnabled) TB3DWater.WaveUpdate((float)TBTimer.EnvSync); //.isTenthsChanged)
                if (TB3DRegion.TBRegion.isWindEnabled) TB3DAtmos.TB_SetWindEngine();
                //if (isShadersSupported && TB3DRegion.TBRegion.isSkyEnabled) TB3DDistant.SkySetShader();
            }

            if (TBTimer.isSecondsChanged)
            {
                TBTimer.isSecondsChanged = false;
            }

            if (TBTimer.isMinutesChanged)
            {
                TBTimer.isMinutesChanged = false;
            }

            if (TBTimer.isTenMinutesChanged)
            {
                TBTimer.isTenMinutesChanged = false;
            }
        }



I agree that system timers will interfere with threading unless lock techniques are used (large overhead)
Logged

www.TecnoBacon.com - the other side of the Bacon family! 3D Development, Music and more.
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.3 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks