From df249f5513465dfa2662fd566f79f5dfb23960eb Mon Sep 17 00:00:00 2001 From: Jeffery Myers Date: Sun, 29 Nov 2020 23:14:11 -0800 Subject: [PATCH] Fix typecast warnings in raylib code as reported by visual studio 2019 (#1443) --- src/core.c | 2 +- src/models.c | 12 ++++++------ src/raudio.c | 8 ++++---- src/textures.c | 48 ++++++++++++++++++++++++------------------------ 4 files changed, 35 insertions(+), 35 deletions(-) diff --git a/src/core.c b/src/core.c index cacfd450..5de15394 100644 --- a/src/core.c +++ b/src/core.c @@ -4461,7 +4461,7 @@ static void KeyCallback(GLFWwindow *window, int key, int scancode, int action, i strcpy(path, TextFormat("./screenrec%03i.gif", screenshotCounter)); #endif - SaveFileData(path, result.data, result.dataSize); + SaveFileData(path, result.data, (unsigned int)result.dataSize); msf_gif_free(result); #if defined(PLATFORM_WEB) diff --git a/src/models.c b/src/models.c index ab3ea7f7..04db669e 100644 --- a/src/models.c +++ b/src/models.c @@ -830,10 +830,10 @@ bool ExportMesh(Mesh mesh, const char *fileName) if (IsFileExtension(fileName, ".obj")) { // Estimated data size, it should be enough... - int dataSize = mesh.vertexCount/3*strlen("v 0000.00f 0000.00f 0000.00f") + - mesh.vertexCount/2*strlen("vt 0.000f 0.00f") + - mesh.vertexCount/3*strlen("vn 0.000f 0.00f 0.00f") + - mesh.triangleCount/3*strlen("f 00000/00000/00000 00000/00000/00000 00000/00000/00000"); + int dataSize = mesh.vertexCount/3* (int)strlen("v 0000.00f 0000.00f 0000.00f") + + mesh.vertexCount/2* (int)strlen("vt 0.000f 0.00f") + + mesh.vertexCount/3* (int)strlen("vn 0.000f 0.00f 0.00f") + + mesh.triangleCount/3* (int)strlen("f 00000/00000/00000 00000/00000/00000 00000/00000/00000"); // NOTE: Text data buffer size is estimated considering mesh data size char *txtData = (char *)RL_CALLOC(dataSize + 2000, sizeof(char)); @@ -2997,9 +2997,9 @@ static Model LoadOBJ(const char *fileName) // count the faces for each material int *matFaces = RL_CALLOC(meshCount, sizeof(int)); - for (int mi = 0; mi < meshCount; mi++) + for (unsigned int mi = 0; mi < meshCount; mi++) { - for (int fi = 0; fi < meshes[mi].length; fi++) + for (unsigned int fi = 0; fi < meshes[mi].length; fi++) { int idx = attrib.material_ids[meshes[mi].face_offset + fi]; if (idx == -1) idx = 0; // for no material face (which could be the whole model) diff --git a/src/raudio.c b/src/raudio.c index 7e6e0f30..ec24a1ee 100644 --- a/src/raudio.c +++ b/src/raudio.c @@ -1929,7 +1929,7 @@ static Wave LoadWAV(const unsigned char *fileData, unsigned int fileSize) if (success) { - wave.sampleCount = wav.totalPCMFrameCount*wav.channels; + wave.sampleCount = (unsigned int)wav.totalPCMFrameCount*wav.channels; wave.sampleRate = wav.sampleRate; wave.sampleSize = 16; // NOTE: We are forcing conversion to 16bit wave.channels = wav.channels; @@ -1958,12 +1958,12 @@ static int SaveWAV(Wave wave, const char *fileName) format.bitsPerSample = wave.sampleSize; unsigned char *fileData = NULL; - unsigned int fileDataSize = 0; + size_t fileDataSize = 0; success = drwav_init_memory_write(&wav, &fileData, &fileDataSize, &format, NULL); - if (success) success = drwav_write_pcm_frames(&wav, wave.sampleCount/wave.channels, wave.data); + if (success) success = (int)drwav_write_pcm_frames(&wav, wave.sampleCount/wave.channels, wave.data); drwav_result result = drwav_uninit(&wav); - if (result == DRWAV_SUCCESS) success = SaveFileData(fileName, fileData, fileDataSize); + if (result == DRWAV_SUCCESS) success = SaveFileData(fileName, fileData, (unsigned int)fileDataSize); drwav_free(fileData, NULL); diff --git a/src/textures.c b/src/textures.c index a26c0ddc..cf51882a 100644 --- a/src/textures.c +++ b/src/textures.c @@ -812,9 +812,9 @@ Image ImageFromImage(Image image, Rectangle rec) // TODO: Check rec is valid? - result.width = rec.width; - result.height = rec.height; - result.data = RL_CALLOC(rec.width*rec.height*bytesPerPixel, 1); + result.width = (int)rec.width; + result.height = (int)rec.height; + result.data = RL_CALLOC((int)(rec.width*rec.height)*bytesPerPixel, 1); result.format = image.format; result.mipmaps = 1; @@ -850,7 +850,7 @@ void ImageCrop(Image *image, Rectangle crop) { int bytesPerPixel = GetPixelDataSize(1, 1, image->format); - unsigned char *croppedData = (unsigned char *)RL_MALLOC(crop.width*crop.height*bytesPerPixel); + unsigned char *croppedData = (unsigned char *)RL_MALLOC((int)(crop.width*crop.height)*bytesPerPixel); // OPTION 1: Move cropped data line-by-line for (int y = (int)crop.y, offsetSize = 0; y < (int)(crop.y + crop.height); y++) @@ -1438,27 +1438,27 @@ void ImageResizeCanvas(Image *image, int newWidth, int newHeight, int offsetX, i if (image->format >= COMPRESSED_DXT1_RGB) TRACELOG(LOG_WARNING, "Image manipulation not supported for compressed formats"); else if ((newWidth != image->width) || (newHeight != image->height)) { - Rectangle srcRec = { 0, 0, image->width, image->height }; - Vector2 dstPos = { offsetX, offsetY }; + Rectangle srcRec = { 0, 0, (float)image->width, (float)image->height }; + Vector2 dstPos = { (float)offsetX, (float)offsetY }; if (offsetX < 0) { - srcRec.x = -offsetX; - srcRec.width += offsetX; + srcRec.x = (float)-offsetX; + srcRec.width += (float)offsetX; dstPos.x = 0; } - else if ((offsetX + image->width) > newWidth) srcRec.width = newWidth - offsetX; + else if ((offsetX + image->width) > newWidth) srcRec.width = (float)(newWidth - offsetX); if (offsetY < 0) { - srcRec.y = -offsetY; - srcRec.height += offsetY; + srcRec.y = (float)-offsetY; + srcRec.height += (float)offsetY; dstPos.y = 0; } - else if ((offsetY + image->height) > newHeight) srcRec.height = newHeight - offsetY; + else if ((offsetY + image->height) > newHeight) srcRec.height = (float)(newHeight - offsetY); - if (newWidth < srcRec.width) srcRec.width = newWidth; - if (newHeight < srcRec.height) srcRec.height = newHeight; + if (newWidth < srcRec.width) srcRec.width = (float)newWidth; + if (newHeight < srcRec.height) srcRec.height = (float)newHeight; int bytesPerPixel = GetPixelDataSize(1, 1, image->format); unsigned char *resizedData = (unsigned char *)RL_CALLOC(newWidth*newHeight*bytesPerPixel, 1); @@ -2570,7 +2570,7 @@ void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec, Color { srcMod = ImageFromImage(src, srcRec); // Create image from another image ImageResize(&srcMod, (int)dstRec.width, (int)dstRec.height); // Resize to destination rectangle - srcRec = (Rectangle){ 0, 0, srcMod.width, srcMod.height }; + srcRec = (Rectangle){ 0, 0, (float)srcMod.width, (float)srcMod.height }; srcPtr = &srcMod; useSrcMod = true; @@ -2593,8 +2593,8 @@ void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec, Color } else if ((dstRec.y + srcRec.height) > dst->height) srcRec.height = dst->height - dstRec.y; - if (dst->width < srcRec.width) srcRec.width = dst->width; - if (dst->height < srcRec.height) srcRec.height = dst->height; + if (dst->width < srcRec.width) srcRec.width = (float)dst->width; + if (dst->height < srcRec.height) srcRec.height = (float)dst->height; // This blitting method is quite fast! The process followed is: // for every pixel -> [get_src_format/get_dst_format -> blend -> format_to_dst] @@ -2628,7 +2628,7 @@ void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec, Color unsigned char *pDst = pDstBase; // Fast path: Avoid moving pixel by pixel if no blend required and same format - if (!blendRequired && (srcPtr->format == dst->format)) memcpy(pDst, pSrc, srcRec.width*bytesPerPixelSrc); + if (!blendRequired && (srcPtr->format == dst->format)) memcpy(pDst, pSrc, (int)(srcRec.width)*bytesPerPixelSrc); else { for (int x = 0; x < (int)srcRec.width; x++) @@ -3080,7 +3080,7 @@ void DrawTextureTiled(Texture2D texture, Rectangle sourceRec, Rectangle destRec, { if (texture.id <= 0 || scale <= 0.0f) return; // Wanna see a infinite loop?!...just delete this line! - int tileWidth = sourceRec.width*scale, tileHeight = sourceRec.height*scale; + int tileWidth = (int)(sourceRec.width*scale), tileHeight = (int)(sourceRec.height*scale); if (destRec.width < tileWidth && destRec.height < tileHeight) { // Can fit only one tile @@ -3093,7 +3093,7 @@ void DrawTextureTiled(Texture2D texture, Rectangle sourceRec, Rectangle destRec, int dy = 0; for (;dy+tileHeight < destRec.height; dy += tileHeight) { - DrawTexturePro(texture, (Rectangle){sourceRec.x, sourceRec.y, ((float)destRec.width/tileWidth)*sourceRec.width, sourceRec.height}, (Rectangle){destRec.x, destRec.y + dy, destRec.width, tileHeight}, origin, rotation, tint); + DrawTexturePro(texture, (Rectangle){sourceRec.x, sourceRec.y, ((float)destRec.width/tileWidth)*sourceRec.width, sourceRec.height}, (Rectangle){destRec.x, destRec.y + dy, destRec.width, (float)tileHeight}, origin, rotation, tint); } // Fit last tile @@ -3109,7 +3109,7 @@ void DrawTextureTiled(Texture2D texture, Rectangle sourceRec, Rectangle destRec, int dx = 0; for (;dx+tileWidth < destRec.width; dx += tileWidth) { - DrawTexturePro(texture, (Rectangle){sourceRec.x, sourceRec.y, sourceRec.width, ((float)destRec.height/tileHeight)*sourceRec.height}, (Rectangle){destRec.x + dx, destRec.y, tileWidth, destRec.height}, origin, rotation, tint); + DrawTexturePro(texture, (Rectangle){sourceRec.x, sourceRec.y, sourceRec.width, ((float)destRec.height/tileHeight)*sourceRec.height}, (Rectangle){destRec.x + dx, destRec.y, (float)tileWidth, destRec.height}, origin, rotation, tint); } // Fit last tile @@ -3128,13 +3128,13 @@ void DrawTextureTiled(Texture2D texture, Rectangle sourceRec, Rectangle destRec, int dy = 0; for (;dy+tileHeight < destRec.height; dy += tileHeight) { - DrawTexturePro(texture, sourceRec, (Rectangle){destRec.x + dx, destRec.y + dy, tileWidth, tileHeight}, origin, rotation, tint); + DrawTexturePro(texture, sourceRec, (Rectangle){destRec.x + dx, destRec.y + dy, (float)tileWidth, (float)tileHeight}, origin, rotation, tint); } if (dy < destRec.height) { DrawTexturePro(texture, (Rectangle){sourceRec.x, sourceRec.y, sourceRec.width, ((float)(destRec.height - dy)/tileHeight)*sourceRec.height}, - (Rectangle){destRec.x + dx, destRec.y + dy, tileWidth, destRec.height - dy}, origin, rotation, tint); + (Rectangle){destRec.x + dx, destRec.y + dy, (float)tileWidth, destRec.height - dy}, origin, rotation, tint); } } @@ -3145,7 +3145,7 @@ void DrawTextureTiled(Texture2D texture, Rectangle sourceRec, Rectangle destRec, for (;dy+tileHeight < destRec.height; dy += tileHeight) { DrawTexturePro(texture, (Rectangle){sourceRec.x, sourceRec.y, ((float)(destRec.width - dx)/tileWidth)*sourceRec.width, sourceRec.height}, - (Rectangle){destRec.x + dx, destRec.y + dy, destRec.width - dx, tileHeight}, origin, rotation, tint); + (Rectangle){destRec.x + dx, destRec.y + dy, destRec.width - dx, (float)tileHeight}, origin, rotation, tint); } // Draw final tile in the bottom right corner