예제 #1
0
int SiodMain(int argc, char **argv, char **env)
{
    int nargc = argc;
    char **nargv = argv;

#if 0
#ifdef _DEBUG
        int tmpflag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);

        tmpflag |= _CRTDBG_ALLOC_MEM_DF;
        tmpflag |= _CRTDBG_CHECK_ALWAYS_DF;
        tmpflag |= _CRTDBG_LEAK_CHECK_DF;

        _CrtSetDbgFlag (tmpflag);

        _CrtSetBreakAlloc(0x88);
#endif
#endif

    if (nargc > 0)
        siod_shuffle_args(&nargc,&nargv);

    process_cla(sizeof(siod_argv)/sizeof(char*), siod_argv, 1);
	
	set_repl_hooks (SiodPuts, SiodLread, 0, SiodLprint) ;

    int r = siod_main (nargc, nargv, env, SiodIPuts) ;

	return r ;
}
예제 #2
0
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
	_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
	_CrtSetBreakAlloc(60);

	// Register the windows class
	WNDCLASS wndClass;
	wndClass.style = CS_DBLCLKS;
	wndClass.lpfnWndProc = StaticWndProc;
	wndClass.cbClsExtra = 0;
	wndClass.cbWndExtra = 0;
	wndClass.hInstance = hInstance;
	wndClass.hIcon = NULL;
	wndClass.hCursor = LoadCursor( NULL, IDC_ARROW );
	wndClass.hbrBackground = ( HBRUSH )GetStockObject( BLACK_BRUSH );
	wndClass.lpszMenuName = NULL;
	wndClass.lpszClassName = "Direct3DWindowClass";

	if( !RegisterClass( &wndClass ) )
	{
		DWORD dwError = GetLastError();
		if( dwError != ERROR_CLASS_ALREADY_EXISTS )
			return -1;
	}

	// Find the window's initial size, but it might be changed later
	int nDefaultWidth = 1280;
	int nDefaultHeight = 720;

	RECT rc;
	SetRect( &rc, 0, 0, nDefaultWidth, nDefaultHeight );
	AdjustWindowRect( &rc, WS_OVERLAPPEDWINDOW, false );

	// Create the render window
	HWND hWnd = CreateWindow( "Direct3DWindowClass", "Vortex", WS_OVERLAPPEDWINDOW,
		CW_USEDEFAULT, CW_USEDEFAULT, ( rc.right - rc.left ), ( rc.bottom - rc.top ), 0,
		NULL, hInstance, 0 );
	if( hWnd == NULL )
	{
		DWORD dwError = GetLastError();
		return -1;
	}
	gHWND = hWnd;

	ShowWindow( hWnd, SW_SHOW );

	CreateDevice( nDefaultWidth, nDefaultHeight );

	g_plugin.PluginPreInitialize(0,0);
	g_plugin.PluginInitialize( pD3DDevice, 0, 0, nDefaultWidth, nDefaultHeight, nDefaultHeight / (float)nDefaultWidth);
	
	MainLoop();

	g_plugin.PluginQuit();

	pD3DDevice->Release();
	pD3D9->Release();

	return 0;
}
예제 #3
0
파일: Main.cpp 프로젝트: oksangman/Ant
///	@brief	WinMain function
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int)
{
#ifdef CHECK_MEMORYLEAK
	_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
	_CrtSetBreakAlloc( 14279 );  
#endif
	MSG msg;
	msg.message = 0;

	GameMain app;

	if( !app.Create(hInstance) )
	{
		app.Shutdown();
		return false;
	}

	while( msg.message != WM_QUIT )
	{
		if( PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) )
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		else
		{
			app.OnIdle();
		}
	}

	app.Shutdown();

	return true;
}
예제 #4
0
int main(int argc, char **argv, char **env)
{
    int nargc = argc;
    char **nargv = argv;

#if 0
#ifdef _DEBUG
        int tmpflag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);

        tmpflag |= _CRTDBG_ALLOC_MEM_DF;
        tmpflag |= _CRTDBG_CHECK_ALWAYS_DF;
        tmpflag |= _CRTDBG_LEAK_CHECK_DF;

        _CrtSetDbgFlag (tmpflag);

        _CrtSetBreakAlloc(0x88);
