Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GameWindow throws StackOverflowException #1494

Open
SilkyKitsune opened this issue Aug 19, 2022 · 18 comments
Open

GameWindow throws StackOverflowException #1494

SilkyKitsune opened this issue Aug 19, 2022 · 18 comments
Labels
4.x needs verification Indicates that this bug needs to be reproduced again becaus of a major/breaking change.

Comments

@SilkyKitsune
Copy link

  • Win10
  • OpenTK 4.7.4 (from nuget)
  • .NET Core 3.1

My GameWindow class kept throwing the exception and I was trying to figure out what specifically was causing it. I kept removing new code until there wasn't anything left running in my inherited class, so I tried running the basic GameWindow itself without inheriting it and it throws the exception even faster than my inherited class did. For clarity my code was near identical to the textures tutorial in the learnOpenTK repo. I did try doing simple searches about this issue but searching 'StackOverflow' I just get results for the website and not any known instances of this exception with opentk.

This is all visual studio would give me for the stack trace, not very useful
System.StackOverflowException
HResult=0x800703E9
Source=
StackTrace:

@NogginBops
Copy link
Member

Can you post your code? "Near identical" is not identical and the difference is likely causing this error

@NogginBops NogginBops added 4.x needs verification Indicates that this bug needs to be reproduced again becaus of a major/breaking change. labels Aug 19, 2022
@SilkyKitsune
Copy link
Author

SilkyKitsune commented Aug 19, 2022

Did you notice "I kept removing new code until there wasn't anything left running in my inherited class"? The exception persisted even when no additional code was being run. No shaders, no textures, no overrides, no new classes what so ever. Did you also notice "I tried running the basic GameWindow itself without inheriting it and it throws the exception even faster than my inherited class did"? My additional code was only delaying the exception from being thrown. The only differences in my code are that shader takes the scripts as strings directly instead of loading text files, and texture was using a zero filled array instead of loading an image file.

@utkumaden
Copy link
Collaborator

utkumaden commented Aug 19, 2022

The issue here is we don't exactly know your codebase to be able to reproduce the issue. What you may think is normal usage may not be normal usage, and really without a single line of code this bug report is hard to verify, reproduce and fix. No such issue came up in #support in the discord either from anyone except you since the release of 4.7.4. What is running a GameWindow by itself?

What I did do is write what I think would be the minimum viable thing you are trying to describe. The following:

using System;
using OpenTK;
using OpenTK.Windowing.Common;
using OpenTK.Windowing.Desktop;

namespace TKtest
{
	public class Program
	{
		public static void Main()
		{
			GameWindow window = new GameWindow(GameWindowSettings.Default, NativeWindowSettings.Default);
			window.Run();
		}
	}
}

This code did not stack overflow. Is there a time frame for the stack overflow? Minutes? Seconds?

@SilkyKitsune
Copy link
Author

SilkyKitsune commented Aug 19, 2022

I have that code almost exactly except native window settings is being constructed like in the tutorial examples, the exception throws within seconds. I tried making a separate project entirely and copied/pasted the textures scripts from the tutorial exactly
and swapped out loading an image file for a zero filled array again and it doesn't seem to throw the exception, but it could just take a while, the time it took to throw the exception seemed to depend on how much extra code was being run and the frequency of the window.

sorry I don't know how box the code like you did I don't use github much

using System;
using OpenTK.Windowing.Desktop;
using OpenTK.Windowing.Common;

namespace TestBed
{
static class Program
{
static void Main()
{
GameWindow window = new GameWindow(GameWindowSettings.Default,
new NativeWindowSettings()
{
Size = new OpenTK.Mathematics.Vector2i(400, 225),
Title = "OpenTK Test",
Flags = ContextFlags.ForwardCompatible
});
window.Run();
}
}
}

@NogginBops
Copy link
Member

Is the above code all the code that you have in your project?
If that is the case I see no possible way for this to overflow the stack. Would be great if you could get some kind of stacktrace for this.

@SilkyKitsune
Copy link
Author

I don't know why github hides things in '<' '>'
stacktrace

@NogginBops
Copy link
Member

