Search Home Members Contacts
About Us
Products
Downloads
Community
Support
Pages: [1] 2
  Print  
Author Topic: How to reboot Tv3D through a code?  (Read 738 times)
Miller
Community Member
*
Posts: 26


« on: August 21, 2008, 12:37:42 PM »

I try to reboot tv3d on the form, and he writes a memory error, prompt what not so?


      private void frmMain_Load(object sender, System.EventArgs e)
      {
            off_controls();
            restart();
           
         
      }


        public void restart()
        {
            run_tv3d();
            TV = new TVEngine();
            TV.SetDebugMode(true, true);
            TV.SetDebugFile(System.IO.Path.GetDirectoryName(Application.ExecutablePath) + "\\debugfile.txt");
            TV.Init3DWindowed(this.pictureBox1.Handle, true);
            TV.GetViewport().SetAutoResize(true);
            TV.DisplayFPS(true);
            TV.SetAngleSystem(MTV3D65.CONST_TV_ANGLE.TV_ANGLE_DEGREE);
            Scene = new TVScene();
            Globals = new TVGlobals();
            Input = new TVInputEngine();
            Input.Initialize(true, true);
            Textures = new TVTextureFactory();
            camera = new TVCamera();
            bDoLoop = true;
            this.Show();
            this.Focus();
            render();
        }

        public void run_tv3d()
        {
            TV = null;
            Scene = null;
            Globals = null;
            Input = null;
            Textures = null;
            camera = null;
            bDoLoop = false ;
        }

        public void render()
        {
            while (bDoLoop)
            {
                camera.SetPosition(camx, camy, camz);

                if (Input.IsKeyPressed(MTV3D65.CONST_TV_KEY.TV_KEY_UP)) { camz += 0.1f; };
                if (Input.IsKeyPressed(MTV3D65.CONST_TV_KEY.TV_KEY_DOWN)) { camz -= 0.1f; };

                    TV.Clear(false);
                    Scene.RenderAll(true);
                    TV.RenderToScreen();
                    if (Input.IsKeyPressed(MTV3D65.CONST_TV_KEY.TV_KEY_ESCAPE)) { bDoLoop = false; };
               
                Application.DoEvents();
            }

            TV = null;
            this.Close();
        }
Logged

Do not concern to a life it is too serious, all the same you will not get out of it alive.
ZaPPZion
Community Member
*
Posts: 341


« Reply #1 on: August 21, 2008, 01:02:42 PM »

try adding TV.ReleaseAll() before setting TV=null. This will free the engine.
Logged
DanDixon
Customers
Community Member
*****
Posts: 181


« Reply #2 on: September 01, 2008, 09:04:47 PM »

I'm trying to do this as well without much success.

I've had some reports that my application crashes after updating and I suspect that it's because the Truevision license file isn't getting updated (which isn't Truevision's issue other than having to deal with the file at all. I greatly dislike having to create and include a license file every time I update, it's caused me a lot of heartache. (like this problem, for example))

Anyway...

I setup TrueVision and then call this line:
Code:
TV.Init3DWindowed(Display.Form, True)
which will crash if the license file is wrong.

I want to reset and try again (which seemed to work a month ago, but isn't anymore)...

But even after setting:
Code:
TV = Nothing

I get a crash when I call this again:
Code:
TV.Init3DWindowed(Display.Form, True)

Can TV be reset and created again after the license check fails?


My Truevision project:
http://universesandbox.com/
Logged
pabloescobar
Customers
Community Member
*****
Posts: 95


WWW
« Reply #3 on: September 02, 2008, 05:30:50 PM »

I'm trying to do this as well without much success.

I've had some reports that my application crashes after updating and I suspect that it's because the Truevision license file isn't getting updated (which isn't Truevision's issue other than having to deal with the file at all. I greatly dislike having to create and include a license file every time I update, it's caused me a lot of heartache. (like this problem, for example))

Anyway...

I setup TrueVision and then call this line:
Code:
TV.Init3DWindowed(Display.Form, True)
which will crash if the license file is wrong.