#endif
#endif

    if (nargc > 0)
        siod_shuffle_args(&nargc,&nargv);

    process_cla(sizeof(siod_argv)/sizeof(char*), siod_argv, 1);

    return(siod_main(nargc, nargv, env, 0));
}
예제 #5
0
eclCmdOptionMatchIndicator EclCmdCommon::matchCommandLineOption(ArgvIterator &iter, bool finalAttempt)
{
    bool boolValue;
    if (iter.matchFlag(boolValue, ECLOPT_VERSION))
    {
        fprintf(stdout, "%s\n", BUILD_TAG);
        return EclCmdOptionCompletion;
    }
    if (iter.matchOption(optServer, ECLOPT_SERVER)||iter.matchOption(optServer, ECLOPT_SERVER_S))
        return EclCmdOptionMatch;
    if (iter.matchOption(optPort, ECLOPT_PORT))
        return EclCmdOptionMatch;
    if (iter.matchOption(optUsername, ECLOPT_USERNAME)||iter.matchOption(optUsername, ECLOPT_USERNAME_S))
        return EclCmdOptionMatch;
    if (iter.matchOption(optPassword, ECLOPT_PASSWORD)||iter.matchOption(optPassword, ECLOPT_PASSWORD_S))
        return EclCmdOptionMatch;
    if (iter.matchFlag(optVerbose, ECLOPT_VERBOSE) || iter.matchFlag(optVerbose, ECLOPT_VERBOSE_S))
        return EclCmdOptionMatch;

    StringAttr tempArg;
    if (iter.matchOption(tempArg, "-brk"))
    {
#if defined(_WIN32) && defined(_DEBUG)
        unsigned id = atoi(tempArg.sget());
        if (id == 0)
            DebugBreak();
        else
            _CrtSetBreakAlloc(id);
#endif
        return EclCmdOptionMatch;
    }
    if (finalAttempt)
        fprintf(stderr, "\n%s option not recognized\n", iter.query());
    return EclCmdOptionNoMatch;
}
예제 #6
0
// ----------------------------------------------------------------------------
//
int main( int argc, char* argv[] ) {

#if DEBUG_LEAKED_OBJECT_ID > 0
    _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
    _CrtSetBreakAlloc( DEBUG_LEAKED_OBJECT_ID );
#endif

    studio.runStudio();
}
BOOL CSeriousSkaStudioApp::InitInstance()
{
  _CrtSetBreakAlloc(55);
  BOOL bResult;
  CTSTREAM_BEGIN {
    bResult = SubInitInstance();
  } CTSTREAM_END;
  return bResult;
}
예제 #8
0
BOOL CFinaceManagerApp::InitInstance()
{
	// 如果一个运行在 Windows XP 上的应用程序清单指定要
	// 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式,
	//则需要 InitCommonControlsEx()。否则,将无法创建窗口。
	INITCOMMONCONTROLSEX InitCtrls;
	InitCtrls.dwSize = sizeof(InitCtrls);
	// 将它设置为包括所有要在应用程序中使用的
	// 公共控件类。
	InitCtrls.dwICC = ICC_WIN95_CLASSES;
	InitCommonControlsEx(&InitCtrls);

	CWinApp::InitInstance();


	AfxEnableControlContainer();

	// 创建 shell 管理器,以防对话框包含
	// 任何 shell 树视图控件或 shell 列表视图控件。
	CShellManager *pShellManager = new CShellManager;

	// 标准初始化
	// 如果未使用这些功能并希望减小
	// 最终可执行文件的大小,则应移除下列
	// 不需要的特定初始化例程
	// 更改用于存储设置的注册表项
	// TODO: 应适当修改该字符串,
	// 例如修改为公司或组织名
	SetRegistryKey(_T("应用程序向导生成的本地应用程序"));

	CFinaceManagerDlg dlg;
	m_pMainWnd = &dlg;
	INT_PTR nResponse = dlg.DoModal();
	if (nResponse == IDOK)
	{
		// TODO: 在此放置处理何时用
		//  “确定”来关闭对话框的代码
	}
	else if (nResponse == IDCANCEL)
	{
		// TODO: 在此放置处理何时用
		//  “取消”来关闭对话框的代码
	}

	// 删除上面创建的 shell 管理器。
	if (pShellManager != NULL)
	{
		delete pShellManager;
	}
	//_CrtDumpMemoryLeaks();
	// 由于对话框已关闭,所以将返回 FALSE 以便退出应用程序,
	//  而不是启动应用程序的消息泵。
	_CrtSetBreakAlloc(706); 
	return FALSE;
}
예제 #9
0
파일: main.cpp 프로젝트: jorji/HIVE
int main(int argc, char* argv[])
{
#ifdef _WIN32
	#ifdef _DEBUG
		_CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF | _CRTDBG_ALLOC_MEM_DF);
		_CrtSetBreakAlloc(1037);
	#endif
#endif

    int rank = 0;
#ifdef HIVE_ENABLE_MPI
    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    //printf("[MPI] rank = %d\n", rank);
#endif
    
    char* scenefile = 0;
    std::vector<std::string> sceneargs;
    
    // Parse args
    for (int i = 1; i < argc; ++i) {
        //const char* arg = &argv[i][0];
        size_t na = strlen(argv[i]);
        if (i == 1
        && na > 4
        && (strncasecmp(&argv[i][na-4],".scn",4) == 0 || strncasecmp(&argv[i][na-4],".lua",4) == 0))
        {
            scenefile = argv[i];
        }
        if (i > 1 && na < 2048) {
            sceneargs.push_back(argv[i]);
        }
    }
    
    if (argc <= 1 || scenefile == 0) {
		if (rank == 0) {
			printf("\n  Usage: hrender scenefile.scn\n\n");
		}

#ifdef HIVE_ENABLE_MPI
        MPI_Finalize();
#endif
        return 0;
    }
    
    renderScene(scenefile, sceneargs);
    
    printf("Exit hrender.\n");
    
#ifdef HIVE_ENABLE_MPI
    printf("[MPI] finalize at rank: %d\n", rank);
    MPI_Finalize();
