3 Commits

4 changed files with 43 additions and 29 deletions

View File

@ -916,6 +916,8 @@ int GetCurrentMonitor(void)
// Get selected monitor position // Get selected monitor position
Vector2 GetMonitorPosition(int monitor) Vector2 GetMonitorPosition(int monitor)
{ {
Vector2 position = { 0 };
int monitorCount = 0; int monitorCount = 0;
GLFWmonitor **monitors = glfwGetMonitors(&monitorCount); GLFWmonitor **monitors = glfwGetMonitors(&monitorCount);
@ -925,10 +927,11 @@ Vector2 GetMonitorPosition(int monitor)
int y = 0; int y = 0;
glfwGetMonitorPos(monitors[monitor], &x, &y); glfwGetMonitorPos(monitors[monitor], &x, &y);
return (Vector2){ (float)x, (float)y }; position = (Vector2){ (float)x, (float)y };
} }
else TRACELOG(LOG_WARNING, "GLFW: Failed to find selected monitor"); else TRACELOG(LOG_WARNING, "GLFW: Failed to find selected monitor");
return (Vector2){ 0, 0 };
return position;
} }
// Get selected monitor width (currently used by monitor) // Get selected monitor width (currently used by monitor)
@ -1018,31 +1021,39 @@ int GetMonitorRefreshRate(int monitor)
// Get the human-readable, UTF-8 encoded name of the selected monitor // Get the human-readable, UTF-8 encoded name of the selected monitor
const char *GetMonitorName(int monitor) const char *GetMonitorName(int monitor)
{ {
const char *name = NULL;
int monitorCount = 0; int monitorCount = 0;
GLFWmonitor **monitors = glfwGetMonitors(&monitorCount); GLFWmonitor **monitors = glfwGetMonitors(&monitorCount);
if ((monitor >= 0) && (monitor < monitorCount)) if ((monitor >= 0) && (monitor < monitorCount))
{ {
return glfwGetMonitorName(monitors[monitor]); name = glfwGetMonitorName(monitors[monitor]);
} }
else TRACELOG(LOG_WARNING, "GLFW: Failed to find selected monitor"); else TRACELOG(LOG_WARNING, "GLFW: Failed to find selected monitor");
return "";
return name;
} }
// Get window position XY on monitor // Get window position XY on monitor
Vector2 GetWindowPosition(void) Vector2 GetWindowPosition(void)
{ {
glfwGetWindowPos(platform.handle, &CORE.Window.position.x, &CORE.Window.position.y); Vector2 position = { 0 };
return (Vector2){ (float)CORE.Window.position.x, (float)CORE.Window.position.y }; glfwGetWindowPos(platform.handle, &CORE.Window.position.x, &CORE.Window.position.y);
position = (Vector2){ (float)CORE.Window.position.x, (float)CORE.Window.position.y };
return position;
} }
// Get window scale DPI factor for current monitor // Get window scale DPI factor for current monitor
Vector2 GetWindowScaleDPI(void) Vector2 GetWindowScaleDPI(void)
{ {
Vector2 scale = { 1.0f, 1.0f }; Vector2 scale = { 1.0f, 1.0f };
if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIGHDPI) && !FLAG_IS_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE)) if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIGHDPI) && !FLAG_IS_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE))
glfwGetWindowContentScale(platform.handle, &scale.x, &scale.y); glfwGetWindowContentScale(platform.handle, &scale.x, &scale.y);
return scale; return scale;
} }

View File