I saw that. I was saying that if there was any way to get a useful stack trace by maybe pausing the debugger just before the exception occurs or something like that it would help a lot in figuring out what is going on.
Because at the moment there is no suspect. Basic projects like this are running 4.7.4 and not getting this exception (I'm like 99% sure) so it's unclear what might be causing this.

@SilkyKitsune
Copy link
Author

I think I've found the problem, the platform target in my project settings was x86. The exception doesn't seem to throw anymore if it's set to different. I'm not totally sure when it got changed to that though.

@SilkyKitsune
Copy link
Author

I'm really not sure why that made a difference since it never does in any other project, but I guess I'll just close this issue then.

@NogginBops
Copy link
Member

I don't think we should close the issue when we haven't figured out what was happening. Especially as we just got an essential clue, the bug is dependent on whether the application is run in 32bit or 64bit mode. Now it might be reproducible.

@NogginBops NogginBops reopened this Aug 20, 2022
@NogginBops
Copy link
Member

I'm not able to reproduce the issue running the code posted above in x86 mode

using System;
using OpenTK.Windowing.Desktop;
using OpenTK.Windowing.Common;

namespace TestBed
{
    static class Program
    {
        static void Main()
        {
            GameWindow window = new GameWindow(GameWindowSettings.Default,
            new NativeWindowSettings()
            {
                Size = new OpenTK.Mathematics.Vector2i(400, 225),
                Title = "OpenTK Test",
                Flags = ContextFlags.ForwardCompatible
            });
            window.Run();
        }
    }
}

@NogginBops
Copy link
Member

@codefoxup does the above code cause the exception for you when running x86?

@IchiganCS
Copy link

IchiganCS commented Aug 22, 2022

If I might help, I tried this on my pc, I received the stack overflow exception with the following trace:

Stack overflow.
   at OpenTK.Windowing.GraphicsLibraryFramework.GLFWNative.glfwGetCursorPos(OpenTK.Windowing.GraphicsLibraryFramework.Window*, Double*, Double*)
   at OpenTK.Windowing.GraphicsLibraryFramework.GLFW.GetCursorPos(OpenTK.Windowing.GraphicsLibraryFramework.Window*, Double ByRef, Double ByRef)
   at OpenTK.Windowing.Desktop.NativeWindow.ProcessInputEvents()
   at OpenTK.Windowing.Desktop.GameWindow.DispatchUpdateFrame()
   at OpenTK.Windowing.Desktop.GameWindow.Run()
   at TestBed.Program.Main()

(Additional information: Compiled in wsl for win x86, run on .Net6 with Win11)

@NogginBops
Copy link
Member

NogginBops commented Aug 22, 2022

Compiled in wsl for win x86, run on .Net6 with Win11

How are you compiling the project? dotnet publish?

@SilkyKitsune
Copy link
Author

The same code still throws the exception even in a totally new project. It does not throw when the platform target is anycpu or x64, only x86. I'm still not sure if there's a way for me to get a better stack trace.

@IchiganCS
Copy link

How are you compiling the project? dotnet publish?

The command to build the executable was

dotnet build --os win --arch x86

@NogginBops
Copy link
Member

This is starting to look like some kind of glfw bug or something with the way we call into glfw when running as a 32 bit process that doesn't work well.

@softwareantics
Copy link

This issue was not occurring for me on master, built for x86 on .NET 5, in VS.

I waited about a minute and no exception was thrown. I noticed we recently updated to GLFW 3.3.8. I didn't see anything related to glfwGetCursorPos so I can only assume this issue still isn't fixed but is most likely still upstream.

I would suggest to @codefoxup that you develop for 64-bit systems as we're now in 2022 😜. But in all honesty, this is likely the best course of action as it seems like this is a GLFW issue.

@NogginBops, I took a quick look over how we're loading the library and I can't seem to find anything. While this is open I'll try replicating this issue on a different machine as I'm hoping I can diagnose who's to blame.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.x needs verification Indicates that this bug needs to be reproduced again becaus of a major/breaking change.
Projects
None yet
Development

No branches or pull requests

5 participants