SFML窗口不显示

时间:2013-01-02 04:40:59

标签: c++ sfml

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

2 个答案:

答案 0 :(得分:3)

我知道这是一个老问题,但万一你还在努力修复它。

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

你需要在app之外声明你的app指针,如

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);

初始化函数应以sf::RenderWindow*作为参数。

答案 1 :(得分:0)

关于未出现的sfml窗口:当您的窗口超出屏幕分辨率时,这是一个已知问题。 减小渲染窗口的高度和/或宽度通常可以解决问题。您也可以使用全屏模式。