godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
88.89k stars 20.16k forks source link

unable to terminate immediately #38577

Closed avril-gh closed 4 years ago

avril-gh commented 4 years ago

Godot version: Godot Engine v3.2.2.beta.custom_build.1e19cdd6c

OS/device including version: Windows 10 x64

Issue description: OS.kill(OS.get_process_id()) does not terminate godot on windows and gives error

ERROR: OS_Windows::kill: Condition "!process_map->has(p_pid)" is true. Returned: FAILED
   At: platform\windows\os_windows.cpp:2874
rsubtil commented 4 years ago

Right now, on Windows, you can only kill processes that you have spawned through OS.execute, which seems weird, considering that on Linux, for example, your same code works without an issue, terminating the game.

This behaviour should be the same independent of the OS, but should Godot be able to "kill" itself? That looks like a weird idea.

If you need to stop your game, the best behaviour is through get_tree().quit(). Since this effectively sets a flag, it only takes action when the next iteration of MainLoop is about to be run. But this is the way to make Godot exit in a clean way: killing your game sounds way too overkill

avril-gh commented 4 years ago

game detect's that it has been hacked and want to terminate, or program found that data is damaged to the degree where further processing will cause only damage so it want to terminate. There's many use cases.

FeralBytes commented 4 years ago

@avril-gh I still can't see why get_tree().quit() is not sufficient for those use cases?

rsubtil commented 4 years ago

game detect's that it has been hacked and want to terminate, or program found that data is damaged to the degree where further processing will cause only damage so it want to terminate.

Even then, regular programs generally use exceptions to handle these scenarios. However Godot doesn't have exceptions because it's their philosophy that games should not crash, no matter what.

Killing programs generally is a voluntary action by the user, but if Godot allows to do them, then I think it should be discussed what should be the best approach. What do you think @akien-mga @Calinou ?

EDIT: Fidling around in Godot, I found this behaviour:

get_tree().quit()
yield(get_tree(), "idle_frame")
print("This line is not executed")

Maybe this works for your use-case..?

avril-gh commented 4 years ago

use case of TerminateProcess , to say it as a metaphor... Its like we're flying a plane, and then lightning strikes and tear off wings.

( when hacker access process memory and do things there, and i detect it, i want to make him to think that game has crashed because of his doings , so his fiddling with memory or other data are pointless because game is crashing )

The question is does godot support cold-exit like TerminateProcess on will (not by accident) or not. I like that godot is rock solid by design, its a feature which please player experience. but on the other side i would like to have ability for sudden immediate quit which have to make someone who fiddling with sensitive data to think that his action fails and that it crashed due to his fault.

the error read's

ERROR: OS_Windows::kill: Condition "!process_map->has(p_pid)" is true. Returned: FAILED
   At: platform\windows\os_windows.cpp:2874

its a bug or its by design ? if its by design - it should at least compare pID with own pID and print warning that this action is not allowed.

rsubtil commented 4 years ago

( when hacker access process memory and do things there, and i detect it, i want to make him to think that game has crashed because of his doings , so his fiddling with memory or other data are pointless because game is crashing )

I can guarantee you 99% of the times this is something outside of your control. If there's a way to read/write to the memory of other processes, that's a huge security problem of the operating system that will be quickly patched. Just look at the recent Spectre/Meltdown headlines.

Having a "kill switch" in your application to fight hackers or anyone trying to read game files, from my experience, will probably affect more innocent people that actual hackers. There are much better ways to protect your game or application.

However, since this works well on Linux, it should work on Windows as well. Apparently there's a lot more restrictions to what you can do to other processes. There's a security/policy system to prevent an app to terminate unrelated others.

I will open a PR that adds the current Godot's PID to this list, to make it possible what you're asking for.

avril-gh commented 4 years ago

(...) If there's a way to read/write to the memory of other processes, that's a huge security problem of the operating system(...)

@Ev1lbl0w

CreateRemoteThread , WriteProcessMemory , VirtualProtectEx , VirtualAllocEx and tens of other ones. ...Not security breach, just debugging helpers.

I will open a PR that adds the current Godot's PID to this list, to make it possible what you're asking for.

thank you 👍

Having a "kill switch" in your application to fight hackers or anyone trying to read game files, from my experience, will probably affect more innocent people that actual hackers. There are much better ways to protect your game or application.

of course ! Its common that hackers remove protection and enjoy the game while honest players often suffer from protections which not allow them play. My rule is