【发布时间】:2016-05-28 02:03:51
【问题描述】:
我有一个很笼统的问题,但我希望有人能够至少指出我正确的方向。
我创建了我的项目,我只在带有 /MDd 标志的调试模式下构建它。 但它开始出现性能问题,所以我想在发布模式下尝试它,看看它是如何进行的。 问题是,当我使用 /MD 或 /MT 标志和发布模式时,我的应用程序会立即崩溃。 所以我试图找出原因。它在调试中工作正常。我尝试了一些代码更改,但没有任何帮助。所以我决定让我的应用程序刚刚启动并注释掉我的其余代码。但它仍然崩溃。即使我的代码未被使用。当我完全删除那些未使用的代码部分时,它不仅崩溃了。
我认为这是具有变量初始化/声明的东西,但我不太确定我应该寻找什么。
有人可以建议我什么会导致应用程序崩溃,即使它只是声明/初始化,甚至没有在运行时使用?
我希望你能以某种方式理解我的问题。
感谢您的任何建议!
编辑:当项目中有未使用的代码时崩溃的代码,但当我删除未使用的代码时不会崩溃。
#include "core/oxygine.h"
#include "Stage.h"
#include "DebugActor.h"
//#include "Galatex.h"
using namespace oxygine;
//called each frame
int mainloop()
{
//galatex_update();
//update our stage
//update all actors. Actor::update would be called also for all children
getStage()->update();
if (core::beginRendering())
{
Color clearColor(32, 32, 32, 255);
Rect viewport(Point(0, 0), core::getDisplaySize());
//render all actors. Actor::render would be called also for all children
getStage()->render(clearColor, viewport);
core::swapDisplayBuffers();
}
//update internal components
//all input events would be passed to Stage::instance.handleEvent
//if done is true then User requests quit from app.
bool done = core::update();
return done ? 1 : 0;
}
//it is application entry point
void run()
{
ObjectBase::__startTracingLeaks();
//initialize Oxygine's internal stuff
core::init_desc desc;
#if OXYGINE_SDL || OXYGINE_EMSCRIPTEN
//we could setup initial window size on SDL builds
desc.w = 1800;
desc.h = 1000;
//marmalade settings could be changed from emulator's menu
#endif
//galatex_preinit();
core::init(&desc);
//create Stage. Stage is a root node
Stage::instance = new Stage(true);
Point size = core::getDisplaySize();
getStage()->setSize(size);
//DebugActor is a helper actor node. It shows FPS, memory usage and other useful stuff
DebugActor::show();
//initialize this example stuff. see example.cpp
//galatex_init();
#ifdef EMSCRIPTEN
/*
if you build for Emscripten mainloop would be called automatically outside.
see emscripten_set_main_loop below
*/
return;
#endif
//here is main game loop
while (1)
{
int done = mainloop();
if (done)
break;
}
//user wants to leave application...
//lets dump all created objects into log
//all created and not freed resources would be displayed
ObjectBase::dumpCreatedObjects();
//lets cleanup everything right now and call ObjectBase::dumpObjects() again
//we need to free all allocated resources and delete all created actors
//all actors/sprites are smart pointer objects and actually you don't need it remove them by hands
//but now we want delete it by hands
//check example.cpp
//galatex_destroy();
//renderer.cleanup();
/**releases all internal components and Stage*/
core::release();
//dump list should be empty now
//we deleted everything and could be sure that there aren't any memory leaks
ObjectBase::dumpCreatedObjects();
ObjectBase::__stopTracingLeaks();
//end
}
#ifdef __S3E__
int main(int argc, char* argv[])
{
run();
return 0;
}
#endif
#ifdef OXYGINE_SDL
#include "SDL_main.h"
extern "C"
{
int main(int argc, char* argv[])
{
run();
return 0;
}
};
#endif
#ifdef EMSCRIPTEN
#include <emscripten.h>
void one() { mainloop(); }
int main(int argc, char* argv[])
{
run();
emscripten_set_main_loop(one, 0, 0);
return 0;
}
#endif
【问题讨论】:
-
您需要发布代码(您声称您有最小的崩溃示例)。
-
如果您在 VS 中从模板创建项目,那么您无需担心所有这些开关。您选择调试或发布。我建议你创建一个新项目并将所有代码复制到其中。
-
我添加了与未使用的代码一起崩溃的代码,但是当我从项目中完全删除未使用的代码时很好。但我认为这对任何事情都没有帮助。
-
如果您评论了所有代码 - 正如您所说的
So I decided to make my app just start and comment out rest of my code,那么您有一些项目配置问题。 -
我已经将代码从项目复制到新项目,但没有帮助。
标签: c++ visual-studio