Недавно я работал с SFML над созданием небольшой игры на стороне — вплоть до сегодняшнего вечера все было на удивление быстро и просто. Я нахожусь вдали от своей обычной рабочей станции и делаю небольшую уборку на планшете / нетбуке с Windows 8, и окно игры больше не появляется. Я могу запустить программу, и она мгновенно завершается и просит меня нажать любую клавишу для выхода в консоли. Я провел некоторое исследование и понял, что версия SFML, которую я использовал, не поддерживает видеокарты ATI, поэтому я обновил программу до версии 2.0 (на данный момент это просто фреймворк, поэтому обновление заняло всего пару часов, а Я подумал, что это не повредит, даже если это не все исправит).
К сожалению, до сих пор не появляется. Когда я запускаю программу, появляется консоль, как и должно быть, но окно графики/рендеринга не появляется - вместо этого текст «Нажмите любую клавишу для продолжения». выводится на консоль, как будто программа уже завершила работу. Нажатие клавиши приводит к завершению программы с возвращаемым значением 0.
Программа написана на C++ с помощью Codelite и скомпилирована с помощью g++. В данный момент я работаю с планшета/нетбука с Windows 8 Professional, и хотя я не могу протестировать его, пока не получу доступ к другому компьютеру, раньше он работал нормально, и у меня нет причин полагать, что он перестал работать. так вне текущей среды. Какие-либо предложения?
[ОБНОВЛЕНИЕ]: попытался запустить его на другом ПК, Windows 7, и получил новую ошибку о невозможности найти точку входа в процедуру __gxx_personality_v0 в libstdc++-6.dll. Код в целом слишком велик для публикации, но я не думаю, что это проблема, так как он даже не попадает в 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). Как только они были предоставлены, я получаю сообщение об ошибке об отсутствующей точке входа в процедуру... хотя на нетбуке она жалуется примерно такая же точка отсутствует в аудио dll SFML....