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

Handle null pointers in Cursor constructors #233

Merged
merged 1 commit into from
Oct 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/SFML.Window/Cursor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,14 @@ public enum CursorType
/// the operating system.
/// </summary>
/// <param name="type">System cursor type</param>
/// <exception cref="LoadingFailedException" />
public Cursor(CursorType type)
: base(sfCursor_createFromSystem(type))
{
if (CPointer == IntPtr.Zero)
{
throw new LoadingFailedException("cursor");
eXpl0it3r marked this conversation as resolved.
Show resolved Hide resolved
}
}

/// <summary>
Expand Down Expand Up @@ -152,6 +157,7 @@ public Cursor(CursorType type)
/// <param name="pixels">Array of pixels of the image</param>
/// <param name="size">Width and height of the image</param>
/// <param name="hotspot">(x,y) location of the hotspot</param>
/// <exception cref="LoadingFailedException" />
public Cursor(byte[] pixels, SFML.System.Vector2u size, SFML.System.Vector2u hotspot)
: base((IntPtr)0)
{
Expand All @@ -162,6 +168,11 @@ public Cursor(byte[] pixels, SFML.System.Vector2u size, SFML.System.Vector2u hot
CPointer = sfCursor_createFromPixels((IntPtr)ptr, size, hotspot);
}
}

if (CPointer == IntPtr.Zero)
{
throw new LoadingFailedException("cursor");
}
}

////////////////////////////////////////////////////////////
Expand Down