#endif
    return 0;
}
예제 #10
0
파일: TTG.cpp 프로젝트: Ithos/TTG
int main(int argc, char **argv) 
{
#if (!defined _VISUALLEAKDETECTOR) && (defined _LEAKDETECTOR)
	_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
	_CrtSetBreakAlloc(-1);
#endif
#else
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
int WINAPI
WinMain(HINSTANCE zhInstance, HINSTANCE prevInstance, LPSTR lpCmdLine, int nCmdShow) 
{
#endif
	{
		const char* const logFile = "./conf/log.conf";
		Application::CTTGApplication* ttg(new Application::CTTGApplication());
		try{
			
#ifdef _DEBUG
			std::stringstream ss;
			ss << "./log/ttg_" << time(0) <<".log";
			std::string log_file = ss.str();
#else
			std::string log_file = "";
#endif
			log_set_up(logFile,log_file.c_str(),true);
			blog_set_up(0,Common::BLog::Level::TRACE,false);
			log_trace("MAIN","Opening...\n");
			if(ttg->init()) 
				while(ttg->run()){
					ttg->release();
					delete ttg;
					ttg = new Application::CTTGApplication();
					ttg->init();
				}
			ttg->release();
			delete ttg;
			log_trace("MAIN","Closing...\n");
		} catch(std::runtime_error e){
			//Needed for the log
			//ttg.release();
			exit(-1);
		}
		//Needed for the log
		try{
		std::raise(SIGTERM);
		} catch(...){

		}
	}
	return 0;
}
예제 #11
0
BOOL CNetTestDlg::OnInitDialog()
{
	CDialog::OnInitDialog();
	_CrtSetBreakAlloc(149);

	// 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
	//  执行此操作
	SetIcon(m_hIcon, TRUE);			// 设置大图标
	SetIcon(m_hIcon, FALSE);		// 设置小图标

	// TODO: 在此添加额外的初始化代码

	return TRUE;  // 除非将焦点设置到控件,否则返回 TRUE
}
예제 #12
0
파일: Main.cpp 프로젝트: itana/KIMP
int main(int argc, char* argv[])
{
#ifdef _MSC_VER
	// Tell the c-run time to do memory check at program shut down
	_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
	_CrtSetBreakAlloc(-1);
#endif

	// Choose the test you want to run
//	testCpuProfiler();
//	testMemoryProfiler();
	testMemoryProfilerTcpServer();

	return 0;
}
예제 #13
0
파일: Main.cpp 프로젝트: adan830/FKEngine
//--------------------------------------------------------------------
int main( int p_nArgc, char* p_Argv[] )
{
	_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
	_CrtSetBreakAlloc( 717 );
	try
	{
		CGameWindow window;
		window.Show();
	}
	catch( ... )
	{
		throw;
	}

	_CrtDumpMemoryLeaks();
}
예제 #14
0
파일: runperl.c 프로젝트: cobaugh/rt-rpm
int
main(int argc, char **argv, char **env)
{
#ifdef _MSC_VER
    /* Arrange for _CrtDumpMemoryLeaks() to be called automatically at program
     * termination when built with CFG = DebugFull. */
    int currentFlag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
    currentFlag |= _CRTDBG_LEAK_CHECK_DF;
    _CrtSetDbgFlag(currentFlag);

    /* Change this -1 to the allocation number of any reported memory leaks to
     * break on the allocation call that was leaked. */
    _CrtSetBreakAlloc(-1L);
#endif

    return RunPerl(argc, argv, env);
}
예제 #15
0
KPROXY_API f8_bool kproxy_init(int leakDetect)
{
	ITcpAdapter *a;	

	_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
	_CrtSetBreakAlloc(leakDetect);
	
	/* initialize and start kernel */
	ex_init();
	
	/* KERN_F_ENABLE_INPUT */

	x_buffer = (char *)__malloc__(LARGE_BUF_SIZE);
	x_buf_len = LARGE_BUF_SIZE;
	b_ShellExit = __false;	

	__new__(ITcpAdapter, a);
	proxy_adapter = __ucast__(ITcpAdapter, IKAdapter, a);

	sections = ke_get_blk(proxy_adapter->kernel, 0);
	assert(sections->uuid == BLK_ID_ROOT);

	create_resource(&sections->uuid);
	create_f8_uuid(&sections->h.uuid);
	create_resource(&sections->h.uuid);

	memset(fileName, 0 , sizeof(fileName));

	g_shell = shell_create(commands);
	
	reset_reg_map();
	init_blklib();
	init_clipboard();

	g_bDirty = __false;


	init_network(RTK_INIT_AS_SERVER, 0);
	vbus = connect_vbus(0xf8, VBUS_CONNECT_AS_SERVER, sr, 0);
	
	return __true;
}
예제 #16
0
파일: Main.cpp 프로젝트: whztt07/DGLE
BOOL APIENTRY DllMain(HMODULE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved)
{
	switch (ul_reason_for_call)
	{
	case DLL_PROCESS_ATTACH:

#if defined(_DEBUG) && CRT_BREAK_ON_ALLOC >= 0
		_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
		_CrtSetBreakAlloc(CRT_BREAK_ON_ALLOC);
#endif
		
		::hModule = hModule;
		
		break;

	case DLL_PROCESS_DETACH:
		
		for(size_t i = 0; i < vecEngineInstances.size(); ++i)
		{
			if(vecEngineInstances[i].pclCore)
			{
				delete vecEngineInstances[i].pclCore;
				vecEngineInstances[i].pclCore = NULL;
			}

			if(vecEngineInstances[i].pclConsole)
				delete vecEngineInstances[i].pclConsole;
		}

		vecEngineInstances.clear();

		if(bTerminate)
			TerminateProcess(GetCurrentProcess(), 1);
		
		break;
	}

	return TRUE;
}
예제 #17
0
bool EclCMDShell::parseCommandLineOptions(ArgvIterator &iter)
{
    if (iter.done())
    {
        usage();
        return false;
    }

    bool boolValue;
    for (; !iter.done(); iter.next())
    {
        const char * arg = iter.query();
        if (iter.matchFlag(optHelp, "help"))
            continue;
        if (*arg!='-')
        {
            cmd.set(arg);
            iter.next();
            break;
        }
        if (iter.matchFlag(boolValue, "--version"))
        {
            fprintf(stdout, "%s\n", BUILD_TAG);
            return false;
        }
        StringAttr tempArg;
        if (iter.matchOption(tempArg, "-brk"))
        {
#if defined(_WIN32) && defined(_DEBUG)
            unsigned id = atoi(tempArg.sget());
            if (id == 0)
                DebugBreak();
            else
                _CrtSetBreakAlloc(id);
#endif
        }
    }
    return true;
}
예제 #18
0
파일: Main.cpp 프로젝트: oksangman/Ant
///	@brief	WinMain function
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int)
{
#ifdef CHECK_MEMORYLEAK
	//_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
	_CrtSetBreakAlloc( 5831 );  
#endif
	MSG msg;
	msg.message = 0;
	HACCEL hAccelTable;

	GameMain app;

	if( !app.Create(hInstance) )
	{
		app.Shutdown();
		return false;
	}

	hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_WIN01);


	while( msg.message != WM_QUIT )
	{
		if( PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) )
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		else
		{
			app.OnIdle();
		}
	}

	app.Shutdown();

	return true;
}
예제 #19
0
esdlCmdOptionMatchIndicator EsdlCmdCommon::matchCommandLineOption(ArgvIterator &iter, bool finalAttempt)
{
    bool boolValue;
    if (iter.matchFlag(boolValue, ESDLOPT_HELP))
    {
        usage();
        return EsdlCmdOptionCompletion;
    }
    if (iter.matchFlag(boolValue, ESDLOPT_VERSION))
    {
        fprintf(stdout, "%s\n", BUILD_TAG);
        return EsdlCmdOptionCompletion;
    }

    if (iter.matchFlag(optVerbose, ESDL_OPTION_VERBOSE) || iter.matchFlag(optVerbose, ESDL_OPT_VERBOSE))
    {
        return EsdlCmdOptionMatch;
    }

    StringAttr tempArg;
    if (iter.matchOption(tempArg, "-brk"))
    {
#if defined(_WIN32) && defined(_DEBUG)
        unsigned id = atoi(tempArg.str());
        if (id == 0)
            DebugBreak();
        else
            _CrtSetBreakAlloc(id);
#endif
        return EsdlCmdOptionMatch;
    }
    if (finalAttempt)
    {
        fprintf(stderr, "\n%s option not recognized\n", iter.query());
        usage();
    }
    return EsdlCmdOptionNoMatch;
}
예제 #20
0
    void Debug::Initializer() {
#if defined(_DEBUG) & defined(WIN32)
        _CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_FILE );
        _CrtSetReportFile( _CRT_ERROR, _CRTDBG_FILE_STDERR );
  
        int tmpDbgFlag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
        tmpDbgFlag |= 
            _CRTDBG_ALLOC_MEM_DF // Enable debug heap allocations and use of memory block type identifiers.
            // | _CRTDBG_CHECK_CRT_DF // Track C run-time allocations.
            | _CRTDBG_LEAK_CHECK_DF // Perform automatic leak checking at program exit through a call to _CrtDumpMemoryLeaks.
            // | _CRTDBG_DELAY_FREE_MEM_DF // This catches stale ptr writes.
            // | _CRTDBG_CHECK_ALWAYS_DF // This slows down execution!
            // | _CRTDBG_CHECK_EVERY_1024_DF // The number of mallocs between leak checking.
         ;
        _CrtSetDbgFlag(tmpDbgFlag);

