仍有bug

This commit is contained in:
2026-08-24 16:27:27 +08:00
parent ca6d8f8e79
commit f463a756fc
27 changed files with 1201 additions and 898 deletions
+57 -1
View File
@@ -28,12 +28,26 @@ bool contains_color(Image_View view) {
}
return false;
}
std::uint64_t image_hash(Image_View view) {
std::uint64_t value{1469598103934665603ULL};
for (int y = 0; y < view.height; ++y) {
const auto* row = reinterpret_cast<const std::byte*>(view.data) +
static_cast<std::ptrdiff_t>(y) * view.stride;
for (std::ptrdiff_t index = 0;
index < static_cast<std::ptrdiff_t>(view.width * sizeof(Pixel));
++index) {
value ^= static_cast<std::uint8_t>(row[index]);
value *= 1099511628211ULL;
}
}
return value;
}
template <typename Scene>
std::unique_ptr<Frame_2D> render_frame(Scene* scene) {
static std::uint64_t sequence{1};
auto frame = std::make_unique<Frame_2D>(Frame_Identity{sequence++, 0});
scene->set_frame_callback([](Frame_2D*) {});
EXPECT_EQ(scene->render(frame.get()), Render_Scene_2D::Render_Result::completed);
EXPECT_TRUE(scene->render(frame.get()).has_value());
return frame;
}
}
@@ -182,3 +196,45 @@ TEST(render_scene_2d, composites_axes_and_spectrum_into_final_frame) {
EXPECT_EQ(resized_frame.height, resized_canvas.height);
EXPECT_TRUE(contains_color(resized_frame));
}
TEST(spectrum_data, repeatedly_publishes_new_samples_during_long_running_render) {
using Frequency = Impl<Frequency_Axis>;
using Power = Impl<Numeric_Axis>;
using Spectrum_Object = Impl<Spectrum>;
using Scene_Object = Impl<Render_Scene_2D>;
initialize_runtime(4);
auto frequency = build_object<Frequency>();
auto power = build_object<Power>();
auto spectrum = build_object<Spectrum_Object>(frequency.get(), power.get());
auto scene = build_scene<Scene_Object>(spectrum.get());
frequency->set<&Abs_Axis::Prop::position>(Point_F{20.0, 100.0});
frequency->set<&Abs_Axis::Prop::pixel_length>(120.0);
frequency->set<&Numeric_Axis::Prop::coordinate_range>(Axis_Range{0.0, 100.0});
power->set<&Abs_Axis::Prop::position>(Point_F{20.0, 100.0});
power->set<&Abs_Axis::Prop::pixel_length>(-80.0);
power->set<&Abs_Axis::Prop::orientation>(Axis_Orientation::vertical);
power->set<&Numeric_Axis::Prop::coordinate_range>(Axis_Range{-100.0, 0.0});
spectrum->set<&Spectrum::Prop::frequency_range>(Axis_Range{0.0, 100.0});
scene->set<&Render_Scene_2D::Prop::viewport>(Size{160, 120});
scene->set<&Render_Scene_2D::Prop::background>(Color::transparent());
scene->activate_view();
std::uint64_t previous_hash{};
std::size_t changed_frames{};
for (std::size_t frame_index = 0; frame_index < 720; ++frame_index) {
std::vector<Spectrum_Power> samples(128, -95.0);
const std::size_t peak = 8 + frame_index % 112;
samples[peak] = -15.0;
spectrum->pending_buffer<Spectrum_Frame_Tag>() =
Spectrum_Frame{std::move(samples)};
spectrum->mark_dirty<Prepare_Data_Tag>();
auto frame = render_frame(scene.get());
const auto hash = image_hash(frame->image());
if (frame_index != 0 && hash != previous_hash) ++changed_frames;
previous_hash = hash;
EXPECT_TRUE(spectrum->read_state<Renderable::Base_Tag>().prepare_executed);
EXPECT_TRUE(spectrum->read_state<Renderable::Base_Tag>().paint_executed);
EXPECT_EQ(spectrum->read_state<Spectrum::Base_Tag>().sample_count, 128u);
}
EXPECT_GT(changed_frames, 700u);
}