0

最近,我一直在与 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 中缺少大约相同的点......

4

2 回答 2

3

我知道这是一个老问题,但以防万一您仍在尝试解决它。

在我看来,您的渲染窗口的初始化函数很可能是问题所在。您正在返回一个指向局部变量的指针,这将起作用,但您不会得到您的窗口。

您需要在 main 之外声明您的应用程序指针,例如

sf::RenderWindow* App;
void initialize() { /* Initialize render window here. */ };

...

int main() ...

或者您可以选择更简单的解决方案,只需在主函数中创建窗口。

...
int main () {
...
sf::RenderWindow App(sf::VideoMode(800, 600), "my window");
...
}

请注意,如果它是在 main 中创建的,您仍然可以将它传递给您的函数

InputHandler::Initialize(&App);

您的初始化函数应将 asf::RenderWindow*作为参数。

于 2015-02-22T10:59:32.410 回答
0

关于不显示 sfml 窗口:这是一个已知问题,当您的窗口超过屏幕分辨率时会发生这种情况。减小渲染窗口的高度和/或宽度通常可以解决问题。您也可以改用全屏模式。

于 2013-04-26T18:16:23.897 回答