#if 0 // For setting a breakpoint on a particular memory allocation:
        static int memAllocNumber = 0;
        _CrtSetBreakAlloc(memAllocNumber);
        // Via debugger: Watch Name: {,,msvcr80d.dll}_crtBreakAlloc
#endif

#endif
    }
예제 #21
0
//=======================================================================
void Application::breakOnCRTAlloc ( int n )
{
#ifdef _DEBUG
   _CrtSetBreakAlloc( n ); 
#endif
}
예제 #22
0
int pwin32main(int argc, char* argv[])
{
    // Enable memory leak checks and heap validation. 
    _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_LEAK_CHECK_DF);
    _CrtSetBreakAlloc(-1);

    int exitCode = EXIT_SUCCESS;

    // Create the memory debugger.
    PMemoryDebugger::create();

    PActivity* activity = PNEW(PActivity(argc, argv));
    if (!activity->initialize())
    {
        PDELETE(activity);
        return EXIT_FAILURE;
    }
    
    pMain(argc, argv);

    // Set console title.
    SetConsoleTitle(L"Console");
    
    // Disable the close button of the console window.
    HWND hConsoleWindow = GetConsoleWindow();
    if (hConsoleWindow != NULL)
    {
        HMENU hMenu = GetSystemMenu(hConsoleWindow, 0);
        if (hMenu != NULL)
        {
            DeleteMenu(hMenu, SC_CLOSE, MF_BYCOMMAND);
            DrawMenuBar(hConsoleWindow);
        }
    }

    PContext* context = activity->findContext(puint32(0));
    PASSERT(context != P_NULL);
    if (context == P_NULL)
    {
        exitCode = EXIT_FAILURE;
        PDELETE(activity);
        return exitCode;
    }

    PWin32Window window(context);

    if (!window.create())
    {
        exitCode = EXIT_FAILURE;
        PDELETE(activity);
        return exitCode;
    }
    
    // Initialize the context. 
    context->setState(P_CONTEXT_STATE_UNINITIALIZED);
    if (!context->initialize(context->properties()->m_windowWidth, context->properties()->m_windowHeight))
    {
        exitCode = EXIT_FAILURE;
    }
    else
    {
        if (!context->onInitialized())
        {
            context->setState(P_CONTEXT_STATE_ERROR);
        }
        else
        {
            PLOG_DEBUG("Starting program main loop");
            context->setState(P_CONTEXT_STATE_RUNNING);
        }

        if (context->state() == P_CONTEXT_STATE_ERROR)
        {
            exitCode = EXIT_FAILURE;
        }

        // The mainloop of window.
        window.run();

        // Right before destroy the context, user might have
        // something to do.
        context->onDestroy();
    }

    context->destroy();
    
    // Destroy native window.
    window.destroy();

    // Destroy the activity
    activity->uninitialize();
    PDELETE(activity);

    // Destroy the memory debugger.
    PMemoryDebugger::destroy();

    // If debugger is present, a pause is required to keep the console output
    // visible. Otherwise the pause is automatic. 
    if (IsDebuggerPresent())
    {
        system("pause");
    }

    return exitCode;
}
예제 #23
0
//-----------------------------------------------------------------------------
// FIXME: Remove when we make our own heap! Crt stuff we're currently using
//-----------------------------------------------------------------------------
long CDbgMemAlloc::CrtSetBreakAlloc( long lNewBreakAlloc )
{
	return _CrtSetBreakAlloc( lNewBreakAlloc );
}
예제 #24
0
파일: Main.cpp 프로젝트: nzeemin/nemigabtl
int APIENTRY _tWinMain(
    HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPTSTR    lpCmdLine,
    int       nCmdShow)
{
    UNREFERENCED_PARAMETER(hPrevInstance);
    UNREFERENCED_PARAMETER(lpCmdLine);

#ifdef _DEBUG
    _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF);
    int n = 0;
    _CrtSetBreakAlloc(n);
