Repository: godotengine/godot (language: cpp)

Issue:
[4.4-beta.1] Game editor not embedded due to parameters for it being after `main_run_args` and `--`.
### Tested versions

- v4.4.beta1.mono.official [d33da79d3]

### System information

Godot v4.4.beta1.mono - Windows 11 (build 22631) - Multi-window, 2 monitors - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 3070 (NVIDIA; 32.0.15.6614) - AMD Ryzen 5 5600X 6-Core Processor (12 threads)

### Issue description

![Image](https://github.com/user-attachments/assets/e50686f4-088b-4fe1-9e96-f4b7f82c6126)

To speed up playtesting iterations, I created a feature to test scenes with their own arbitrary execution argument options, and at the time, I made it clear to distinguish them from the Godot engine's execution arguments by putting in parameters with just `--`.
After updating the project to `4.4-beta.1`, I realized that the Game Editor was not embedding only when I started playtesting with the features I had created and started investigating the issue.

![Image](https://github.com/user-attachments/assets/d7ad4808-97bc-4a24-851c-630e61e24677)

![Image](https://github.com/user-attachments/assets/6c040191-3ad5-43d0-a96f-9c8c7e8954b4)

https://github.com/godotengine/godot/blob/d33da79d3f8fe84be2521d25b9ba8e440cf25a88/editor/plugins/game_view_plugin.cpp#L566-L603

I noticed that the parameters that seem to be needed for handling window embedding in the Game editor added in 4.4 go after `main_run_args`.
I suspect this was caused by the function not working properly because it was blocked by the `--` that separates Godot arguments.

### Steps to reproduce

- Create or open any project.
- Open project settings and turn on advanced settings then find `main_run_args`. (`editor/run/main_run_args`)
- Put `--` in `main_run_args` and start play test.
- You can see game window are separated from game editor window.

### Minimal reproduction project (MRP)

[game-editor-window-not-embedded-mrp.zip](https://github.com/user-attachments/files/18455857/game-editor-window-not-embedded-mrp.zip)


Discussion / hints:
Thanks for testing/reporting the issue, I'll look into it, should be easy to fix. Did not thought about the `--`.

Fix patch:
diff --git a/editor/plugins/game_view_plugin.cpp b/editor/plugins/game_view_plugin.cpp
index 212957dd2d9f..c1ec552afc21 100644
--- a/editor/plugins/game_view_plugin.cpp
+++ b/editor/plugins/game_view_plugin.cpp
@@ -570,6 +570,7 @@ void GameView::_update_arguments_for_instance(int p_idx, List<String> &r_argumen
 
 	// Remove duplicates/unwanted parameters.
 	List<String>::Element *E = r_arguments.front();
+	List<String>::Element *user_args_element = nullptr;
 	while (E) {
 		List<String>::Element *N = E->next();
 
@@ -583,23 +584,26 @@ void GameView::_update_arguments_for_instance(int p_idx, List<String> &r_argumen
 			}
 		} else if (E->get() == "-f" || E->get() == "--fullscreen" || E->get() == "-m" || E->get() == "--maximized" || E->get() == "-t" || E->get() == "-always-on-top") {
 			r_arguments.erase(E);
+		} else if (E->get() == "--" || E->get() == "++") {
+			user_args_element = E;
+			break;
 		}
 
 		E = N;
 	}
 
 	// Add the editor window's native ID so the started game can directly set it as its parent.
-	r_arguments.push_back("--wid");
-	r_arguments.push_back(itos(DisplayServer::get_singleton()->window_get_native_handle(DisplayServer::WINDOW_HANDLE, get_window()->get_window_id())));
+	List<String>::Element *N = r_arguments.insert_before(user_args_element, "--wid");
+	N = r_arguments.insert_after(N, itos(DisplayServer::get_singleton()->window_get_native_handle(DisplayServer::WINDOW_HANDLE, get_window()->get_window_id())));
 
 	// Be sure to have the correct window size in the embedded_process control.
 	_update_embed_window_size();
 
 	Rect2i rect = embedded_process->get_screen_embedded_window_rect();
-	r_arguments.push_back("--position");
-	r_arguments.push_back(itos(rect.position.x) + "," + itos(rect.position.y));
-	r_arguments.push_back("--resolution");
-	r_arguments.push_back(itos(rect.size.x) + "x" + itos(rect.size.y));
+	N = r_arguments.insert_after(N, "--position");
+	N = r_arguments.insert_after(N, itos(rect.position.x) + "," + itos(rect.position.y));
+	N = r_arguments.insert_after(N, "--resolution");
+	r_arguments.insert_after(N, itos(rect.size.x) + "x" + itos(rect.size.y));
 }
 
 void GameView::_window_before_closing() {


Test patch: