最近,我一直在与 SFML 合作创建一个小游戏——直到今天晚上,一切都出奇地快速和简单。我离开了常用的工作站,在 Windows 8 平板电脑/上网本上进行了一些清理工作,游戏窗口不再出现。我可以运行程序,它立即完成,并要求我按任意键退出控制台。我做了一些研究,发现我使用的SFML版本不支持ATI显卡,所以我将程序升级到2.0(它现在基本上只是一个框架,所以升级只花了几个小时,并且我认为即使它没有解决所有问题也不会受到伤害)。
不幸的是,它仍然没有出现。当我运行程序时,控制台会按预期出现,但图形/渲染窗口没有 - 而是显示文本“按任意键继续”。打印在控制台上,就好像程序已经运行完毕一样。按下某个键会导致程序退出,返回值为 0。
该程序使用 Codelite 用 C++ 编写,并使用 g++ 编译。我目前正在使用 Windows 8 Professional 平板电脑/上网本,虽然在我可以访问另一台计算机之前无法对其进行测试,但它之前运行良好,我没有理由相信它已经停止运行所以在当前环境之外。有什么建议么?
[更新]:尝试在另一台 PC 上运行它,Windows 7,并得到一个新的错误,关于无法在 libstdc++-6.dll 中找到过程入口点 __gxx_personality_v0。整个代码太大而无法发布,但我认为这不是问题,因为它似乎甚至没有进入 main()。
#include <iostream>
#include <string>
#include <cstdio>
#include <cassert>
#include "sfml.hpp"
#include "angelscript.hpp"
#include "MapGenerator.hpp"
#include "TestState.hpp"
#include "std.hpp"
sf::RenderWindow* initialize();
void TestAngelScript();
void MessageCallback(const asSMessageInfo *msg, void *param);
int main()
{
std::cout << "Made it into main!!!" << std::endl;
TestAngelScript();
std::cout << "Initializing" << std::endl;
sf::RenderWindow* App = initialize();
TextureHandler::Initialize();
FontHandler::Initialize();
SoundHandler::Initialize();
MusicHandler::Initialize();
InputHandler::Initialize(App);
StateEngine engine;
IState* state = new TestState(App);
engine.AddState(state);
sf::Clock clock;
while (App->isOpen())
{
sf::Event Event;
while (App->pollEvent(Event))
{
// Window closed
if (Event.type == sf::Event::Closed)
App->close();
// Escape key pressed
if ((Event.type == sf::Event::KeyPressed) && (Event.key.code == sf::Keyboard::Escape))
App->close();
}
// Get elapsed time
float ElapsedTime = clock.restart().asSeconds();
engine.Update(ElapsedTime);
App->clear();
engine.Draw(App);
App->display();
}
return EXIT_SUCCESS;
}
sf::RenderWindow* initialize()
{
return new sf::RenderWindow(sf::VideoMode(800, 600, 32), "SFML Graphics");
}
// Print the script string to the standard output stream
void print(std::string &msg)
{
printf("%s", msg.c_str());
}
void TestAngelScript()
{
// Create the script engine
asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
// Set the message callback to receive information on errors in human readable form.
int r = engine->SetMessageCallback(asFUNCTION(MessageCallback), 0, asCALL_CDECL); assert( r >= 0 );
// AngelScript doesn't have a built-in string type, as there is no definite standard
// string type for C++ applications. Every developer is free to register it's own string type.
// The SDK do however provide a standard add-on for registering a string type, so it's not
// necessary to implement the registration yourself if you don't want to.
RegisterStdString(engine);
// Register the function that we want the scripts to call
r = engine->RegisterGlobalFunction("void print(const string &in)", asFUNCTION(print), asCALL_CDECL); assert( r >= 0 );
// The CScriptBuilder helper is an add-on that loads the file,
// performs a pre-processing pass if necessary, and then tells
// the engine to build a script module.
CScriptBuilder builder;
r = builder.StartNewModule(engine, "MyModule");
if( r < 0 )
{
// If the code fails here it is usually because there
// is no more memory to allocate the module
printf("Unrecoverable error while starting a new module.\n");
return;
}
r = builder.AddSectionFromFile("assets\\scripts\\test.as");
if( r < 0 )
{
// The builder wasn't able to load the file. Maybe the file
// has been removed, or the wrong name was given, or some
// preprocessing commands are incorrectly written.
printf("Please correct the errors in the script and try again.\n");
return;
}
r = builder.BuildModule();
if( r < 0 )
{
// An error occurred. Instruct the script writer to fix the
// compilation errors that were listed in the output stream.
printf("Please correct the errors in the script and try again.\n");
return;
}
// Find the function that is to be called.
asIScriptModule *mod = engine->GetModule("MyModule");
asIScriptFunction *func = mod->GetFunctionByDecl("void main()");
if( func == 0 )
{
// The function couldn't be found. Instruct the script writer
// to include the expected function in the script.
printf("The script must have the function 'void main()'. Please add it and try again.\n");
return;
}
// Create our context, prepare it, and then execute
asIScriptContext *ctx = engine->CreateContext();
ctx->Prepare(func);
r = ctx->Execute();
if( r != asEXECUTION_FINISHED )
{
// The execution didn't complete as expected. Determine what happened.
if( r == asEXECUTION_EXCEPTION )
{
// An exception occurred, let the script writer know what happened so it can be corrected.
printf("An exception '%s' occurred. Please correct the code and try again.\n", ctx->GetExceptionString());
}
}
// Clean up
ctx->Release();
engine->Release();
}
// Implement a simple message callback function
void MessageCallback(const asSMessageInfo *msg, void *param)
{
const char *type = "ERR ";
if( msg->type == asMSGTYPE_WARNING )
type = "WARN";
else if( msg->type == asMSGTYPE_INFORMATION )
type = "INFO";
printf("%s (%d, %d) : %s : %s\n", msg->section, msg->row, msg->col, type, msg->message);
}
没有任何东西输出到控制台,保存执行后输入的提示。程序返回 0。
在 IDE 之外运行程序会导致一些关于缺少 DLL 的错误(libstdc++-6.dll 和 libgcc_s_sjlj_1.dll)一旦提供了这些错误,我就会收到关于缺少过程入口点的错误……尽管在上网本上它会抱怨SFML 音频 dll 中缺少大约相同的点......