#endif

    g_hInst = hInstance; // Store instance handle in our global variable

    LARGE_INTEGER nFrameStartTime;
    nFrameStartTime.QuadPart = 0;

    // Initialize global strings
    LoadString(g_hInst, IDS_APP_TITLE, g_szTitle, MAX_LOADSTRING);
    LoadString(g_hInst, IDC_NEMIGABTL, g_szWindowClass, MAX_LOADSTRING);
    MainWindow_RegisterClass();

    // Perform application initialization
    if (! InitInstance(hInstance, nCmdShow))
        return FALSE;

    HACCEL hAccelTable = ::LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_NEMIGABTL));

    LARGE_INTEGER nPerformanceFrequency;
    ::QueryPerformanceFrequency(&nPerformanceFrequency);

    // Main message loop
    MSG msg;
    for (;;)
    {
        ::QueryPerformanceCounter(&nFrameStartTime);

        if (!g_okEmulatorRunning)
            ::Sleep(20);
        else
        {
            if (Emulator_IsBreakpoint())
                Emulator_Stop();
            else
            {
                Emulator_SystemFrame();

                ScreenView_RedrawScreen();
            }
        }

        // Process all queue
        while (::PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ))
        {
            if (msg.message == WM_QUIT)
                goto endprog;

            if (::TranslateAccelerator(g_hwnd, hAccelTable, &msg))
                continue;

            ::TranslateMessage(&msg);
            ::DispatchMessage(&msg);
        }

        if (g_okEmulatorRunning && !Settings_GetSound())
        {
            if (Settings_GetRealSpeed() == 0)
                ::Sleep(1);  // We should not consume 100% of CPU
            else
            {
                // Slow down to 25 frames per second
                LARGE_INTEGER nFrameFinishTime;  // Frame start time
                ::QueryPerformanceCounter(&nFrameFinishTime);
                LONGLONG nTimeElapsed = (nFrameFinishTime.QuadPart - nFrameStartTime.QuadPart)
                        * 1000 / nPerformanceFrequency.QuadPart;
                LONGLONG nFrameDelay = 1000 / 25 - 1;  // 1000 millisec / 25 = 40 millisec
                if (Settings_GetRealSpeed() == 0x7ffe)  // Speed 25%
                    nFrameDelay = 1000 / 25 * 4 - 1;
                else if (Settings_GetRealSpeed() == 0x7fff)  // Speed 50%
                    nFrameDelay = 1000 / 25 * 2 - 1;
                else if (Settings_GetRealSpeed() == 2)  // Speed 200%
                    nFrameDelay = 1000 / 25 / 2 - 1;
                if (nTimeElapsed > 0 && nTimeElapsed < nFrameDelay)
                {
                    LONG nTimeToSleep = (LONG)(nFrameDelay - nTimeElapsed);
                    ::Sleep((DWORD)nTimeToSleep);
                }
            }
        }
    }
