Ptr<Mesh> Mesh::CreateMeshFromFile(const String& filePath) { auto exceptionManager = ExceptionManager::GetInstance(); AssimpLoader loader; Ptr<Mesh> mesh = loader.Load(filePath); if (mesh == nullptr) { Ptr<Exception> exception = Ptr<Exception>::New((String)"加载模型文件" + filePath + "失败。原因是:\n" + exceptionManager->GetException()->GetInfo()); exceptionManager->PushException(exception); return nullptr; } return mesh; }
void CBCGPRecurrence::DoException (const COleDateTime& dtDate, const CBCGPAppointmentPropertyList& props, BOOL bDeleted) { ASSERT_VALID (m_pAppointment); CBCGPAppointmentPropertyList srcProps; m_pAppointment->GetProperties (srcProps); if (!bDeleted) { ASSERT (srcProps.GetCount () == props.GetCount ()); } CBCGPRecurrenceBaseRule* pRule = GetRule (); ASSERT_VALID (pRule); COleDateTime dtStart; COleDateTime dtFinish; CBCGPAppointmentPropertyList propsEcp; XBCGPRecurrenceException* pEcp = GetException (dtDate); if (!bDeleted) { CBCGPAppointmentProperty* pProp = NULL; pProp = (CBCGPAppointmentProperty*)props.Get (BCGP_APPOINTMENT_PROPERTY_DATE_START); dtStart = *pProp; pProp = (CBCGPAppointmentProperty*)props.Get (BCGP_APPOINTMENT_PROPERTY_DATE_FINISH); dtFinish = *pProp; COleDateTime dtStartNeed (dtDate + pRule->GetTimeStart ()); COleDateTime dtFinishNeed (dtDate + pRule->GetTimeFinish ()); BOOL bTimeChanged = dtStart != dtStartNeed || dtFinish != dtFinishNeed; if (pEcp != NULL) { bTimeChanged |= pEcp->m_Properties.PropertyExists (BCGP_APPOINTMENT_PROPERTY_DATE_START) || pEcp->m_Properties.PropertyExists (BCGP_APPOINTMENT_PROPERTY_DATE_FINISH); if (!bDeleted) { POSITION pos = pEcp->m_Properties.GetStart (); DWORD ID = 0; CBCGPAppointmentBaseProperty* pProp = NULL; while (pos != NULL) { pEcp->m_Properties.GetNext (pos, ID, pProp); if (ID == BCGP_APPOINTMENT_PROPERTY_DATE_START || ID == BCGP_APPOINTMENT_PROPERTY_DATE_FINISH) { continue; } *(srcProps[ID]) = *pProp; } } } POSITION pos = srcProps.GetStart (); DWORD ID = 0; CBCGPAppointmentBaseProperty* pSrcProp = NULL; while (pos != NULL) { srcProps.GetNext (pos, ID, pSrcProp); if (!bTimeChanged && (ID == BCGP_APPOINTMENT_PROPERTY_DATE_START || ID == BCGP_APPOINTMENT_PROPERTY_DATE_FINISH)) { continue; } const CBCGPAppointmentBaseProperty* pDstProp = props.Get (ID); BOOL bEqual = TRUE; if (pDstProp == NULL) { continue; } else if (pSrcProp != NULL) { bEqual = *pSrcProp == *pDstProp; } if (!bEqual || (ID == BCGP_APPOINTMENT_PROPERTY_DATE_START || ID == BCGP_APPOINTMENT_PROPERTY_DATE_FINISH)) { CBCGPAppointmentBaseProperty* pNewProp = (CBCGPAppointmentBaseProperty*)(pDstProp->GetRuntimeClass ()->CreateObject ()); *pNewProp = *pDstProp; propsEcp[ID] = pNewProp; } } } if (bDeleted || propsEcp.GetCount () > 0) { if (pEcp == NULL) { pEcp = new XBCGPRecurrenceException; } if (!bDeleted) { pEcp->m_dtStart = dtStart; pEcp->m_dtFinish = dtFinish; POSITION pos = propsEcp.GetStart (); DWORD ID = 0; CBCGPAppointmentBaseProperty* pProp = NULL; while (pos != NULL) { propsEcp.GetNext (pos, ID, pProp); ASSERT_VALID (pProp); if (!pEcp->m_Properties.PropertyExists (ID)) { CBCGPAppointmentBaseProperty* pNewProp = (CBCGPAppointmentBaseProperty*)(pProp->GetRuntimeClass ()->CreateObject ()); *pNewProp = *pProp; pEcp->m_Properties[ID] = pNewProp; } else { *(pEcp->m_Properties[ID]) = *pProp; } } } else { pEcp->m_Deleted = bDeleted; pEcp->m_Properties.RemoveAll (); } m_Exceptions[dtDate] = pEcp; } }
result_t JSHandler::invoke(object_base *v, obj_ptr<Handler_base> &retVal, exlib::AsyncEvent *ac) { if (ac) return CHECK_ERROR(CALL_E_NOASYNC); v8::Local<v8::Object> o = v->wrap(); obj_ptr<Message_base> msg = Message_base::getInstance(v); v8::Local<v8::Value> a = v8::Local<v8::Value>::New(isolate, o); v8::Local<v8::Value> hdlr = v8::Local<v8::Value>::New(isolate, m_handler); result_t hr; bool bResult = false; while (true) { if (hdlr->IsFunction()) { v8::Local<v8::Function> func = v8::Local<v8::Function>::Cast(hdlr); obj_ptr<List_base> params; std::vector<v8::Local<v8::Value> > argv; v8::Local<v8::Value> *pargv; int32_t len = 0, i; if (msg != NULL) { msg->get_params(params); params->get_length(len); } if (len > 0) { argv.resize(len + 1); argv[0] = a; for (i = 0; i < len; i++) { Variant v; params->_indexed_getter(i, v); argv[i + 1] = v; } pargv = argv.data(); } else pargv = &a; if (!isolate->GetCallingContext().IsEmpty()) { hdlr = func->Call(v8::Undefined(isolate), len + 1, pargv); if (hdlr.IsEmpty()) return CHECK_ERROR(CALL_E_JAVASCRIPT); } else { v8::TryCatch try_catch; hdlr = func->Call(v8::Undefined(isolate), len + 1, pargv); if (try_catch.HasCaught()) return CHECK_ERROR(Runtime::setError(GetException(try_catch, 0))); } if (IsEmpty (hdlr)) return CALL_RETURN_NULL; bResult = true; } else if (hdlr->IsObject()) { if ((retVal = Handler_base::getInstance(hdlr)) != NULL) return 0; if (msg == NULL) return CHECK_ERROR(CALL_E_BADVARTYPE); if (bResult) { msg->set_result(hdlr); return CALL_RETURN_NULL; } std::string method; hr = msgMethod(msg, method); if (hr < 0) return hr; hdlr = v8::Local<v8::Object>::Cast(hdlr)->Get( v8::String::NewFromUtf8(isolate, method.c_str(), v8::String::kNormalString, (int) method.length())); if (IsEmpty (hdlr)) return CHECK_ERROR(Runtime::setError("method \"" + method + "\" not found.")); bResult = false; } else if (bResult && msg) { msg->set_result(hdlr); return CALL_RETURN_NULL; } else return CHECK_ERROR(CALL_E_INTERNAL); } return 0; }
/* Callback for the exception handler * Parameters: * e - The exception information * Returns: * EXCEPTION_EXECUTE_HANDLER to terminate the process * Side Effects: * unrealircd.PID.core is created * If not running in service mode, a message box is displayed, * else output is written to service.log */ LONG __stdcall ExceptionFilter(EXCEPTION_POINTERS *e) { MEMORYSTATUS memStats; char file[512], text[1024], minidumpf[512]; FILE *fd; time_t timet = time(NULL); #ifndef NOMINIDUMP HANDLE hDump; HMODULE hDll = NULL; #endif sprintf(file, "unrealircd.%d.core", getpid()); fd = fopen(file, "w"); GlobalMemoryStatus(&memStats); fprintf(fd, "Generated at %s\n%s (%d.%d.%d)\n%s[%s%s%s] (%s)\n" "-----------------\nMemory Information:\n" "\tPhysical: (Available:%ldMB/Total:%ldMB)\n" "\tVirtual: (Available:%ldMB/Total:%ldMB)\n" "-----------------\nException:\n\t%s\n-----------------\n" "Backup Buffer:\n\t%s\n-----------------\nRegisters:\n" "%s-----------------\nStack Trace:\n%s", asctime(gmtime(&timet)), OSName, VerInfo.dwMajorVersion, VerInfo.dwMinorVersion, VerInfo.dwBuildNumber, IRCDTOTALVERSION, serveropts, extraflags ? extraflags : "", tainted ? "3" : "", buildid, memStats.dwAvailPhys/1048576, memStats.dwTotalPhys/1048576, memStats.dwAvailVirtual/1048576, memStats.dwTotalVirtual/1048576, GetException(e->ExceptionRecord->ExceptionCode), backupbuf, GetRegisters(e->ContextRecord), StackTrace(e)); sprintf(text, "UnrealIRCd has encountered a fatal error. Debugging information has been dumped to %s.", file); fclose(fd); #ifndef NOMINIDUMP hDll = LoadLibrary("DBGHELP.DLL"); if (hDll) { MINIDUMPWRITEDUMP pDump = (MINIDUMPWRITEDUMP)GetProcAddress(hDll, "MiniDumpWriteDump"); if (pDump) { MINIDUMP_EXCEPTION_INFORMATION ExInfo; sprintf(minidumpf, "unrealircd.%d.mdmp", getpid()); hDump = CreateFile(minidumpf, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (hDump != INVALID_HANDLE_VALUE) { ExInfo.ThreadId = GetCurrentThreadId(); ExInfo.ExceptionPointers = e; ExInfo.ClientPointers = 0; if (pDump(GetCurrentProcess(), GetCurrentProcessId(), hDump, MiniDumpNormal, &ExInfo, NULL, NULL)) { sprintf(text, "UnrealIRCd has encountered a fatal error. Debugging information has been dumped to %s and %s.", file, minidumpf); } CloseHandle(hDump); } sprintf(minidumpf, "unrealircd.%d.full.mdmp", getpid()); hDump = CreateFile(minidumpf, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (hDump != INVALID_HANDLE_VALUE) { ExInfo.ThreadId = GetCurrentThreadId(); ExInfo.ExceptionPointers = e; ExInfo.ClientPointers = 0; CloseHandle(hDump); } } } #endif if (!IsService) { MessageBox(NULL, text, "Fatal Error", MB_OK); StartCrashReporter(); } else { FILE *fd = fopen("service.log", "a"); if (fd) { fprintf(fd, "UnrealIRCd has encountered a fatal error. Debugging information " "has been dumped to unrealircd.%d.core, please file a bug and upload " "this file to http://bugs.unrealircd.org/.", getpid()); fclose(fd); } } CleanUp(); return EXCEPTION_EXECUTE_HANDLER; }
void ReportException(TryCatch &try_catch, result_t hr) { if (try_catch.HasCaught() || hr < 0) asyncLog(console_base::_ERROR, GetException(try_catch, hr)); }
result_t JSHandler::invoke(object_base *v, obj_ptr<Handler_base> &retVal, AsyncEvent *ac) { if (ac) return CHECK_ERROR(CALL_E_NOASYNC); v8::Local<v8::Object> o = v->wrap(); Isolate* isolate = holder(); obj_ptr<Message_base> msg = Message_base::getInstance(v); v8::Local<v8::Value> a = v8::Local<v8::Value>::New(isolate->m_isolate, o); v8::Local<v8::Value> hdlr = GetPrivate("handler"); while (true) { v8::Local<v8::Function> func = v8::Local<v8::Function>::Cast(hdlr); obj_ptr<List_base> params; std::vector<v8::Local<v8::Value> > argv; v8::Local<v8::Value> *pargv; int32_t len = 0, i; if (msg != NULL) { msg->get_params(params); params->get_length(len); } if (len > 0) { argv.resize(len + 1); argv[0] = a; for (i = 0; i < len; i++) { Variant v; params->_indexed_getter(i, v); argv[i + 1] = v; } pargv = argv.data(); } else pargv = &a; { TryCatch try_catch; hdlr = func->Call(v8::Undefined(isolate->m_isolate), len + 1, pargv); if (try_catch.HasCaught()) { v8::Local<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace( isolate->m_isolate, 1, v8::StackTrace::kScriptId); if (stackTrace->GetFrameCount() > 0) { try_catch.ReThrow(); return CALL_E_JAVASCRIPT; } else return CHECK_ERROR(Runtime::setError(GetException(try_catch, 0))); } } if (IsEmpty (hdlr)) return CALL_RETURN_NULL; if (!hdlr->IsFunction()) { if (hdlr->IsObject()) return JSHandler::New(hdlr, retVal); msg->set_result(hdlr); return CALL_RETURN_NULL; } } return 0; }
static result_t run(int32_t loglevel) { if (!s_root) return 0; if (s_now != s_root) return CHECK_ERROR(CALL_E_INVALID_CALL); s_now = NULL; QuickArray<obj_ptr<_case> > stack; QuickArray<std::string> names; QuickArray<std::string> msgs; int i, j; int32_t oldlevel = 0; int32_t cnt = 0, errcnt = 0; char buf[128]; date_t da1, da2; console_base::get_loglevel(oldlevel); console_base::set_loglevel(loglevel); stack.append(s_root); da1.now(); while (stack.size()) { _case *p = stack[stack.size() - 1]; _case *p1, *p2; if (p->m_pos == 0) { for (i = 0; i < (int) p->m_hooks[HOOK_BEFORE].size(); i++) if (v8::Local<v8::Function>::New(isolate, p->m_hooks[HOOK_BEFORE][i])->Call(v8::Undefined(isolate), 0, NULL).IsEmpty()) { console_base::set_loglevel(oldlevel); clear(); return 0; } } if (p->m_pos < (int) p->m_subs.size()) { std::string str(stack.size() * 2, ' '); p1 = p->m_subs[p->m_pos++]; if (p1->m_block.IsEmpty()) { console_base::set_loglevel(oldlevel); if (stack.size() == 1) asyncLog(console_base::_INFO, ""); str.append(logger::highLight()); str.append(p1->m_name); str.append(COLOR_RESET); asyncLog(console_base::_INFO, str); console_base::set_loglevel(loglevel); stack.append(p1); continue; } for (j = 0; j < (int) stack.size(); j++) { p2 = stack[j]; for (i = 0; i < (int) p2->m_hooks[HOOK_BEFORECASE].size(); i++) if (v8::Local<v8::Function>::New(isolate, p2->m_hooks[HOOK_BEFORECASE][i])->Call(v8::Undefined(isolate), 0, NULL).IsEmpty()) { console_base::set_loglevel(oldlevel); clear(); return 0; } } cnt++; { v8::TryCatch try_catch; date_t d1, d2; d1.now(); v8::Local<v8::Function>::New(isolate, p1->m_block)->Call(v8::Undefined(isolate), 0, NULL); d2.now(); if (try_catch.HasCaught()) { sprintf(buf, "%d) ", ++errcnt); p1->m_error = true; if (loglevel > console_base::_ERROR) ReportException(try_catch, 0); else if (loglevel == console_base::_ERROR) { std::string str1(buf); for (i = 1; i < (int)stack.size(); i ++) { str1.append(stack[i]->m_name); str1.append(" ", 1); } str1.append(p1->m_name); names.append(logger::highLight() + str1 + COLOR_RESET); msgs.append(GetException(try_catch, 0)); } str.append(buf); str.append(p1->m_name); } else { double n = d2.diff(d1); str.append(logger::notice() + "\xe2\x88\x9a " COLOR_RESET); str.append(p1->m_name); if (n > s_slow / 2) { sprintf(buf, " (%dms) ", (int) n); if (n > s_slow) str.append(logger::error()); else str.append(logger::warn()); str.append(buf); str.append(COLOR_RESET); } } } console_base::set_loglevel(oldlevel); asyncLog( p1->m_error ? console_base::_ERROR : console_base::_INFO, str); console_base::set_loglevel(loglevel); for (j = (int) stack.size() - 1; j >= 0; j--) { p2 = stack[j]; for (i = (int) p2->m_hooks[HOOK_AFTERCASE].size() - 1; i >= 0; i--) if (v8::Local<v8::Function>::New(isolate, p2->m_hooks[HOOK_AFTERCASE][i])->Call(v8::Undefined(isolate), 0, NULL).IsEmpty()) { console_base::set_loglevel(oldlevel); clear(); return 0; } } } if (p->m_pos == (int)p->m_subs.size()) { for (i = (int) p->m_hooks[HOOK_AFTER].size() - 1; i >= 0; i--) if (v8::Local<v8::Function>::New(isolate, p->m_hooks[HOOK_AFTER][i])->Call(v8::Undefined(isolate), 0, NULL).IsEmpty()) { console_base::set_loglevel(oldlevel); clear(); return 0; } stack.pop(); } } console_base::set_loglevel(oldlevel); asyncLog(console_base::_INFO, ""); if (errcnt == 0) { da2.now(); sprintf(buf, (logger::notice() + " \xe2\x88\x9a %d tests completed" COLOR_RESET " (%dms)").c_str(), cnt, (int) da2.diff(da1)); asyncLog(console_base::_INFO, buf); } else { sprintf(buf, (logger::error() + " × %d of %d tests failed" COLOR_RESET).c_str(), errcnt, cnt); asyncLog(console_base::_ERROR, buf); } asyncLog(console_base::_INFO, ""); for (i = 0; i < (int) msgs.size(); i++) { asyncLog(console_base::_INFO, names[i]); asyncLog(console_base::_ERROR, msgs[i]); } clear(); return 0; }
void ReportException(TryCatch &try_catch, result_t hr) { if (try_catch.HasCaught() || hr < 0) errorLog(GetException(try_catch, hr)); }