I want to reset and try again (which seemed to work a month ago, but isn't anymore)...

But even after setting:
Code:
TV = Nothing

I get a crash when I call this again:
Code:
TV.Init3DWindowed(Display.Form, True)

Can TV be reset and created again after the license check fails?


My Truevision project:
http://universesandbox.com/

You dont forget to call "TV = new TVEngine();" before the "TV.Init3DWindowed(Display.Form, True)"?
Logged

-----------------------------
http://criswork.blogspot.com
DanDixon
Customers
Community Member
*****
Posts: 181


« Reply #4 on: September 02, 2008, 05:38:43 PM »

Thanks for the reply pabloescobar.

Sorry... I didn't correctly explain what I was doing and what was happening:

If this fails:
Code:
TV.Init3DWindowed(Display.Form, True)

Then I try to do this:
Code:
TV = Nothing
TV = New TVEngine
(and other stuff)
TV.Init3DWindowed(Display.Form, True)

But it fails (generates an exception) again on the 2nd line (TV = New TVEngine).

The exception is a common one:
"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
Logged
Toaster
Community Member
*
Posts: 147


WWW
« Reply #5 on: September 04, 2008, 10:58:24 AM »

Use TV.ReleaseAll() before TV = null; like ZaPPZion said. Tongue

-Toaster
Logged

Visit my site at: Unknown Abstraction
DanDixon
Customers
Community Member
*****
Posts: 181


« Reply #6 on: September 04, 2008, 12:53:35 PM »

I tried that but without success.

Calling:
Code:
TV.ReleaseAll()

after this line has generated an error:
Code:
TV.Init3DWindowed(Display.Form, True)

generates the same error.
"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
Logged
SylvainTV
Administrator
Community Member
*****
Posts: 4479


WWW
« Reply #7 on: September 04, 2008, 01:03:52 PM »

Let's see where it crashes in the debug file.
I will be able to tell you if it crashed in license file check code or not.
Logged

Regards

Sylvain Dupont
TrueVision3D Developer
sylvain@truevision3d.com

TV3D IRC at http://chat.truevision3d.com or on server irc.truevision3d.com #Truevision3D. Come talk with us !
DanDixon
Customers
Community Member
*****
Posts: 181


« Reply #8 on: September 04, 2008, 01:51:22 PM »

Thanks Sylvain.

Here are two different logs:

1 - Here one complete Log from my machine:
Code:
09-04-2008 11:15:38 | --------------------------------------------
09-04-2008 11:15:38 | Truevision3D Debug/Log File
09-04-2008 11:15:38 | --------------------------------------------
09-04-2008 11:15:38 | Engine Version : 6.5
09-04-2008 11:15:38 | ENGINE INFO : DLL Compilation time May 15 2008 21:29:32
(it ends here)

And the corresponding errors:
Code:
     0 | 2008-09-04 11:15:38.550 * Error: Init3DWindowed 1st pass | Attempted to read or write protected memory. This is often an indication that other memory is corrupt. |    at CTVEngine.Init3DWindowed(CTVEngine* , HWND__* , Boolean )
   at MTV3D65.TVEngine.Init3DWindowed(IntPtr hWnd, Boolean bEnableTL)

     0 | 2008-09-04 11:15:38.550 * Error: Init3DWindowed 2st pass | Attempted to read or write protected memory. This is often an indication that other memory is corrupt. |    at new(UInt32 )
   at MTV3D65.TVEngine..ctor()



2 - And this one from a user of Russian windows:

Code:
09-04-2008 21:02:40 | --------------------------------------------
09-04-2008 21:02:40 | Truevision3D Debug/Log File
09-04-2008 21:02:40 | --------------------------------------------
09-04-2008 21:02:40 | Engine Version : 6.5
09-04-2008 21:02:40 | ENGINE INFO : DLL Compilation time May 15 2008 21:29:32
09-04-2008 21:02:40 | DEVICE INIT : Initialize Depth
09-04-2008 21:02:40 | DEVICE INIT : Initializing the device in windowed mode, with a render surface size of 1272x720, format 22, depthbuffer 75
09-04-2008 21:02:40 | VIEWPORT MANAGER : Main viewport initialization
09-04-2008 21:02:40 | VIEWPORT MANAGER : Main viewport initialized (1272x720)
09-04-2008 21:03:29 | START UNLOAD
(it ends here)

Code:
     0 | 2008-09-04 21:02:40.406 * Error: Init3DWindowed 1st pass | Попытка чтения или записи в защищенную память. Это часто свидетельствует о том, что другая память повреждена. |    в CTVEngine.Init3DWindowed(CTVEngine* , HWND__* , Boolean )
   в MTV3D65.TVEngine.Init3DWindowed(IntPtr hWnd, Boolean bEnableTL)
   в bi.m()
     0 | 2008-09-04 21:02:40.828 * Error: Init3DWindowed 2st pass | Попытка чтения или записи в защищенную память. Это часто свидетельствует о том, что другая память повреждена. |    в CTVEngine.Init3DWindowed(CTVEngine* , HWND__* , Boolean )
   в MTV3D65.TVEngine.Init3DWindowed(IntPtr hWnd, Boolean bEnableTL)
   в bi.m()
« Last Edit: September 05, 2008, 12:42:10 PM by DanDixon » Logged
Omnicrash
Community Member
*
Posts: 55


WWW
« Reply #9 on: September 08, 2008, 02:05:17 AM »

I had a similar problem, where I needed tv3d in my configuration screen, which comes before the game starts.
Setting everything to null and correctly unloading, still caused random crashes when a new engine was initialized.

I managed to solve this by using the .NET function GC.Collect() after the first engine was unloaded.
Logged

Raine
Customers
Community Member
*****
Posts: 1189


« Reply #10 on: September 09, 2008, 05:49:40 PM »

Just to add that actually GC.Collect solves the exception problem when restarting the engine (and I'm not restarting it during the application loop, but in a new debug session), however, sometimes the Init* method takes 7 or so seconds instead of the average 1.5.

Something worth checking imho
Logged

DanDixon
Customers
Community Member
*****
Posts: 181


« Reply #11 on: September 11, 2008, 04:07:25 PM »

Adding GC.Collect kind of helped, but it doesn't seem to be a 100% fix.

Thanks for the great idea though.

And I solved the update issue which was the larger problem relating to this one.

Either way... I wish the engine wouldn't crash if the license file didn't work. It should just show the logo.
Logged
AriusEso
Customers
Community Member
*****
Posts: 377

Esoteric


« Reply #12 on: September 11, 2008, 04:11:08 PM »

Either way... I wish the engine wouldn't crash if the license file didn't work. It should just show the logo.

It crashes on purpose. This is to stop people working around the issue. It's been this way since beta. I'm not sure if it is relevant to a public release, but the actual crash on fail was done on purpose( same as SetBetaKey back in the day ). Essentialy, it's not a bug is what I'm trying to say, it's an absolute "Oh, right, I'm gonna crash then" scenario.
Logged

DanDixon
Customers
Community Member
*****
Posts: 181


« Reply #13 on: September 11, 2008, 04:55:46 PM »

It crashes on purpose.

Well then I'll stop complaining about that. Smiley

Thanks for the info.
Logged
Hawthorne
Customers
Community Member
*****
Posts: 233


« Reply #14 on: September 12, 2008, 03:03:40 AM »

Couple things, just create your instances once and then clean them out and reset them for reuse. Define your variables as null and let the create procedure new them for you. Let the destroy procedure destory anything that needs to get destroyed but dont worry about setting things to null in your destroy, simply reuse the objects.

Obviously some of this code has proprietary stuff in it for my systems, but you get the idea. Create and reuse, dont create/dump the entire system and then try to renew your objects you will just get a ton of problems. Flush via a destroy routine and reuse the variables without renewing them.


Code:
public static void CreateTrueVision(System.IntPtr Handle,string YourWorldMapName, PathClass YourPaths, ref GeoWorldClass YourWorldObjects, ref TVObjects TruevisionObjects)
        {
            TruevisionObjects = new TVObjects();
            if (Truevision.Engine != null) GeoWorldClass.Destroy();
            else
                Truevision.Engine = new TVEngine();
            {
                // Set the debugging information.
                Truevision.Engine.SetDebugMode(true, true);
                Truevision.Engine.SetVSync(true);
                Truevision.Engine.SetFPUPrecision(true);
                Truevision.Engine.SetDebugFile(System.AppDomain.CurrentDomain.BaseDirectory + "debugfile.txt");
                Truevision.Engine.SetAngleSystem(CONST_TV_ANGLE.TV_ANGLE_RADIAN);
                Truevision.Engine.SetSearchDirectory(Application.ExecutablePath);
                Truevision.Engine.AllowMultithreading(true);
                Truevision.Engine.DisplayFPS(true);
                if (World.AntiAliasing == CONST_TV_MULTISAMPLE_TYPE.TV_MULTISAMPLE_NONE)
                    Truevision.Engine.SetAntialiasing(false, CONST_TV_MULTISAMPLE_TYPE.TV_MULTISAMPLE_NONE);
                else
                    Truevision.Engine.SetAntialiasing(true, World.AntiAliasing);
                Truevision.Engine.Init3DWindowed(Handle, true);
                Truevision.Engine.GetViewport().SetAutoResize(true);
            }
            //-------------------------------------------------------------------------------
            if (Truevision.Scene == null) Truevision.Scene = new TVScene();

            {
                Truevision.Scene.SetAutoTransColor((int)World._AutoTransColor);
                Truevision.Scene.SetTextureFilter(World._TextureFilter);
                Truevision.Scene.SetDithering(World._UseDithering);
            }
            //-------------------------------------------------------------------------------
            if (Truevision.LightEngine == null) Truevision.LightEngine = new TVLightEngine();
            //-------------------------------------------------------------------------------
            if (Truevision.Atmosphere == null) Truevision.Atmosphere = new TVAtmosphere();
            //-------------------------------------------------------------------------------
            if (Truevision.TVInternals == null) Truevision.TVInternals = new TVInternalObjects();
            //-------------------------------------------------------------------------------
            if (Truevision.AI == null) Truevision.AI = new TVAI();
            //-------------------------------------------------------------------------------
            if (Truevision.DeviceInfo == null) Truevision.DeviceInfo = new TVDeviceInfo();
            //-------------------------------------------------------------------------------
            if (Truevision.Screen2DText == null) Truevision.Screen2DText = new TVScreen2DText();
            //-------------------------------------------------------------------------------
            if (Truevision.InputEngine == null)
            {
                Truevision.InputEngine = new TVInputEngine();
                Truevision.InputEngine.Initialize(true, true);
            }
            //-------------------------------------------------------------------------------
            if (Truevision.Materials == null) Truevision.Materials = new TVMaterialFactory();
            //-------------------------------------------------------------------------------
            if (Truevision.TVMath == null) Truevision.TVMath = new TVMathLibrary();
            //-------------------------------------------------------------------------------
             if (Truevision.Physics == null) Truevision.Physics = new TVPhysics();
            //-------------------------------------------------------------------------------
            if (Truevision.AI == null) Truevision.AI = new TVAI();
            //-------------------------------------------------------------------------------
            if (Truevision.Immediate == null) Truevision.Immediate = new TVScreen2DImmediate();
            //-------------------------------------------------------------------------------
            if (Truevision.Globals == null) Truevision.Globals = new TVGlobals();
            //if (Truevision.Particles == null) Truevision.Particles = Truevision.Scene.CreateParticleSystem();

            if (Truevision.TVTextureManager == null) Truevision.TVTextureManager = new TVTextureFactory();

            YourWorldObjects = (GeoWorldClass)GeoWorldClass.Load(Paths.Worlds + YourWorldMapName + "\\" + YourWorldMapName + ".map");
            //Set View/Cam
            Truevision.TVTextureManager.SetTextureMode(World.TextureMode);
            if (Truevision.Camera == null) Truevision.Camera = new TVCamera();
            Truevision.Camera.SetLookAt(0, -1, 0);
            Truevision.Camera.SetViewFrustum(World._FOV, World._FarPlane, World._NearPlane);

            //Init the Geonardo System (ONLY AFTER YOU'VE LOADED THE MAP! Otherwise KABOOM!)
            GeoWorldClass.Initialize(TruevisionObjects, YourPaths, YourWorldObjects);

 
        }


And to Destroy your session before running CreateTrueVision again
Code:
public static void Destroy()
        {
            try { World.PhysicsManager.Destroy(); }
            catch { };
            try { World.MediaManager.Destroy(); }
            catch { };
            try { Truevision.TVTextureManager.DeleteAllTextures(); }
            catch { };
            try {Truevision.Materials.DeleteAllMaterials();}
            catch { };
            try {Truevision.Scene.DestroyAllActors();}
            catch { };
            try {Truevision.Scene.DestroyAllLandscapes();}
            catch { };
            try {Truevision.Scene.DestroyAllMinimeshes();}
            catch { };
            try {Truevision.Scene.DestroyAllMeshes();}
            catch { };
            try {Truevision.Scene.DestroyAllParticleSystems();}
            catch { };
            try { Truevision.LightEngine.DeleteAllLights(); }
            catch { };
            try { World.SceneManager.Destroy(); }
            catch { };
            try { World.ActorManager.RemoveAllBaseActors(); }
            catch { };
            try { World.MeshManager.BaseMesh.Clear(); }
            catch { };
            try { World.ActorManager.BaseActors.Clear(); }
            catch { };
            try { World.ActorManager.Actors.Clear(); }
            catch { };
            try { World.FoilageManager.Foilage.Clear(); }
            catch { };
            try { GeoWorldClass.LandscapeManagerClass.Pages.Clear(); }
            catch { };
            try { GeoWorldClass.LandscapeManagerClass.LoadedPages.Clear(); }
            catch { };
            try { World.Materials.Clear(); }
            catch { };
            try { GeoWorldClass.WaterManagerClass.Destroy(); }
            catch { };
            try { World.SplatPacks.Clear(); }
            catch { };
            try { World.Splats.Clear(); }
            catch { };
            try { World.Textures.Clear(); }
            catch { };
            try { World.AIManager.Destroy(); }
            catch { };
            try { World.WaterManager.WaterMaps.Clear(); }
            catch { };
            try { World.MediaManager.SoundMarkers.Clear(); }
            catch { };
            try { World.EffectManager.Destroy(); }
            catch { };
            try { Truevision.Engine.ReleaseAll(); }
            catch { };
        }

-Pat
Logged
Raine
Customers
Community Member
*****
Posts: 1189


« Reply #15 on: September 12, 2008, 04:04:28 AM »

How about just one try-catch block?
Logged

Hawthorne
Customers
Community Member
*****
Posts: 233


« Reply #16 on: September 12, 2008, 05:33:00 AM »

How about just one try-catch block?

Wont do for obvious reasons. If you get a failure for some stupid reason that really does not matter you could jeopardize the rest of the unload sequences unless you feel like writing your own destroy wrapper for each component of your system.. that is a matter of semantics. The point is not to jeopardize the integrity of TV so that you can reuse it.

-Pat
Logged
Raine
Customers
Community Member
*****
Posts: 1189


« Reply #17 on: September 12, 2008, 06:24:20 AM »

Sorry, I don't agree. Try / catch blocks aren't made to solve problems automagically. If an object is in an invalid state and throws an exception, there must be a reason which might keep the very same object from working properly upon next usage.

The TV clr wrapper doesn't even throw managed exceptions afaik, besides access violations which are likely thrown by the clr. This, plus the fact that TV seems to reuse the same object instances per process, isn't going to help, no matter how much you catch during disposal. In this way, if TV had an exception, you'll simply get it again when you next reuse that object or perform the same operation - unless you plan on adding try/catch blocks on every TV call, but that's another story.
Logged

Hawthorne
Customers
Community Member
*****
Posts: 233


« Reply #18 on: September 12, 2008, 07:23:40 AM »

Sorry, I don't agree. Try / catch blocks aren't made to solve problems automagically. If an object is in an invalid state and throws an exception, there must be a reason which might keep the very same object from working properly upon next usage.

The TV clr wrapper doesn't even throw managed exceptions afaik, besides access violations which are likely thrown by the clr. This, plus the fact that TV seems to reuse the same object instances per process, isn't going to help, no matter how much you catch during disposal. In this way, if TV had an exception, you'll simply get it again when you next reuse that object or perform the same operation - unless you plan on adding try/catch blocks on every TV call, but that's another story.

Actually thats not true at all. You could have simply not called a clear, and the next clear will fix that said access vilotation. There are several things you are not taking into consideratin but I digress.

The bottom line is this solution works, it works well and its been tested over 1000 times in a production environment. You are more than welcome to express dissent, but provide a solution instead of pointing at those of us who  provide a solution that actually works Wink

And for the record that is no diffrent from On Error Resume Next via VB6 VB.NET, on a destory routine that runs on a specialized need. I don't think anyone will mind a few try catch's when at the end of the day the stuff works just like they expect, except maybe you Wink.

-Pat
« Last Edit: September 12, 2008, 07:27:41 AM by Hawthorne » Logged
Raine
Customers
Community Member
*****
Posts: 1189


« Reply #19 on: September 12, 2008, 07:57:12 AM »

Clear? What clear? We're talking about exceptions here, right?
But yes, I for one do mind. I'm used to good code practices Wink
Logged

Pages: [1] 2
  Print  
 
Jump to:  

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