endprog:

    DoneInstance();

#ifdef _DEBUG
    if (_CrtDumpMemoryLeaks())
        ::MessageBeep(MB_ICONEXCLAMATION);
#endif

    return (int) msg.wParam;
}
예제 #25
0
void memory_leak_test(behaviac::Workspace::EFileFormat format)
{
#if ENABLE_MEMORYDUMP
    _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
    _CrtDumpMemoryLeaks();

    static long s_breakalloc = -1;
    _CrtSetBreakAlloc(s_breakalloc);
#endif
    behaviac::IMemAllocator& allocator = behaviac::GetMemoryAllocator();
	size_t allocatedSize = allocator.GetAllocatedSize();

#if ENABLE_MEMORYDUMP
    _CrtMemState s1;
    _CrtMemCheckpoint(&s1);
#endif
    EmployeeParTestAgent::clearAllStaticMemberVariables();

    behaviac::Profiler::CreateInstance();
    behaviac::Config::SetSocketing(false);
    behaviac::Config::SetLogging(false);

    registerAllTypes();
    EmployeeParTestAgent* myTestAgent = EmployeeParTestAgent::DynamicCast(behaviac::Agent::Create<EmployeeParTestAgent>());
    behaviac::Agent::SetIdMask(1);
    myTestAgent->SetIdFlag(1);

    //myTestAgent->btload("par_test/register_name_as_left_value_and_param");
    myTestAgent->btsetcurrent("par_test/register_name_as_left_value_and_param");

    ParTestRegNameAgent::clearAllStaticMemberVariables();

    behaviac::Agent::Create<ParTestRegNameAgent>("ParTestRegNameAgent");
    ParTestRegNameAgent* regNameAgent = behaviac::Agent::GetInstance<ParTestRegNameAgent>("ParTestRegNameAgent");
    regNameAgent->resetProperties();

    myTestAgent->resetProperties();
    myTestAgent->btexec();

    behaviac::Agent::Destroy(regNameAgent);
    behaviac::Agent::UnRegisterInstanceName<ParTestRegNameAgent>("ParTestRegNameAgent");

    BEHAVIAC_DELETE(myTestAgent);
    behaviac::Workspace::GetInstance()->UnLoadAll();

    EmployeeParTestAgent::clearAllStaticMemberVariables();
    ParTestRegNameAgent::clearAllStaticMemberVariables();

    unregisterAllTypes();

    behaviac::Profiler::DestroyInstance();

	size_t allocatedSize1 = allocator.GetAllocatedSize();
	size_t allocateDiff = allocatedSize1 - allocatedSize;

#if !ENABLE_MEMORYDUMP
    //if CStringID is used before this test, CStringID::Cleaup() will free more memory
    //allocateDiff would be negative
    //CHECK_EQUAL(true, allocateDiff <= 0);
    CHECK_EQUAL(true, allocateDiff == 0);
#endif

#if ENABLE_MEMORYDUMP
    _CrtMemState s2;
    _CrtMemState s3;

    BEHAVIAC_UNUSED_VAR(s1);
    BEHAVIAC_UNUSED_VAR(s2);
    BEHAVIAC_UNUSED_VAR(s3);

    _CrtMemCheckpoint(&s2);

    //CHECK_EQUAL(0, _CrtMemDifference(&s3, &s1, &s2));
    if (_CrtMemDifference(&s3, &s1, &s2))
    {
        _CrtMemDumpStatistics(&s3);
        _CrtDumpMemoryLeaks();
    }

#endif
    BEHAVIAC_ASSERT(true);
}
예제 #26
0
파일: main.cpp 프로젝트: suyu0925/backup
int main(int argc, char* argv[])
{
    int exitCode = EXIT_SUCCESS;

    PActivity* activity = pNew(PActivity(argc, argv));
    
    // Enable memory leak checks and heap validation. 
    _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_LEAK_CHECK_DF);
    _CrtSetBreakAlloc(-1);
    
    pMain(argc, argv);

    // Set console title.
    SetConsoleTitle(L"protoss debug console");
    
    // Disable the close button of the console window.
    HWND hConsoleWindow = GetConsoleWindow();
    if (hConsoleWindow != NULL)
    {
        HMENU hMenu = GetSystemMenu(hConsoleWindow, 0);
        if (hMenu != NULL)
        {
            DeleteMenu(hMenu, SC_CLOSE, MF_BYCOMMAND);
            DrawMenuBar(hConsoleWindow);
        }
    }

    PContext* context = activity->findContext(pUint32(0));
    pAssert(context != P_NULL);
    if (context == P_NULL)
    {
        exitCode = EXIT_FAILURE;
        pDelete(activity);
        return exitCode;
    }

    PWin32Window window(context);

    if (!window.create())
    {
        exitCode = EXIT_FAILURE;
        pDelete(activity);
        return exitCode;
    }
    
    // Initialize the context. 
    // kzaPlatformSetInstanceHandle(context, GetModuleHandle(NULL));
    context->setState(P_CONTEXT_STATE_UNINITIALIZED);
    if (!context->initialize())
    {
        exitCode = EXIT_FAILURE;
    }

    if (!context->onInitialized())
    {
        context->setState(P_CONTEXT_STATE_ERROR);
    }
    else
    {
        pLogDebug("Starting program main loop");
        context->setState(P_CONTEXT_STATE_RUNNING);
    }

    if (context->getState() == P_CONTEXT_STATE_ERROR)
    {
        exitCode = EXIT_FAILURE;
    }

    // The mainloop of window.
    window.run();

    // Right before destroy the context, user might have
    // something to do.
    context->onDestroy();

    context->destroy();
    
    // Destroy native window.
    window.destroy();

    // Destroy the activity
    pDelete(activity);

    // If debugger is present, a pause is required to keep the console output
    // visible. Otherwise the pause is automatic. 
    if (IsDebuggerPresent())
    {
        system("pause");
    }

    return exitCode;
}
예제 #27
0
파일: main.cpp 프로젝트: asir6/Colt
int main(int argc, char** argv)
{
#if defined(_WIN32) && defined(_DEBUG)
#if !defined(USING_VLD)
    _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);

    #ifdef _DEBUG
    // to debug memory leaks, set a breakpoint here and set iBlock
    // to the block allocation you want to break on
    long iBlock = -1;
    _CrtSetBreakAlloc(iBlock);
    #endif
#endif
#endif

    ACE_DEBUG((LM_INFO, ACE_TEXT("Initialize Platform.ini\n")));
    //Benchmark this
#ifdef WIN32
    //Muffle errors due to broken FDO RDBMS provider dlls, they aren't the ones exercised
    //under test anyway
    SetErrorMode(SEM_FAILCRITICALERRORS);
    long lStart = GetTickCount();
#endif
    MgdPlatform::Initialize(L"Platform.ini");
#ifdef WIN32
    ACE_DEBUG((LM_INFO, ACE_TEXT("Platform Initialization time in %dms\n"), (GetTickCount()-lStart)));
#endif
    Ptr<MgCoordinateSystemFactory> csFactory = new MgCoordinateSystemFactory();
    Ptr<MgCoordinateSystemCatalog> csCatalog = csFactory->GetCatalog();
    STRING dictDir = csCatalog->GetDictionaryDir();

    ACE_DEBUG((LM_INFO, ACE_TEXT("MENTOR_DICTIONARY_PATH is: %s\n"), dictDir.c_str()));

    CppUnit::TextUi::TestRunner runner;

    // Add all of the tests
    //NOTE: Leave trace log off, otherwise one of the tests here will fail
#if TEST_LOG_MANAGER == 1
    runner.addTest(CppUnit::TestFactoryRegistry::getRegistry("TestLogManager").makeTest());
#endif
#if TEST_RESOURCE_SERVICE == 1
    runner.addTest(CppUnit::TestFactoryRegistry::getRegistry("TestResourceService").makeTest());
#endif
#if TEST_RENDERING_SERVICE == 1
    runner.addTest(CppUnit::TestFactoryRegistry::getRegistry("TestRenderingService").makeTest());
#endif
#if TEST_FEATURE_SERVICE == 1
    runner.addTest(CppUnit::TestFactoryRegistry::getRegistry("TestFeatureService").makeTest());
#endif
#if TEST_MAPPING_SERVICE == 1
    runner.addTest(CppUnit::TestFactoryRegistry::getRegistry("TestMappingService").makeTest());
#endif
#if TEST_PROFILING_SERVICE == 1
	runner.addTest(CppUnit::TestFactoryRegistry::getRegistry("TestProfilingService").makeTest());
#endif
#if TEST_TILE_SERVICE == 1
    //This causes access violations in Visual Leak Detector when run in debug mode. Only uncommment
    //to verify functionality, but don't use VLD for memory leak detection. Seek an alternate tool/library
    //in this case.
    runner.addTest(CppUnit::TestFactoryRegistry::getRegistry("TestTileService").makeTest());
