X-Git-Url: https://git.octo.it/?a=blobdiff_plain;ds=sidebyside;f=src%2Fsupertux%2Fconsole.cpp;h=7244191f47fd472426d024470334cf853e35591a;hb=c0b5cfa3eadebef8101f87cd593eb221bdef9280;hp=6b866b25df2d6fb32965c82b30d1dd791addefac;hpb=d041b64d9d853852bf66b5a194c5beaf7e6fe611;p=supertux.git diff --git a/src/supertux/console.cpp b/src/supertux/console.cpp index 6b866b25d..7244191f4 100644 --- a/src/supertux/console.cpp +++ b/src/supertux/console.cpp @@ -19,7 +19,8 @@ #include #include -#include "physfs/ifile_stream.hpp" +#include "physfs/buffered_ifile_stream.hpp" +#include "scripting/scripting.hpp" #include "scripting/squirrel_util.hpp" #include "supertux/gameconfig.hpp" #include "supertux/globals.hpp" @@ -122,6 +123,16 @@ Console::~Console() void Console::on_buffer_change(int line_count) { + if (!m_font) + { + // FIXME: This is an ugly workaround for a crash at startup. + // Console::current() becomes valid before the Console constructor + // is finished and loading Surfaces and Fonts wants to write text + // to the Console, with Fonts that aren't yet loaded, thus + // crashing + return; + } + // increase console height if necessary if (m_stayOpen > 0 && m_height < 64) { @@ -164,8 +175,9 @@ Console::ready_vm() try { std::string filename = "scripts/console.nut"; - IFileStream stream(filename); - scripting::compile_and_run(m_vm, stream, filename); + BufferedIFileStream* buffered_stream = new BufferedIFileStream(filename); + IFileStream* stream = buffered_stream->get_stream(); + scripting::compile_and_run(m_vm, *stream, filename); } catch(std::exception& e) { log_warning << "Couldn't load console.nut: " << e.what() << std::endl; } @@ -246,11 +258,11 @@ void Console::show_history(int offset_) { while ((offset_ > 0) && (m_history_position != m_history.end())) { - m_history_position++; + ++m_history_position; offset_--; } while ((offset_ < 0) && (m_history_position != m_history.begin())) { - m_history_position--; + --m_history_position; offset_++; } if (m_history_position == m_history.end()) { @@ -413,10 +425,9 @@ Console::parse(std::string s) // split line into list of args std::vector args; - size_t start = 0; size_t end = 0; while (1) { - start = s.find_first_not_of(" ,", end); + size_t start = s.find_first_not_of(" ,", end); end = s.find_first_of(" ,", start); if (start == s.npos) break; args.push_back(s.substr(start, end-start)); @@ -550,7 +561,7 @@ Console::draw(DrawingContext& context) } int skipLines = -m_offset; - for (std::list::iterator i = m_buffer.m_lines.begin(); i != m_buffer.m_lines.end(); i++) + for (std::list::iterator i = m_buffer.m_lines.begin(); i != m_buffer.m_lines.end(); ++i) { if (skipLines-- > 0) continue; lineNo++;