Changeset 87 for osgVisual/src/core


Ignore:
Timestamp:
Jul 28, 2010, 5:13:22 PM (14 years ago)
Author:
Torben Dannhauer
Message:

Introductes VS 2008 Memory Leak Debugging.
Todo: Compile on Linux and compare with Valgrind, VS 2008 seems to be awkward in leak debugging

Location:
osgVisual/src/core
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • osgVisual/src/core/osgVisual.cpp

    r86 r87  
    1515*/
    1616
    17 // Declare this in header.
     17const unsigned int MAX_NUM_EVENTS = 10;
     18
     19#ifdef _DEBUG
     20        #ifdef WIN32
     21                // Declare this in header.
     22                #define _CRTDBG_MAP_ALLOC
     23                #include <stdlib.h>
     24                #include <crtdbg.h>
     25        #endif
     26#endif
     27
    1828//#include <windows.h>
    19 #define _CRTDBG_MAP_ALLOC
    20 #include <crtdbg.h>
    2129
    2230#include <osg/ArgumentParser>
     
    2634#include <visual_core.h>
    2735
    28 const unsigned int MAX_NUM_EVENTS = 10;
     36
    2937
    3038
     
    3341       
    3442#ifdef _DEBUG
    35         #include <leakDetection.h>      // ugly but must be included inside the class
     43        #ifdef WIN32
     44                #include <leakDetection.h>      // ugly but must be included inside the class
    3645
    37     int tmp_flag;
     46                int tmp_flag;
    3847
    39     HANDLE log_file = CreateFile("mem_log.txt", GENERIC_WRITE,FILE_SHARE_WRITE,
    40         NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
     48                HANDLE log_file = CreateFile("mem_log.txt", GENERIC_WRITE,FILE_SHARE_WRITE,
     49                        NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
    4150
    42     _CrtSetReportMode(_CRT_ASSERT,_CRTDBG_MODE_FILE | _CRTDBG_MODE_WNDW |
    43         _CRTDBG_MODE_DEBUG);
    44     _CrtSetReportMode(_CRT_WARN,_CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
    45     _CrtSetReportMode(_CRT_ERROR,_CRTDBG_MODE_FILE | _CRTDBG_MODE_WNDW |
    46         _CRTDBG_MODE_DEBUG);
     51                _CrtSetReportMode(_CRT_ASSERT,_CRTDBG_MODE_FILE | _CRTDBG_MODE_WNDW |
     52                        _CRTDBG_MODE_DEBUG);
     53                _CrtSetReportMode(_CRT_WARN,_CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
     54                _CrtSetReportMode(_CRT_ERROR,_CRTDBG_MODE_FILE | _CRTDBG_MODE_WNDW |
     55                        _CRTDBG_MODE_DEBUG);
    4756
    48     // output to the file if not under VS
    49     _CrtSetReportFile(_CRT_ASSERT, log_file);
    50     _CrtSetReportFile(_CRT_WARN, log_file);
    51     _CrtSetReportFile(_CRT_ERROR, log_file);
     57                // output to the file if not under VS
     58                _CrtSetReportFile(_CRT_ASSERT, log_file);
     59                _CrtSetReportFile(_CRT_WARN, log_file);
     60                _CrtSetReportFile(_CRT_ERROR, log_file);
    5261
    53     tmp_flag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
    54     tmp_flag |= _CRTDBG_ALLOC_MEM_DF;
    55     tmp_flag |= _CRTDBG_DELAY_FREE_MEM_DF;
    56     tmp_flag |= _CRTDBG_LEAK_CHECK_DF;
     62                tmp_flag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
     63                tmp_flag |= _CRTDBG_ALLOC_MEM_DF;
     64                tmp_flag |= _CRTDBG_DELAY_FREE_MEM_DF;
     65                tmp_flag |= _CRTDBG_LEAK_CHECK_DF;
    5766
    58     _CrtSetDbgFlag(tmp_flag);
     67                _CrtSetDbgFlag(tmp_flag);
     68        #endif
    5969#endif
    6070
     
    6878    core->initialize();
    6979
     80        // Shut osgVisual down
     81        core->shutdown();
     82
    7083        // Set Pointer to null to destroy the objects before this function ends - otherwise memory leaks wil be detected.
    7184        core = NULL;
  • osgVisual/src/core/visual_core.cpp

    r86 r87  
    2828visual_core::~visual_core(void)
    2929{
    30         // shut osgVisual down
    31         shutdown();
    32 
    3330        OSG_NOTIFY( osg::ALWAYS ) << "visual_core destroyed." << std::endl;
    34 
    3531}
    3632
     
    4945
    5046        // Setup coordinate system node
    51         rootNode = new osg::CoordinateSystemNode;
     47        rootNode = new osg::CoordinateSystemNode;       // todo memleakf
    5248        rootNode->setEllipsoidModel(new osg::EllipsoidModel());
    5349
    5450        // Test memory leak (todo)
    55         double* test = new double[1000];
     51        //double* test = new double[1000];
    5652
    5753        #ifdef USE_SPACENAVIGATOR
     
    130126        OSG_NOTIFY( osg::ALWAYS ) << "Shutdown visual_core..." << std::endl;
    131127
     128        // Shutdown Dbug HUD
     129        if(hud.valid())
     130                hud->shutdown();
    132131        // Unset scene data
    133132        viewer->setSceneData( NULL );
     
    144143                distortion->shutdown();
    145144#endif
     145
     146        // Shutdown data
     147        rootNode = NULL;
    146148
    147149        // Shutdown dataIO
     
    295297        //testObj->addUpdater( new object_updater(testObj) );
    296298
    297         osg::ref_ptr<visual_object> testObj2 = new visual_object( rootNode, "cessna" );
     299        osg::ref_ptr<visual_object> testObj2 = new visual_object( rootNode, "cessna" ); // todo memleak
    298300        //testObj2->setNewPosition( osg::DegreesToRadians(47.8123), osg::DegreesToRadians(12.94088), 600 );
    299301        testObj2->setNewPosition( osg::DegreesToRadians(50.8123), osg::DegreesToRadians(8.94088), 600 );
    300302        testObj2->loadGeometry( "../models/cessna.osg" );
    301         testObj2->addUpdater( new object_updater(testObj2) );
    302 
    303         osg::ref_ptr<visual_object> testObj3 = new visual_object( rootNode, "SAENGER1" );
     303        testObj2->addUpdater( new object_updater(testObj2) );   // todo memleak
     304
     305        osg::ref_ptr<visual_object> testObj3 = new visual_object( rootNode, "SAENGER1" );       // todo memleak
    304306        testObj3->setNewPosition( osg::DegreesToRadians(47.8123), osg::DegreesToRadians(12.94088), 600 );
    305307        testObj3->loadGeometry( "../models/saenger1.flt" );
    306         testObj3->addUpdater( new object_updater(testObj3) );
    307        
    308 
    309         osg::ref_ptr<visual_object> testObj4 = new visual_object( rootNode, "SAENGER2" );
     308        testObj3->addUpdater( new object_updater(testObj3) );   // todo memleak
     309       
     310
     311        osg::ref_ptr<visual_object> testObj4 = new visual_object( rootNode, "SAENGER2" );       // todo memleak
    310312        testObj4->setNewPosition( osg::DegreesToRadians(47.8123), osg::DegreesToRadians(12.94088), 650 );
    311313        testObj4->loadGeometry( "../models/saenger2.flt" );
    312         testObj4->addUpdater( new object_updater(testObj4) );
     314        testObj4->addUpdater( new object_updater(testObj4) );   // todo memleak
    313315        testObj4->addLabel("testLabel", "LabelTest!!\nnächste Zeile :)",osg::Vec4(1.0f,0.25f,1.0f,1.0f));
    314316
    315         osg::ref_ptr<visual_object> testObj5 = new visual_object( rootNode, "SAENGER" );
     317        osg::ref_ptr<visual_object> testObj5 = new visual_object( rootNode, "SAENGER" );        // todo memleak
    316318        testObj5->setNewPosition( osg::DegreesToRadians(47.8123), osg::DegreesToRadians(12.94088), 550 );
    317319        testObj5->loadGeometry( "../models/saengerCombine.flt" );
    318320        //testObj5->setScale( 2 );
    319         testObj5->addUpdater( new object_updater(testObj5) );
     321        testObj5->addUpdater( new object_updater(testObj5) );   // todo memleak
    320322
    321323#ifdef USE_SPACENAVIGATOR
     
    359361        visual_draw2D::getInstance()->init( rootNode, viewer );
    360362        //osg::ref_ptr<visual_hud> hud = new visual_hud();
    361         osg::ref_ptr<visual_debug_hud> hud = new visual_debug_hud();
     363        hud = new visual_debug_hud();
    362364        hud->init( viewer, rootNode );
    363365       
Note: See TracChangeset for help on using the changeset viewer.