Skip to content

Commit b1b9c0e

Browse files
committed
Rectify remaining self-review comments
1 parent 5816b63 commit b1b9c0e

File tree

2 files changed

+46
-26
lines changed

2 files changed

+46
-26
lines changed

sources/Windowing/Windowing/Implementations/SDL3/SdlSurfaceComponents.OpenGL.cs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -214,25 +214,24 @@ private bool TryCreateContext(bool isInitializing)
214214
currentWindow = Sdl.GLGetCurrentWindow();
215215
}
216216

217-
if (Handle == nullptr)
217+
if (Handle == nullptr && isInitializing)
218218
{
219-
if (isInitializing)
220-
{
221-
throw new InvalidOperationException(
222-
"Attempted to initialize OpenGL context before window initialization - this should not be possible "
223-
+ "with normal usage. Please report this at https://github.com/dotnet/Silk.NET"
224-
);
225-
}
219+
throw new InvalidOperationException(
220+
"Attempted to initialize OpenGL context before window initialization - this should not be possible "
221+
+ "with normal usage. Please report this at https://github.com/dotnet/Silk.NET"
222+
);
223+
}
226224

227-
// We need to create a dummy window if we haven't already (InitializePlatform does this, but it's only made
228-
// available to the first Surface).
229-
var props = CreateDummyWindowProps();
230-
Handle = Sdl.CreateWindowWithProperties(props);
231-
Sdl.DestroyProperties(props);
232-
if (Handle == nullptr)
233-
{
234-
Sdl.ThrowError();
235-
}
225+
// We need to create a dummy window if we haven't already (InitializePlatform does this, but it's only made
226+
// available to the first Surface). This is assigned to Handle if successful.
227+
if (
228+
!isInitializing
229+
&& GetDummyWindow(Sdl.WindowOpengl, nFlags: Sdl.WindowVulkan) == nullptr
230+
)
231+
{
232+
// Guess OpenGL isn't supported after all...
233+
Sdl.ClearError();
234+
return false;
236235
}
237236

238237
// Get the shared context we need to make current before creating the context

sources/Windowing/Windowing/Implementations/SDL3/SdlSurfaceComponents.cs

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,15 @@ public static WindowHandle InitializePlatform()
8888
DebugPrintWithError(IsVulkanEnabled ? "Vulkan support enabled" : "Vulkan support disabled");
8989
Sdl.ClearError();
9090

91-
var props = CreateDummyWindowProps();
92-
var tempWindow = Sdl.CreateWindowWithProperties(props);
91+
var tempWindow = Sdl.CreateWindow("Dummy Window", 1, 1, Sdl.WindowHidden);
9392
if (tempWindow == nullptr)
9493
{
9594
// Should be able to at least create a window.
96-
Sdl.DestroyProperties(props);
9795
Sdl.ThrowError();
9896
return nullptr;
9997
}
10098

101-
var tempChildWindow = Sdl.CreateWindowWithProperties(props);
99+
var tempChildWindow = Sdl.CreateWindow("Dummy Window 2", 1, 1, Sdl.WindowHidden);
102100
if (tempChildWindow != nullptr)
103101
{
104102
IsChildrenEnabled = true;
@@ -111,15 +109,38 @@ public static WindowHandle InitializePlatform()
111109
IsWindowEnabled = Sdl.SetWindowPosition(tempWindow, 1, 1);
112110
DebugPrintWithError($"Window decoration {(IsWindowEnabled ? "supported" : "unsupported")}");
113111
Sdl.ClearError();
114-
Sdl.DestroyProperties(props);
115112
return tempWindow;
116113
}
117114

118-
private static uint CreateDummyWindowProps()
115+
private WindowHandle GetDummyWindow(ulong flags = 0, ulong nFlags = 0)
119116
{
120-
var props = Sdl.CreateProperties();
121-
Sdl.SetBooleanProperty(props, Sdl.PropWindowCreateHiddenBoolean, true);
122-
return props;
117+
flags |= Sdl.WindowHidden;
118+
ulong originalFlags = 0;
119+
if (
120+
Handle != nullptr
121+
&& flags == (flags & (flags |= (originalFlags = Sdl.GetWindowFlags(Handle))))
122+
)
123+
{
124+
return Handle;
125+
}
126+
127+
flags &= ~nFlags;
128+
Sdl.DestroyWindow(Handle); // so we don't get errors pertaining to multi-window on single-window platforms
129+
var ret = Sdl.CreateWindow("Dummy Window", 1, 1, flags);
130+
if (ret == nullptr)
131+
{
132+
if (originalFlags != 0)
133+
{
134+
// Recreate the old dummy window.
135+
Handle = Sdl.CreateWindow("Dummy Window", 1, 1, originalFlags);
136+
}
137+
}
138+
else
139+
{
140+
Handle = ret;
141+
}
142+
143+
return ret;
123144
}
124145

125146
public void PreInitializeSurface()

0 commit comments

Comments
 (0)