ErrorReport.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include "EditorDefs.h"
  9. #include "ErrorReport.h"
  10. // Editor
  11. #include "ErrorReportDialog.h"
  12. //////////////////////////////////////////////////////////////////////////
  13. QString CErrorRecord::GetErrorText() const
  14. {
  15. QString str = error.trimmed();
  16. const char* sModuleName = "";
  17. // Module name
  18. switch (module)
  19. {
  20. case VALIDATOR_MODULE_UNKNOWN:
  21. sModuleName = "";
  22. break;
  23. case VALIDATOR_MODULE_RENDERER:
  24. sModuleName = "Renderer";
  25. break;
  26. case VALIDATOR_MODULE_3DENGINE:
  27. sModuleName = "Engine";
  28. break;
  29. case VALIDATOR_MODULE_SYSTEM:
  30. sModuleName = "System";
  31. break;
  32. case VALIDATOR_MODULE_AUDIO:
  33. sModuleName = "Audio";
  34. break;
  35. case VALIDATOR_MODULE_MOVIE:
  36. sModuleName = "Movie";
  37. break;
  38. case VALIDATOR_MODULE_EDITOR:
  39. sModuleName = "Editor";
  40. break;
  41. case VALIDATOR_MODULE_NETWORK:
  42. sModuleName = "Network";
  43. break;
  44. case VALIDATOR_MODULE_PHYSICS:
  45. sModuleName = "Physics";
  46. break;
  47. case VALIDATOR_MODULE_FEATURETESTS:
  48. sModuleName = "FeatureTests";
  49. break;
  50. case VALIDATOR_MODULE_SHINE:
  51. sModuleName = "UI";
  52. break;
  53. }
  54. str = QStringLiteral("[%1]\t[%2]\t%3").arg(count, 2).arg(QString(sModuleName).leftJustified(6), error).trimmed();
  55. if (!file.isEmpty())
  56. {
  57. str += QString("\t") + file;
  58. }
  59. else
  60. {
  61. str += QString("\t ");
  62. }
  63. return str;
  64. }
  65. //////////////////////////////////////////////////////////////////////////
  66. // CError Report.
  67. //////////////////////////////////////////////////////////////////////////
  68. CErrorReport::CErrorReport()
  69. {
  70. m_errors.reserve(100);
  71. m_bImmediateMode = true;
  72. m_bShowErrors = true;
  73. m_pParticle = nullptr;
  74. }
  75. //////////////////////////////////////////////////////////////////////////
  76. void CErrorReport::ReportError(CErrorRecord& err)
  77. {
  78. static bool bNoRecurse = false;
  79. if (bNoRecurse)
  80. {
  81. return;
  82. }
  83. bNoRecurse = true;
  84. if (m_bImmediateMode)
  85. {
  86. if (err.module == VALIDATOR_MODULE_EDITOR && err.severity == static_cast<int>(VALIDATOR_ERROR))
  87. {
  88. Warning(err.error.toUtf8().data());
  89. }
  90. else
  91. {
  92. // Show dialog if first character of warning is !.
  93. if (!err.error.isEmpty() && err.error[0] == '!')
  94. {
  95. Warning(err.error.toUtf8().data());
  96. }
  97. else
  98. {
  99. m_errors.push_back(err);
  100. }
  101. }
  102. }
  103. else
  104. {
  105. m_errors.push_back(err);
  106. }
  107. bNoRecurse = false;
  108. }
  109. //////////////////////////////////////////////////////////////////////////
  110. void CErrorReport::Clear()
  111. {
  112. m_errors.clear();
  113. }
  114. //////////////////////////////////////////////////////////////////////////
  115. inline bool SortErrorsByModule(const CErrorRecord& e1, const CErrorRecord& e2)
  116. {
  117. if (e1.module == e2.module)
  118. {
  119. if (e1.error == e2.error)
  120. {
  121. return e1.file < e2.file;
  122. }
  123. else
  124. {
  125. return e1.error < e2.error;
  126. }
  127. }
  128. return e1.module < e2.module;
  129. }
  130. //////////////////////////////////////////////////////////////////////////
  131. void CErrorReport::Display()
  132. {
  133. if (m_errors.empty() || !m_bShowErrors)
  134. {
  135. SetImmediateMode(true);
  136. return;
  137. }
  138. // Sort by module.
  139. std::sort(m_errors.begin(), m_errors.end(), SortErrorsByModule);
  140. std::vector<CErrorRecord> errorList;
  141. errorList.swap(m_errors);
  142. m_errors.reserve(errorList.size());
  143. QString prevName = "";
  144. QString prevFile = "";
  145. for (int i = 0; i < errorList.size(); i++)
  146. {
  147. CErrorRecord& err = errorList[i];
  148. if (err.error != prevName || err.file != prevFile)
  149. {
  150. err.count = 1;
  151. m_errors.push_back(err);
  152. }
  153. else if (!m_errors.empty())
  154. {
  155. m_errors.back().count++;
  156. }
  157. prevName = err.error;
  158. prevFile = err.file;
  159. }
  160. // Log all errors.
  161. CryLogAlways("========================= Errors =========================");
  162. for (int i = 0; i < m_errors.size(); i++)
  163. {
  164. CErrorRecord& err = m_errors[i];
  165. QString str = err.GetErrorText();
  166. CryLogAlways("%3d) %s", i, str.toUtf8().data());
  167. }
  168. CryLogAlways("========================= End Errors =========================");
  169. ICVar* const noErrorReportWindowCVar = gEnv && gEnv->pConsole ? gEnv->pConsole->GetCVar("sys_no_error_report_window") : nullptr;
  170. if (noErrorReportWindowCVar && noErrorReportWindowCVar->GetIVal() == 0)
  171. {
  172. CErrorReportDialog::Open(this);
  173. }
  174. SetImmediateMode(true);
  175. }
  176. //////////////////////////////////////////////////////////////////////////
  177. bool CErrorReport::IsEmpty() const
  178. {
  179. return m_errors.empty();
  180. }
  181. //////////////////////////////////////////////////////////////////////////
  182. CErrorRecord& CErrorReport::GetError(int i)
  183. {
  184. assert(i >= 0 && i < m_errors.size());
  185. return m_errors[i];
  186. };
  187. //////////////////////////////////////////////////////////////////////////
  188. void CErrorReport::SetImmediateMode(bool bEnable)
  189. {
  190. if (bEnable != m_bImmediateMode)
  191. {
  192. Clear();
  193. m_bImmediateMode = bEnable;
  194. }
  195. }
  196. //////////////////////////////////////////////////////////////////////////
  197. void CErrorReport::SetCurrentFile(const QString& file)
  198. {
  199. m_currentFilename = file;
  200. }