Repository navigation
Description
I am updating the VCS integration code done in the godot/godot-git-plugin (godotengine/godot-git-plugin#84). I have created a _push() routine to do git pushes.
The repo variable is already initialized in this context. However, this function seems to succeed whenever there are new commits to push to the branch and it crashes when there are no other commits to push (i.e. while trying to do the equivalent of running git push twice).
void GitAPI::_push(String remote, String username, String password) {
Godot::print("GitAPI: Performing push to " + remote);
git_remote *remote_object;
GIT2_CALL(git_remote_lookup(&remote_object, repo, CString(remote).data), "Could not lookup remote \"" + remote + "\"");
CString c_username(username);
CString c_password(username);
String payload[2] = {
username,
password
};
git_remote_callbacks remote_cbs = GIT_REMOTE_CALLBACKS_INIT;
remote_cbs.credentials = &credentials_cb;
remote_cbs.update_tips = &update_cb;
remote_cbs.sideband_progress = &progress_cb;
remote_cbs.transfer_progress = &transfer_progress_cb;
remote_cbs.payload = payload;
remote_cbs.push_transfer_progress = &push_transfer_progress_cb;
remote_cbs.push_update_reference = &push_update_reference_cb;
GIT2_CALL(git_remote_connect(remote_object, GIT_DIRECTION_PUSH, &remote_cbs, NULL, NULL), "Could not connect to remote \"" + remote + "\". Are your credentials correct? Try using a PAT token (in case you are using Github) as your password");
String branch_name(_get_current_branch_name(false));
CString ref_name("refs/heads/" + branch_name + ":refs/remotes/" + remote + "/" + branch_name);
git_remote_add_push(repo, CString(remote).data, ref_name.data);
git_push_options push_options;
git_push_init_options(&push_options, GIT_PUSH_OPTIONS_VERSION);
push_options.callbacks = remote_cbs;
GIT2_CALL(git_remote_push(remote_object, NULL, &push_options), "Failed to push");
git_remote_free(remote_object);
Godot::print("GitAPI: Push ended");
}Crash backtrace:
GitAPI: Performing push to origin
Writing Objects: 0% (0/9), 12 bytes, done.
Writing Objects: 66% (6/9), 1049577 bytes, done.
Writing Objects: 66% (6/9), 1222188 bytes, done.
Writing Objects: 100% (9/9), 1222342 bytes, done.
[updated] refs/remotes/origin/master
GitAPI: Push ended
GitAPI: Performing fetch from origin
GitAPI: Fetch ended
GitAPI: Performing push to origin
================================================================
CrashHandlerException: Program crashed
Engine version: Godot Engine v3.4.beta.custom_build (5ab78381480ba70658ab8413b84f03cdc72526c1)
Dumping the backtrace. Please include this when reporting the bug on https://github.com/godotengine/godot/issues
[0] godot_nativescript_init
[1] godot_nativescript_init
[2] git_smart_subtransport_ssh
[3] git_packbuilder_free
[4] git_packbuilder_foreach
[5] git_smart_subtransport_ssh
[6] git_push_init_options
[7] git_push_init_options
[8] git_remote_upload
[9] git_remote_push
[10] godot_nativescript_init
[11] godot_nativescript_init
[12] godot_nativescript_init
[13] NativeScriptInstance::call (C:\Users\Twarit\Documents\Github\godotengine\godot\modules\gdnative\nativescript\nativescript.cpp:731)
[14] Object::call (C:\Users\Twarit\Documents\Github\godotengine\godot\core\object.cpp:899)
[15] Object::call (C:\Users\Twarit\Documents\Github\godotengine\godot\core\object.cpp:847)
[16] EditorVCSInterface::create_diff_hunk (C:\Users\Twarit\Documents\Github\godotengine\godot\editor\editor_vcs_interface.cpp:237)
[17] VersionControlEditorPlugin::_push (C:\Users\Twarit\Documents\Github\godotengine\godot\editor\plugins\version_control_editor_plugin.cpp:352)
[18] List<EditorVCSInterface::DiffFile,DefaultAllocator>::_Data::erase (C:\Users\Twarit\Documents\Github\godotengine\godot\core\method_bind.gen.inc:149)
[19] Object::call (C:\Users\Twarit\Documents\Github\godotengine\godot\core\object.cpp:918)
[20] Object::emit_signal (C:\Users\Twarit\Documents\Github\godotengine\godot\core\object.cpp:1224)
[21] Object::emit_signal (C:\Users\Twarit\Documents\Github\godotengine\godot\core\object.cpp:1280)
[22] BaseButton::_pressed (C:\Users\Twarit\Documents\Github\godotengine\godot\scene\gui\base_button.cpp:128)
[23] BaseButton::on_action_event (C:\Users\Twarit\Documents\Github\godotengine\godot\scene\gui\base_button.cpp:168)
[24] BaseButton::_gui_input (C:\Users\Twarit\Documents\Github\godotengine\godot\scene\gui\base_button.cpp:67)
[25] MethodBind1<BaseButton,Ref<InputEvent> >::call (C:\Users\Twarit\Documents\Github\godotengine\godot\core\method_bind.gen.inc:867)
[26] Object::call_multilevel (C:\Users\Twarit\Documents\Github\godotengine\godot\core\object.cpp:766)
[27] Object::call_multilevel (C:\Users\Twarit\Documents\Github\godotengine\godot\core\object.cpp:864)
[28] Viewport::_gui_call_input (C:\Users\Twarit\Documents\Github\godotengine\godot\scene\main\viewport.cpp:1632)
[29] Viewport::_gui_input_event (C:\Users\Twarit\Documents\Github\godotengine\godot\scene\main\viewport.cpp:2018)
[30] Viewport::input (C:\Users\Twarit\Documents\Github\godotengine\godot\scene\main\viewport.cpp:2786)
[31] Viewport::_vp_input (C:\Users\Twarit\Documents\Github\godotengine\godot\scene\main\viewport.cpp:1401)
[32] MethodBind1<Viewport,Ref<InputEvent> const &>::call (C:\Users\Twarit\Documents\Github\godotengine\godot\core\method_bind.gen.inc:867)
[33] Object::call (C:\Users\Twarit\Documents\Github\godotengine\godot\core\object.cpp:918)
[34] Object::call (C:\Users\Twarit\Documents\Github\godotengine\godot\core\object.cpp:847)
[35] SceneTree::call_group_flags (C:\Users\Twarit\Documents\Github\godotengine\godot\scene\main\scene_tree.cpp:272)
[36] SceneTree::input_event (C:\Users\Twarit\Documents\Github\godotengine\godot\scene\main\scene_tree.cpp:431)
[37] InputDefault::_parse_input_event_impl (C:\Users\Twarit\Documents\Github\godotengine\godot\main\input_default.cpp:477)
[38] InputDefault::flush_buffered_events (C:\Users\Twarit\Documents\Github\godotengine\godot\main\input_default.cpp:699)
[39] OS_Windows::process_events (C:\Users\Twarit\Documents\Github\godotengine\godot\platform\windows\os_windows.cpp:2554)
[40] OS_Windows::run (C:\Users\Twarit\Documents\Github\godotengine\godot\platform\windows\os_windows.cpp:3346)
[41] widechar_main (C:\Users\Twarit\Documents\Github\godotengine\godot\platform\windows\godot_windows.cpp:161)
[42] _main (C:\Users\Twarit\Documents\Github\godotengine\godot\platform\windows\godot_windows.cpp:183)
[43] main (C:\Users\Twarit\Documents\Github\godotengine\godot\platform\windows\godot_windows.cpp:195)
[44] __scrt_common_main_seh (d:\a01\_work\2\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288)
[45] BaseThreadInitThunk
-- END OF BACKTRACE --
================================================================
I do realize that the Godot related functions might not be relevant in the backtrace but the crash is only occurring inside of git_remote_push() or git_remote_upload().
Reproduction steps
- Download https://drive.google.com/file/d/1dEiVbaPW3PaPPEHZ0SCFhPuste3ZdkqY/view?usp=sharing (I uploaded the project to drive due to space limitation).
- Open the Godot executable
- Open the demo project
- Go to Project > Version Control > Set Up Version Control. Provide your Github creds (Godot will not send the creds anywhere). Click on Initialize.
- Go to commit dock, create a commit and try to push.
- After the push succeeds, try to push again.
Source code is present at godotengine/godot-git-plugin#84
Expected behavior
Should not crash when there are no commits to push.
Actual behavior
Crashes when no commits are required to be pushed.
Version of libgit2 (release number or SHA1)
v1.3
Operating system(s) tested
Windows 10
Activity
ethomson commentedon Oct 3, 2021
Is this a regression? Has this ever worked and now fails in your upgrade to 1.3 or is this net new functionality?
twaritwaikar commentedon Oct 3, 2021
It might be a regression because it didn't appear before upgrading to v1.3. However, there have been some considerable code changes on our end since the upgrade so I can downgrade again to test a bit more and get back.
ethomson commentedon Oct 4, 2021
Apologies, not very familiar with godot. How do you do your FFI? Between v1.1 and v1.3 we made some ABI breaking changes. If you're not just talking to the C API or automatically generating your bindings then we may have broken you. For example v1.1.1...v1.2.0#diff-09d6e347090c92179ac7cb177bb3e4a2cb5b10c477187ddb80ed950c64dbc278R618
(ABI compatibility is an important consideration going forward but we've been very poor about it in the v0 and v1 series.)
twaritwaikar commentedon Oct 4, 2021
We are not doing any FFI. We are directly using the C API in C++ code, and rebuilding the libgit2 binary everytime from source
ethomson commentedon Oct 4, 2021
Oh, sorry! I had it in my head that godot was written in C#. Alas, I was hoping for an easy fix here.
twaritwaikar commentedon Oct 4, 2021
@ethomson Ah sorry, I didn't clear that earlier. I am working on a plugin, written in C++ for the Godot Editor, which is also written in C++. There is no language interop in question apart from the C-C++ one.
twaritwaikar commentedon Oct 4, 2021
Downgrading to v1.0 doesn't help resolve this issue
twaritwaikar commentedon Oct 4, 2021
Additional info: Running
git push originfrom the Git CLI shows this error:I believe handling this error is what is currently being missed in libgit2
twaritwaikar commentedon Oct 7, 2021
This turned out to be a division by 0 error in one of the remote callbacks. This makes sense because this issue only came up when the remote branch exactly matched the history of the local branch, a.k.a. the total data to transfer would be 0, and dividing the data transferred so far by the total data to transfer to get the % data transferred will result in a division by 0 error.
Sorry for the mistake, this is not a bug in libgit2!
ethomson commentedon Oct 7, 2021
Thanks for the update @ChronicallySerious !