Skip to content

Workaround IL2CPP missing support for Console.CancelKeyPress#5

Merged
Frooxius merged 1 commit intoYellow-Dog-Man:mainfrom
jvyden:console-keypress-workaround
Apr 22, 2026
Merged

Workaround IL2CPP missing support for Console.CancelKeyPress#5
Frooxius merged 1 commit intoYellow-Dog-Man:mainfrom
jvyden:console-keypress-workaround

Conversation

@jvyden
Copy link
Copy Markdown

@jvyden jvyden commented Apr 22, 2026

This gets the IL2CPP renderer a little further into initialization.

When setting up a queue, Interprocess will setup an event handler with the console's ^C handler to shutdown cleanly when the process is exited via the console.

This ends up calling a method in Mono named WindowsConsole::DoWindowsConsoleCancelEvent which is missing a MonoPInvokeCallback attribute, which is required for managed methods under IL2CPP. This ends up throwing a NotSupportedException:

Failed to connect to the controller:
System.NotSupportedException: To marshal a managed method, please add an attribute named 'MonoPInvokeCallback' to the method definition. The method we're attempting to marshal is: System.Console+WindowsConsole::DoWindowsConsoleCancelEvent
  at System.Console+WindowsConsole.SetConsoleCtrlHandler (System.Console+WindowsConsole+WindowsCancelHandler handler, System.Boolean addHandler) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Console.add_CancelKeyPress (System.ConsoleCancelEventHandler value) [0x00000] in <00000000000000000000000000000000>:0 
  at Cloudtoid.Interprocess.Queue..ctor (Cloudtoid.Interprocess.QueueOptions options, Microsoft.Extensions.Logging.ILoggerFactory loggerFactory) [0x00000] in <00000000000000000000000000000000>:0 
  at Cloudtoid.Interprocess.Publisher..ctor (Cloudtoid.Interprocess.QueueOptions options, Microsoft.Extensions.Logging.ILoggerFactory loggerFactory) [0x00000] in <00000000000000000000000000000000>:0 
  at Cloudtoid.Interprocess.QueueFactory.CreatePublisher (Cloudtoid.Interprocess.QueueOptions options) [0x00000] in <00000000000000000000000000000000>:0 
  at Renderite.Shared.MessagingManager.Connect (System.String queueName, System.Boolean isAuthority, System.Int64 capacity) [0x00000] in <00000000000000000000000000000000>:0 
  at Renderite.Unity.RenderingManager.Awake () [0x00000] in <00000000000000000000000000000000>:0 

We can't modify Mono here easily, so to fix, just catch and ignore that particular exception.

Related to Yellow-Dog-Man/Renderite.Unity.Renderer#2

Copy link
Copy Markdown
Member

@Frooxius Frooxius left a comment

Choose a reason for hiding this comment

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

Huh. I didn't actually know the library is hooking into this in the first place.

This looks ok! Good on making the Exception type scoped too!

Thank you!

@Frooxius Frooxius merged commit 5385fe0 into Yellow-Dog-Man:main Apr 22, 2026
2 checks passed
@jvyden jvyden deleted the console-keypress-workaround branch April 22, 2026 23:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants