bool TitleScene::init() { controller = g_AppSettings.openController(1); if(!ConfigManager::music_lastIniFile.isEmpty()) { ConfigManager::music_lastIniFile.clear(); ConfigManager::loadDefaultMusics(); } if(!ConfigManager::sound_lastIniFile.isEmpty()) { ConfigManager::sound_lastIniFile.clear(); ConfigManager::loadDefaultSounds(); ConfigManager::buildSoundIndex(); } luaEngine.setLuaScriptPath(ConfigManager::PathScript()); luaEngine.setCoreFile(":/script/maincore_title.lua"); luaEngine.setUserFile(ConfigManager::setup_TitleScreen.luaFile); luaEngine.setErrorReporterFunc([this](const QString & errorMessage, const QString & stacktrace) { qWarning() << "Lua-Error: "; qWarning() << "Error Message: " << errorMessage; qWarning() << "Stacktrace: \n" << stacktrace; PGE_MsgBox msgBox(this, QString("A lua error has been thrown: \n") + errorMessage + "\n\nMore details in the log!", PGE_MsgBox::msg_error); msgBox.exec(); }); D_pLogDebug("Attempt to init..."); luaEngine.init(); D_pLogDebug("done!"); return true; }
static std::string getStacktrace() { #if defined(_WIN32) //StackTracer tracer; //tracer.runStackTracerForAllThreads(); //return tracer.theOutput(); //dbg::stack s; //std::stringstream out; //std::copy(s.begin(), s.end(), std::ostream_iterator<dbg::stack_frame>(out, "\n")); std::string stack; GetStackWalk(stack); return stack; #elif (defined(__linux__) && !defined(__ANDROID__) || defined(__APPLE__)) void *array[400]; int size; char **strings; D_pLogDebug("Requesting backtrace..."); size = backtrace(array, 400); D_pLogDebug("Converting..."); strings = backtrace_symbols(array, size); D_pLogDebug("Initializing std::string..."); std::string bkTrace(""); D_pLogDebug("Filling std::string..."); for(int j = 0; j < size; j++) { bkTrace.append(strings[j]); bkTrace.push_back('\n'); } D_pLogDebug("DONE!"); return bkTrace; #else return std::string("<Stack trace not supported for this platform!>"); #endif }
FIBITMAP *GraphicsHelps::loadImage(std::string file, bool convertTo32bit) { #ifdef DEBUG_BUILD ElapsedTimer loadingTime; ElapsedTimer fReadTime; ElapsedTimer imgConvTime; loadingTime.start(); fReadTime.start(); #endif #if defined(__unix__) || defined(__APPLE__) || defined(_WIN32) FileMapper fileMap; if(!fileMap.open_file(file.c_str())) return NULL; FIMEMORY *imgMEM = FreeImage_OpenMemory(reinterpret_cast<unsigned char *>(fileMap.data()), static_cast<unsigned int>(fileMap.size())); FREE_IMAGE_FORMAT formato = FreeImage_GetFileTypeFromMemory(imgMEM); if(formato == FIF_UNKNOWN) return NULL; FIBITMAP *img = FreeImage_LoadFromMemory(formato, imgMEM, 0); FreeImage_CloseMemory(imgMEM); fileMap.close_file(); if(!img) return NULL; #else FREE_IMAGE_FORMAT formato = FreeImage_GetFileType(file.toUtf8().data(), 0); if(formato == FIF_UNKNOWN) return NULL; FIBITMAP *img = FreeImage_Load(formato, file.toUtf8().data()); if(!img) return NULL; #endif #ifdef DEBUG_BUILD long long fReadTimeElapsed = static_cast<long long>(fReadTime.elapsed()); long long imgConvertElapsed = 0; #endif if(convertTo32bit) { #ifdef DEBUG_BUILD imgConvTime.start(); #endif FIBITMAP *temp; temp = FreeImage_ConvertTo32Bits(img); if(!temp) return NULL; FreeImage_Unload(img); img = temp; #ifdef DEBUG_BUILD imgConvertElapsed = static_cast<long long>(imgConvTime.elapsed()); #endif } #ifdef DEBUG_BUILD D_pLogDebug("File read of texture %s passed in %d milliseconds", file.c_str(), static_cast<int>(fReadTimeElapsed)); D_pLogDebug("Conv to 32-bit of %s passed in %d milliseconds", file.c_str(), static_cast<int>(imgConvertElapsed)); D_pLogDebug("Total Loading of image %s passed in %d milliseconds", file.c_str(), static_cast<int>(loadingTime.elapsed())); #endif return img; }
static void handle_signal(int signal, siginfo_t *siginfo, void * /*context*/) { #ifdef _WIN32 //Unsupported signals by Windows (void)siginfo; #endif // Find out which signal we're handling switch(signal) { #ifndef _WIN32 //Unsupported signals by Windows case SIGHUP: pLogWarning("Terminal was closed"); abortEngine(signal); case SIGQUIT: pLogWarning("<Quit command>"); abortEngine(signal); case SIGKILL: pLogFatal("<killed>"); abortEngine(signal); case SIGALRM: { pLogFatal("<alarm() time out!>"); msgBox( //% "Time out!" qtTrId("CRASH_TIMEOUT_TITLE"), //% "Engine has abourted because alarm() time out!" qtTrId("CRASH_TIMEOUT_MSG")); abortEngine(signal); } case SIGBUS: { std::string stack = getStacktrace(); if(siginfo) { switch(siginfo->si_code) { case BUS_ADRALN: pLogFatal("<Physical memory address error: wrong address alignment>\n" STACK_FORMAT, stack.c_str(), g_messageToUser); break; case BUS_ADRERR: pLogFatal("<Physical memory address error: physical address is not exists>\n" STACK_FORMAT, stack.c_str(), g_messageToUser); break; case BUS_OBJERR: pLogFatal("<Physical memory address error: object specific hardware error>\n" STACK_FORMAT, stack.c_str(), g_messageToUser); break; default: pLogFatal("<Physical memory address error>\n" STACK_FORMAT, stack.c_str(), g_messageToUser); } } else { pLogFatal("<Physical memory address error>\n" STACK_FORMAT, stack.c_str(), g_messageToUser); } msgBox( //% "Physical memory address error!" qtTrId("CRASH_BUS_TITLE"), //% "Engine has crashed because a physical memory address error" qtTrId("CRASH_BUS_MSG")); abortEngine(signal); } case SIGURG: case SIGUSR1: case SIGUSR2: break; case SIGILL: { std::string stack = getStacktrace(); pLogFatal("<Wrong CPU Instruction>\n" STACK_FORMAT, stack.c_str(), g_messageToUser); msgBox( //% "Wrong CPU Instruction!" qtTrId("CRASH_ILL_TITLE"), //% "Engine has crashed because a wrong CPU instruction" qtTrId("CRASH_ILL_MSG")); abortEngine(signal); } #endif case SIGFPE: { std::string stack = getStacktrace(); #ifndef _WIN32 //Unsupported signals by Windows if(siginfo) { switch(siginfo->si_code) { case FPE_INTDIV: pLogFatal("<wrong arithmetical operation: division of integer number by zero>\n" STACK_FORMAT, stack.c_str(), g_messageToUser); break; case FPE_FLTDIV: pLogFatal("<wrong arithmetical operation: division of floating point number by zero>\n" STACK_FORMAT, stack.c_str(), g_messageToUser); break; case FPE_INTOVF: pLogFatal("<wrong arithmetical operation: integer number max bits size overflot>\n" STACK_FORMAT, stack.c_str(), g_messageToUser); break; case FPE_FLTOVF: pLogFatal("<wrong arithmetical operation: floating point number max bits size overflot>\n" STACK_FORMAT, stack.c_str(), g_messageToUser); break; default: pLogFatal("<wrong arithmetical operation>\n" STACK_FORMAT, stack.c_str(), g_messageToUser); } } else #endif { pLogFatal("<wrong arithmetical operation>\n" STACK_FORMAT, stack.c_str(), g_messageToUser); } msgBox( //% "Wrong arithmetical operation" qtTrId("CRASH_FPE_TITLE"), //% "Engine has crashed because of a wrong arithmetical operation!" qtTrId("CRASH_FPE_MSG")); abortEngine(signal); } case SIGABRT: { std::string stack = getStacktrace(); pLogFatal("<Aborted!>\n" STACK_FORMAT, stack.c_str(), g_messageToUser); msgBox( //% "Aborted" qtTrId("CRASH_ABORT_TITLE"), //% "Engine has been aborted because critical error was occouped." qtTrId("CRASH_ABORT_TITLE.")); abortEngine(signal); } case SIGSEGV: { D_pLogDebug("\n===========================================================\n" "Attempt to take a backtrace..." "(if log ends before \"DONE\" will be shown, seems also trouble in the backtracing function too...)"); std::string stack = getStacktrace(); #ifndef _WIN32 //Unsupported signals by Windows if(siginfo) { switch(siginfo->si_code) { case SEGV_MAPERR: pLogFatal("<Segmentation fault crash!: Address is not pointing to object!!!>\n" STACK_FORMAT, stack.c_str(), g_messageToUser); break; case SEGV_ACCERR: pLogFatal("<Segmentation fault crash!: Wrong access rights for address!!!>\n" STACK_FORMAT, stack.c_str(), g_messageToUser); break; default: pLogFatal("<Segmentation fault crash!>\n" STACK_FORMAT, stack.c_str(), g_messageToUser); break; } } else #endif { pLogFatal("<Segmentation fault crash!>\n" STACK_FORMAT, stack.c_str(), g_messageToUser); } msgBox( //% "Segmentation fault" qtTrId("CRASH_SIGSEGV_TITLE"), /*% "Engine has crashed because of a Segmentation fault.\n" "Run debugging with a built in debug mode application\n" "and retry your recent actions to get more detailed information." */ qtTrId("CRASH_SIGSEGV_MSG.")); abortEngine(signal); } case SIGINT: { pLogFatal("<Interrupted!>"); msgBox( //% "Interrupt" qtTrId("CRASH_INT_TITLE"), //% "Engine has been interrupted" qtTrId("CRASH_INT_MSG")); abortEngine(signal); } default: return; } }
void PGE_TextInputBox::processBox(double tickTime) { PGE_BoxBase::processBox(tickTime); bool wasExitKeyPress = m_keys.run_pressed || m_keys.alt_run_pressed || m_keys.start_pressed; if(wasExitKeyPress) { if(m_keys.start_pressed || m_keys.jump_pressed || m_keys.alt_jump_pressed) m_inputTextSrc = m_inputText; nextPage(); setFade(10, 0.0, 0.05); SDL_StopTextInput(); return; } m_blinkTimeout -= tickTime; if(m_blinkTimeout < 0.0) { m_blinkShown = !m_blinkShown; m_blinkTimeout += (tickTime < 250.0) ? 250.0 : tickTime + 250.0; } SDL_StartTextInput(); SDL_Event event; while(SDL_PollEvent(&event)) { PGE_Window::processEvents(event); switch(event.type) { case SDL_QUIT: nextPage(); setFade(10, 0.0, 0.05); SDL_StopTextInput(); break; case SDL_KEYDOWN: // If pressed key { switch(event.key.keysym.sym) { // Check which case SDLK_ESCAPE: // ESC case SDLK_RETURN:// Enter case SDLK_KP_ENTER: case SDLK_AC_BACK://Android "back" key { if(event.key.keysym.sym != SDLK_ESCAPE && event.key.keysym.sym != SDLK_AC_BACK) m_inputTextSrc = m_inputText; nextPage(); setFade(10, 0.0, 0.05); SDL_StopTextInput(); break; } case SDLK_BACKSPACE: { if(m_inputText.length() > 0) { FontManager::utf8_pop_back(m_inputText); updatePrintable(); } break; } default: break; } switch(event.key.keysym.scancode) { case SDL_SCANCODE_V: { if((event.key.keysym.mod & KMOD_CTRL) && (SDL_HasClipboardText() == SDL_TRUE)) { m_inputText.append(SDL_GetClipboardText()); std::remove(m_inputText.begin(), m_inputText.end(), '\r'); std::replace(m_inputText.begin(), m_inputText.end(), '\n', ' '); updatePrintable(); } break; } default: break; } break; } case SDL_TEXTINPUT: { D_pLogDebug("TEXT INPUT EVENT %s", event.text.text); m_inputText.append(event.text.text); updatePrintable(); } break; case SDL_TEXTEDITING: { D_pLogDebug("TEXT EDIT EVENT start %d, %s", event.edit.start, event.edit.text); m_inputText = event.edit.text; m_cursor = event.edit.start; m_selectionLength = event.edit.length; updatePrintable(); } break; // case SDL_MOUSEBUTTONDOWN: // switch(event.button.button) // { // case SDL_BUTTON_LEFT: // { // _page++; // setFade(10, 0.0f, 0.05f); // } // break; // } // break; default: break; } } }
void ConfigManager::buildSoundIndex() { int need_to_reserve = 0; int total_channels = 32; bool newBuild = main_sfx_index.empty(); #ifdef DEBUG_BUILD ElapsedTimer loadingTime; loadingTime.start(); #endif if(newBuild) { //build array table main_sfx_index.resize(static_cast<size_t>(main_sound.size()) - 1); for(unsigned long i = 1; i < main_sound.size(); i++) { obj_sound_index sound; if(main_sound.contains(i)) { obj_sound &snd = main_sound[i]; #if defined(__unix__) || defined(__APPLE__) || defined(_WIN32) FileMapper fileMap; if(fileMap.open_file(snd.absPath.c_str())) { sound.chunk = Mix_LoadWAV_RW(SDL_RWFromMem(fileMap.data(), static_cast<int>(fileMap.size())), 1); fileMap.close_file(); } #else sound.chunk = Mix_LoadWAV(snd.absPath.toUtf8().data()); #endif sound.path = snd.absPath; if(!sound.chunk) pLogWarning("Fail to load sound-%d: %s", i, Mix_GetError()); else need_to_reserve += (snd.channel >= 0 ? 1 : 0); sound.channel = snd.channel; } main_sfx_index[static_cast<size_t>(i) - 1] = sound; } } else { for(unsigned long i = 1; (i < main_sound.size()) && (i <= static_cast<unsigned long>(main_sfx_index.size())); i++) { if(main_sound.contains(i)) { obj_sound_index &sound = main_sfx_index[static_cast<size_t>(i) - 1]; obj_sound &snd = main_sound[i]; sound.setPath(snd.absPath); if(sound.need_reload) { #if defined(__unix__) || defined(__APPLE__) || defined(_WIN32) FileMapper fileMap; if(fileMap.open_file(snd.absPath.c_str())) { sound.chunk = Mix_LoadWAV_RW(SDL_RWFromMem(fileMap.data(), static_cast<int>(fileMap.size())), static_cast<int>(fileMap.size())); fileMap.close_file(); } #else sound.chunk = Mix_LoadWAV(snd.absPath.toUtf8().data()); #endif } if(!sound.chunk) pLogWarning("Fail to load sound-%d: %s", i, Mix_GetError()); else need_to_reserve += (snd.channel >= 0 ? 1 : 0); sound.channel = snd.channel; } } } if(need_to_reserve > 0) { total_channels = (total_channels + need_to_reserve + 32); total_channels = Mix_AllocateChannels(total_channels); } //Final channel definition (use reserved channels at end of channels set) //int set_channel = (total_channels-1); //for(int i=0; i < main_sfx_index.size(); i++) //{ // obj_sound_index &sound = main_sfx_index[i]; // if(sound.channel>=0) // { // sound.channel = set_channel--; // } //} if(need_to_reserve == total_channels) need_to_reserve = 0; //else // need_to_reserve=set_channel; #ifndef DEBUG_BUILD Mix_ReserveChannels(need_to_reserve) #endif #define RESERVE_CHANS_COMMAND Mix_ReserveChannels(need_to_reserve) D_pLogDebug("Loading of sounds passed in %d milliseconds", static_cast<int>(loadingTime.elapsed())); D_pLogDebug("Reserved audio channels: %d", RESERVE_CHANS_COMMAND); D_pLogDebug("SFX Index entries: %d", main_sfx_index.size()); #undef RESERVE_CHANS_COMMAND SDL_ClearError(); }