adventuregamestudio / ags

AGS editor and engine source code
Other
708 stars 159 forks source link

Reorganize DebugManager and make it thread-safe #2361

Closed ivan-mogilko closed 8 months ago

ivan-mogilko commented 8 months ago

Resolves #2339

This does a number of changes to DebugManager, with a purpose to make its interface simpler, and thus easier to safeguard its innards when logging from multiple threads. Adds a mutex to protect public methods.

  1. Moved DebugOutput inside DebugManager, and removed its access from public interface.
  2. Added a mutex, which guards every public method in DebugManager.
  3. Moved MessageBuffer object also inside DebugManager, let it handle message buffering instead of hacking this externally.
  4. Made DebugManager owning output objects and dispose them when shutting logging down. I had to create a separate class for logging to stdout, called StdOutLogger, which is created by AGSPlatformDriver, as we cannot let DebugManager own whole AGSPlatformDriver.
ericoporto commented 8 months ago

ok tested the web port and it seems it's all good. (I remembered https://github.com/libsdl-org/SDL/issues/6344, which is why I was worried, but turns out the mutex used here doesn't crash things and everything works fine).

I am not sure how to test this besides trying a bunch of games and seeing that it still works - btw I did that and all things worked afaict.