Skip to content

Abort execution if MovieWriter can't write file or find a valid extension #95867

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2761,6 +2761,16 @@ Error Main::setup2(bool p_show_boot_logo) {
OS::get_singleton()->benchmark_end_measure("Servers", "Modules and Extensions");
}

// Perform this check before initializing the rest of the servers to avoid a crash on failure.
if (Engine::get_singleton()->get_write_movie_path() != String()) {
movie_writer = MovieWriter::find_writer_for_file(Engine::get_singleton()->get_write_movie_path());
if (movie_writer == nullptr) {
ERR_PRINT(vformat("Can't find MovieWriter for file type, aborting.\nCheck if the specified file path has a valid extension: %s", Engine::get_singleton()->get_write_movie_path()));
OS::get_singleton()->set_exit_code(EXIT_FAILURE);
return FAILED;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the clean exit, it's likely needs the same cleanup as DisplayServer failure:

https://github.com/godotengine/godot/blob/913a0c0043daa3009737ffa45c09744631167b80/main/main.cpp#L2857-L2879

}
}

/* Initialize Input */

{
Expand Down Expand Up @@ -2947,14 +2957,6 @@ Error Main::setup2(bool p_show_boot_logo) {
rendering_server->set_print_gpu_profile(true);
}

if (Engine::get_singleton()->get_write_movie_path() != String()) {
movie_writer = MovieWriter::find_writer_for_file(Engine::get_singleton()->get_write_movie_path());
if (movie_writer == nullptr) {
ERR_PRINT("Can't find movie writer for file type, aborting: " + Engine::get_singleton()->get_write_movie_path());
Engine::get_singleton()->set_write_movie_path(String());
}
}

OS::get_singleton()->benchmark_end_measure("Servers", "Rendering");
}

Expand Down
16 changes: 14 additions & 2 deletions servers/movie_writer/movie_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,13 @@ void MovieWriter::begin(const Size2i &p_movie_size, uint32_t p_fps, const String
audio_channels = AudioDriverDummy::get_dummy_singleton()->get_channels();
audio_mix_buffer.resize(mix_rate * audio_channels / fps);

write_begin(p_movie_size, p_fps, p_base_path);
const Error err = write_begin(p_movie_size, p_fps, p_base_path);

if (err != OK) {
ERR_PRINT(vformat("Couldn't begin writing files for Movie Maker mode, aborting.\nCheck if the specified file path is valid and has write permissions: %s", p_base_path));
// FIXME: This technically works, but it does not exit cleanly.
exit(EXIT_FAILURE);
}
}

void MovieWriter::_bind_methods() {
Expand Down Expand Up @@ -196,7 +202,13 @@ void MovieWriter::add_frame() {
gpu_time += RenderingServer::get_singleton()->viewport_get_measured_render_time_gpu(main_vp_rid);

AudioDriverDummy::get_dummy_singleton()->mix_audio(mix_rate / fps, audio_mix_buffer.ptr());
write_frame(vp_tex, audio_mix_buffer.ptr());
const Error err = write_frame(vp_tex, audio_mix_buffer.ptr());

if (err != OK) {
ERR_PRINT(vformat("Couldn't write frame %d for Movie Maker mode, aborting.\nCheck if the specified file path is valid, has write permissions and enough space on disk.", Engine::get_singleton()->get_frames_drawn()));
// FIXME: This technically works, but it does not exit cleanly.
exit(EXIT_FAILURE);
}
}

void MovieWriter::end() {
Expand Down
Loading