@ -810,11 +810,9 @@ Wave LoadWaveFromMemory(const char *fileType, const unsigned char *fileData, int
{ {
Wave wave = { 0 }; Wave wave = { 0 };
if (fileType == NULL) // Security checks for input data
{ if ((fileData == NULL) || (dataSize <= 0)) { TRACELOG(LOG_WARNING, "WAVE: Invalid file data"); return wave; }
TRACELOG(LOG_WARNING, "WAVE: Missing file extension"); if (fileType == NULL) { TRACELOG(LOG_WARNING, "WAVE: Missing file extension"); return wave; }
return wave;
}
if (false) { } if (false) { }
#if SUPPORT_FILEFORMAT_WAV #if SUPPORT_FILEFORMAT_WAV
@ -1551,6 +1549,10 @@ Music LoadMusicStreamFromMemory(const char *fileType, const unsigned char *data,
Music music = { 0 }; Music music = { 0 };
bool musicLoaded = false; bool musicLoaded = false;
// Security checks for input data
if ((data == NULL) || (dataSize <= 0)) { TRACELOG(LOG_WARNING, "MUSIC: Invalid file data"); return music; }
if (fileType == NULL) { TRACELOG(LOG_WARNING, "MUSIC: Missing file extension"); return music; }
if (false) { } if (false) { }
#if SUPPORT_FILEFORMAT_WAV #if SUPPORT_FILEFORMAT_WAV
else if ((strcmp(fileType, ".wav") == 0) || (strcmp(fileType, ".WAV") == 0)) else if ((strcmp(fileType, ".wav") == 0) || (strcmp(fileType, ".WAV") == 0))

View File

@ -2630,21 +2630,30 @@ RMAPI Vector3 QuaternionToEuler(Quaternion q)
{ {
Vector3 result = { 0 }; Vector3 result = { 0 };
// Roll (x-axis rotation)
float x0 = 2.0f*(q.w*q.x + q.y*q.z);
float x1 = 1.0f - 2.0f*(q.x*q.x + q.y*q.y);
result.x = atan2f(x0, x1);
// Pitch (y-axis rotation) // Pitch (y-axis rotation)
float y0 = 2.0f*(q.w*q.y - q.z*q.x); float y0 = 2.0f*(q.w*q.y - q.z*q.x);
y0 = y0 > 1.0f ? 1.0f : y0; y0 = y0 > 1.0f ? 1.0f : y0;
y0 = y0 < -1.0f ? -1.0f : y0; y0 = y0 < -1.0f ? -1.0f : y0;
result.y = asinf(y0); result.y = asinf(y0);
if (fabsf(y0) >= 0.9999995f)
{
// Gimbal lock: roll and yaw turn about the same axis, keep the whole turn in roll
float sign = (q.w < 0.0f)? -1.0f : 1.0f;
result.x = 2.0f*atan2f(sign*q.x, sign*q.w);
}
else
{
// Roll (x-axis rotation)
float x0 = 2.0f*(q.w*q.x + q.y*q.z);
float x1 = 1.0f - 2.0f*(q.x*q.x + q.y*q.y);
result.x = atan2f(x0, x1);
// Yaw (z-axis rotation) // Yaw (z-axis rotation)
float z0 = 2.0f*(q.w*q.z + q.x*q.y); float z0 = 2.0f*(q.w*q.z + q.x*q.y);
float z1 = 1.0f - 2.0f*(q.y*q.y + q.z*q.z); float z1 = 1.0f - 2.0f*(q.y*q.y + q.z*q.z);
result.z = atan2f(z0, z1); result.z = atan2f(z0, z1);
}
return result; return result;
} }

View File

@ -423,16 +423,8 @@ Image LoadImageFromMemory(const char *fileType, const unsigned char *fileData, i
Image image = { 0 }; Image image = { 0 };
// Security checks for input data // Security checks for input data
if ((fileData == NULL) || (dataSize == 0)) if ((fileData == NULL) || (dataSize == 0)) { TRACELOG(LOG_WARNING, "IMAGE: Invalid file data"); return image; }
{ if (fileType == NULL) { TRACELOG(LOG_WARNING, "IMAGE: Missing file extension"); return image; }
TRACELOG(LOG_WARNING, "IMAGE: Invalid file data");
return image;
}
if (fileType == NULL)
{
TRACELOG(LOG_WARNING, "IMAGE: Missing file extension");
return image;
}
if ((false) if ((false)
#if SUPPORT_FILEFORMAT_PNG #if SUPPORT_FILEFORMAT_PNG