错误处理

This commit is contained in:
2026-08-16 20:39:12 +08:00
parent b33b57b0e3
commit 9d544c7ba9
44 changed files with 469 additions and 459 deletions
+24 -24
View File
@@ -29,22 +29,22 @@
#include <vector>
namespace renderive::web {
namespace {
Gallery_Render_Error gallery_render_error(Plot_Render_Error error) {
Gallery_Render_Result gallery_render_error(Plot_Render_Result error) {
switch (error) {
case Plot_Render_Error::none:
return Gallery_Render_Error::none;
case Plot_Render_Error::view_inactive:
return Gallery_Render_Error::inactive;
case Plot_Render_Error::cancelled:
return Gallery_Render_Error::cancelled;
case Plot_Render_Error::deadline_exceeded:
return Gallery_Render_Error::deadline_exceeded;
case Plot_Render_Error::external_failure:
return Gallery_Render_Error::backend_failure;
case Plot_Render_Error::scene_shutting_down:
return Gallery_Render_Error::shutting_down;
case Plot_Render_Result::none:
return Gallery_Render_Result::none;
case Plot_Render_Result::view_inactive:
return Gallery_Render_Result::inactive;
case Plot_Render_Result::cancelled:
return Gallery_Render_Result::cancelled;
case Plot_Render_Result::deadline_exceeded:
return Gallery_Render_Result::deadline_exceeded;
case Plot_Render_Result::external_failure:
return Gallery_Render_Result::backend_failure;
case Plot_Render_Result::scene_shutting_down:
return Gallery_Render_Result::shutting_down;
default:
return Gallery_Render_Error::frame_unavailable;
return Gallery_Render_Result::frame_unavailable;
}
}
template <class Update>
@@ -213,7 +213,7 @@ public:
static_cast<void>(plot_.set_max_render_fps(30.0));
plot_.activate_view();
update_model();
if (plot_.render_frame(true) != Plot_Render_Error::none)
if (plot_.render_frame(true) != Plot_Render_Result::none)
plot_.request_redraw();
}
~Gallery_Scene() {
@@ -349,13 +349,13 @@ public:
}
}, event);
}
Gallery_Render_Error render_latest_frame() override {
Gallery_Render_Result render_latest_frame() override {
if (!plot_.view_active())
return Gallery_Render_Error::inactive;
return Gallery_Render_Result::inactive;
update_model();
const auto started = std::chrono::steady_clock::now();
const auto error = plot_.render_frame(true);
const bool rendered = error == Plot_Render_Error::none;
const bool rendered = error == Plot_Render_Result::none;
record_performance(started, rendered);
if (rendered)
rendered_since_last_pixel_ = true;
@@ -365,7 +365,7 @@ public:
if (!plot_.view_active())
return std::nullopt;
if (!rendered_since_last_pixel_ && !can_render_automatically() &&
render_latest_frame() != Gallery_Render_Error::none)
render_latest_frame() != Gallery_Render_Result::none)
return std::nullopt;
rendered_since_last_pixel_ = false;
std::string pixels;
@@ -420,7 +420,7 @@ public:
}
if (request.id == "mode_prepare" || request.id == "mode_enqueue") {
update_model();
const bool prepared = plot_.prepare_frame() == Plot_Render_Error::none;
const bool prepared = plot_.prepare_frame() == Plot_Render_Result::none;
last_action_result_ = prepared ? "frame prepared" : "prepare rejected";
return prepared ? "Kernel 帧已准备/入队" : "Kernel 拒绝准备帧";
}
@@ -432,19 +432,19 @@ public:
int prepared{};
for (int index = 0; index < count; ++index) {
update_model();
prepared += plot_.prepare_frame() == Plot_Render_Error::none ? 1 : 0;
prepared += plot_.prepare_frame() == Plot_Render_Result::none ? 1 : 0;
}
last_action_result_ = "enqueued=" + std::to_string(prepared);
return "回放帧已批量压入 Flow 队列";
}
if (request.id == "mode_refresh") {
const bool refreshed = plot_.refresh_manual_frame() == Plot_Render_Error::none;
const bool refreshed = plot_.refresh_manual_frame() == Plot_Render_Result::none;
last_action_result_ = refreshed ? "manual refresh succeeded" : "manual refresh failed";
return refreshed ? "Manual 待处理帧已提交刷新" : "当前没有可刷新的 Manual 帧";
}
if (request.id == "mode_render" || request.id == "mode_dequeue") {
const auto started = std::chrono::steady_clock::now();
const bool rendered = plot_.render_prepared_frame() == Plot_Render_Error::none;
const bool rendered = plot_.render_prepared_frame() == Plot_Render_Result::none;
record_performance(started, rendered);
rendered_since_last_pixel_ = rendered;
last_action_result_ = rendered ? "prepared frame rendered" : "no prepared frame";
@@ -458,7 +458,7 @@ public:
if (request.id == "mode_cycle") {
update_model();
const auto started = std::chrono::steady_clock::now();
const bool rendered = plot_.render_frame(true) == Plot_Render_Error::none;
const bool rendered = plot_.render_frame(true) == Plot_Render_Result::none;
record_performance(started, rendered);
rendered_since_last_pixel_ = rendered;
last_action_result_ = rendered ? "full frame cycle rendered" : "frame cycle skipped";