Changeset 86


Ignore:
Timestamp:
Jul 28, 2010, 3:36:28 PM (14 years ago)
Author:
Torben Dannhauer
Message:

implemented technique to debug memory leaks

Location:
osgVisual
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • osgVisual/CMakeLists.txt

    r83 r86  
    263263        src/core/visual_core.cpp
    264264        src/core/osgVisual.cpp
     265        # Memory Leak debugging
     266        include/core/leakDetection.h
    265267        # Util
    266268        include/util/visual_util.h
  • osgVisual/include/dataIO/visual_dataIO.h

    r85 r86  
    1616*/
    1717
    18 #include <osg/notify>
    19 #include <osg/referenced>
     18#include <osg/Notify>
     19#include <osg/Referenced>
    2020#include <osg/ArgumentParser>
    2121
  • osgVisual/src/core/osgVisual.cpp

    r31 r86  
    1515*/
    1616
     17// Declare this in header.
     18//#include <windows.h>
     19#define _CRTDBG_MAP_ALLOC
     20#include <crtdbg.h>
     21
    1722#include <osg/ArgumentParser>
    1823#include <osg/Referenced>
     
    2126#include <visual_core.h>
    2227
     28const unsigned int MAX_NUM_EVENTS = 10;
    2329
    24 const unsigned int MAX_NUM_EVENTS = 10;
    25 const unsigned int SWAP_BYTES_COMPARE = 0x12345678;
    2630
    2731int main(int argc, char** argv)
    2832{
     33       
     34#ifdef _DEBUG
     35        #include <leakDetection.h>      // ugly but must be included inside the class
     36
     37    int tmp_flag;
     38
     39    HANDLE log_file = CreateFile("mem_log.txt", GENERIC_WRITE,FILE_SHARE_WRITE,
     40        NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
     41
     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);
     47
     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);
     52
     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;
     57
     58    _CrtSetDbgFlag(tmp_flag);
     59#endif
     60
    2961    // Use an ArgumentParser object to manage the program arguments.
    3062        osg::ArgumentParser arguments(&argc,argv);
     
    3668    core->initialize();
    3769
     70        // Set Pointer to null to destroy the objects before this function ends - otherwise memory leaks wil be detected.
     71        core = NULL;
     72
    3873        return 0;
    3974}
  • osgVisual/src/core/visual_core.cpp

    r75 r86  
    1515*/
    1616
     17
    1718#include <visual_core.h>
    1819
     
    2223{
    2324        OSG_NOTIFY( osg::ALWAYS ) << "visual_core instantiated." << std::endl;
     25        #include <leakDetection.h>
     26}
     27
     28visual_core::~visual_core(void)
     29{
     30        // shut osgVisual down
     31        shutdown();
     32
     33        OSG_NOTIFY( osg::ALWAYS ) << "visual_core destroyed." << std::endl;
     34
     35}
     36
     37void visual_core::initialize()
     38{
     39        OSG_NOTIFY( osg::ALWAYS ) << "Initialize visual_core..." << std::endl;
     40
     41        // Configure osg to use KdTrees
     42        osgDB::Registry::instance()->setBuildKdTreesHint(osgDB::ReaderWriter::Options::BUILD_KDTREES);
    2443
    2544        // Setup pathes
     
    3453
    3554        // Test memory leak (todo)
    36         //double* test = new double[1000];
     55        double* test = new double[1000];
    3756
    3857        #ifdef USE_SPACENAVIGATOR
     
    4160
    4261        //osg::DisplaySettings::instance()->setNumOfDatabaseThreadsHint( 8 );
    43 }
    44 
    45 visual_core::~visual_core(void)
    46 {
    47         // shut osgVisual down
    48         shutdown();
    49 
    50         OSG_NOTIFY( osg::ALWAYS ) << "visual_core destroyed." << std::endl;
    51 
    52 }
    53 
    54 void visual_core::initialize()
    55 {
    56         OSG_NOTIFY( osg::ALWAYS ) << "Initialize visual_core..." << std::endl;
    57 
    58         // Load terrain
    59         //loadTerrain(arguments);
    6062
    6163        // Show model
     
    7375#ifdef USE_SKY_SILVERLINING
    7476        // Initialize sky
    75         OSG_NOTIFY( osg::ALWAYS ) << "Using Sky without distortion." << std::endl;
    7677        sky = new visual_skySilverLining( viewer );
    7778        sky->init(distortedSceneGraph, rootNode);       // Without distortedSceneGraph=NULL
     
    156157        }
    157158#endif
     159
     160        // Destroy osgViewer
     161        viewer = NULL;
    158162}
    159163
Note: See TracChangeset for help on using the changeset viewer.