#endif

    STRING fileName = L"UnitTestResults.xml";
    if (fileName.size() > 0)
    {
        ofstream outfile(MG_WCHAR_TO_CHAR(fileName.c_str()));

        if (outfile.is_open())
        {
            runner.setOutputter(new CppUnit::XmlOutputter(&runner.result(), outfile, "ISO-8859-1"));
            runner.run();
            outfile.close();
        }
    }
    else
    {
        runner.setOutputter(new CppUnit::TextOutputter(&runner.result(), std::cout));
        runner.run();
    }

    int nResult = runner.result().testFailuresTotal();

    MgdPlatform::Terminate();

    return nResult;
}
예제 #28
0
int main(int argc, char **argv)
{
    setlocale(LC_ALL, "C");
    DisableDataExecution();

    WStrVec argList;
    ParseCmdLine(GetCommandLine(), argList);
    if (argList.Count() < 2) {
Usage:
        ErrOut("%s <filename> [-pwd <password>][-full][-alt][-render <path-%%d.tga>]\n",
            path::GetBaseName(argList.At(0)));
        return 0;
    }

    ScopedMem<WCHAR> filePath;
    WIN32_FIND_DATA fdata;
    HANDLE hfind = FindFirstFile(argList.At(1), &fdata);
    if (INVALID_HANDLE_VALUE != hfind) {
        ScopedMem<WCHAR> dir(path::GetDir(argList.At(1)));
        filePath.Set(path::Join(dir, fdata.cFileName));
        FindClose(hfind);
    }
    else {
        // embedded documents are referred to by an invalid path
        // containing more information after a colon (e.g. "C:\file.pdf:3:0")
        filePath.Set(str::Dup(argList.At(1)));
    }

    bool fullDump = false;
    WCHAR *password = NULL;
    WCHAR *renderPath = NULL;
    bool useAlternateHandlers = false;
    bool loadOnly = false;
    int breakAlloc = 0;

    for (size_t i = 2; i < argList.Count(); i++) {
        if (str::Eq(argList.At(i), L"-full"))
            fullDump = true;
        else if (str::Eq(argList.At(i), L"-pwd") && i + 1 < argList.Count())
            password = argList.At(++i);
        else if (str::Eq(argList.At(i), L"-render") && i + 1 < argList.Count())
            renderPath = argList.At(++i);
        else if (str::Eq(argList.At(i), L"-alt"))
            useAlternateHandlers = true;
        else if (str::Eq(argList.At(i), L"-loadonly"))
            loadOnly = true;
#ifdef DEBUG
        else if (str::Eq(argList.At(i), L"-breakalloc") && i + 1 < argList.Count())
            breakAlloc = _wtoi(argList.At(++i));
#endif
        else
            goto Usage;
    }

#ifdef DEBUG
    if (breakAlloc) {
        _CrtSetBreakAlloc(breakAlloc);
        if (!IsDebuggerPresent())
            MessageBox(NULL, L"Keep your debugger ready for the allocation breakpoint...", L"EngineDump", MB_ICONINFORMATION);
    }
#endif

    // optionally use GDI+ rendering for PDF/XPS and the original ChmEngine for CHM
    DebugGdiPlusDevice(useAlternateHandlers);
    DebugAlternateChmEngine(!useAlternateHandlers);

    ScopedGdiPlus gdiPlus;
    DocType engineType;
    PasswordHolder pwdUI(password);
    BaseEngine *engine = EngineManager::CreateEngine(true, filePath, &pwdUI, &engineType);
    if (!engine) {
        ErrOut("Error: Couldn't create an engine for %s!\n", path::GetBaseName(filePath));
        return 1;
    }
    if (!loadOnly)
        DumpData(engine, fullDump);
    if (renderPath)
        RenderDocument(engine, renderPath);
    delete engine;

#ifdef DEBUG
    // report memory leaks on stderr for engines that shouldn't leak
    if (engineType != Engine_DjVu) {
        _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
        _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
        _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
    }
#endif

    return 0;
}
예제 #29
0
파일: AFXMEM.CPP 프로젝트: VectorDM/VC98
// Obsolete API
void AFXAPI AfxSetAllocStop(LONG lRequestNumber)
{
	_CrtSetBreakAlloc(lRequestNumber);
}
예제 #30
0
int main()
{
#ifdef DEBUG_MEM_LEAK_ALLOC_CRASH
  _CrtSetBreakAlloc(DEBUG_MEM_LEAK_ALLOC_ADDR);
#endif

  {

    Image* img = NULL;
    Vec3* eye = NULL;
    int nObj = 0, nSrc = 0;
    Object **obj = NULL, **src = NULL;

    std::cout << "Calling cfg parser." << std::endl;
    getParams(CONFIG_FILE_PATH);

    sceneParser(SCENE_PATH, &obj, &nObj, &src, &nSrc, &img, &eye);

    /* ~~~ Start rendering. ~~~ */
    std::cout << "Creating test world\n";
    TestWorld world = TestWorld(obj, nObj, src, nSrc, *eye, img, 1.0f);
#ifdef EN_PARALLEL_PROC
    par_proc_testWorld = &world;
#endif
    world.runTest();

    /* Delete allocated objects and sources. */
    /* First delete objects. */
    for (int j = 0; j < nObj; j++)
    {
      bool skipThisObj = false;
      /* Don't delete if we're going to delete it in the sources list later. */
      for (int k = 0; k < nSrc; k++)
      {
        if (obj[j] == src[k])
        {
          skipThisObj = true;
          break;
        }
      }
      if (skipThisObj)
      {
        continue;
      }
      /* No repeat in source list, go ahead and delete. */
      std::cout << "Del obj " << j << "\n";
      delete obj[j];
    }
    /* delete the array itself. */
    delete[] obj;

    for (int j = 0; j < nSrc; j++)
    {
      std::cout << "Del src " << j << "\n";
      delete src[j];
    }
    /* delete the array itself. */
    delete[] src;

    img->autoScale();
    img->exportBitmap(OUTPUT_IMG);

    delete img;
    delete eye;

    std::cout << "End\n";
  }

#ifdef DEBUG_MEM_LEAK_REPORT
  _CrtDumpMemoryLeaks();
#endif

  return 0;
}