From 886e3bb42f94104bb5caecaba6d2656adf00ec3e Mon Sep 17 00:00:00 2001 From: bjorn Date: Mon, 19 Dec 2022 14:00:02 -0800 Subject: [PATCH] Fix some windows warnings; --- CMakeLists.txt | 10 +++++++++- deps/msdfgen | 2 +- src/api/l_data_blob.c | 7 ++++--- src/api/l_data_modelData.c | 8 ++++---- src/api/l_event.c | 2 +- src/modules/data/sound.c | 2 +- 6 files changed, 20 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2c85f037..d9aa740a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -59,6 +59,8 @@ if(EMSCRIPTEN) set(LOVR_USE_OPENXR OFF) set(LOVR_USE_WEBGPU ON) set(LOVR_USE_VULKAN OFF) +elseif(MSVC) + add_compile_options(/MP) elseif(ANDROID) find_package(Java REQUIRED) set(LOVR_USE_DESKTOP OFF) @@ -110,6 +112,11 @@ if(LOVR_USE_LUAJIT AND NOT EMSCRIPTEN) else() add_subdirectory(deps/luajit luajit) set_target_properties(luajit PROPERTIES EXCLUDE_FROM_ALL 1) + if(MSVC) + target_compile_definitions(libluajit PRIVATE _CRT_SECURE_NO_WARNINGS) + target_compile_definitions(minilua PRIVATE _CRT_SECURE_NO_WARNINGS) + target_compile_definitions(buildvm PRIVATE _CRT_SECURE_NO_WARNINGS) + endif() include_directories(deps/luajit/src ${CMAKE_BINARY_DIR}/luajit) set(LOVR_LUA libluajit) endif() @@ -623,11 +630,12 @@ if(WIN32) target_sources(lovr PRIVATE src/core/os_win32.c) target_sources(lovr PRIVATE etc/lovr.rc) if (MSVC) - set_target_properties(lovr PROPERTIES COMPILE_FLAGS "/wd4244 /MP") + set_target_properties(lovr PROPERTIES COMPILE_FLAGS /wd4244) # Excuse anonymous union for type punning set_source_files_properties(src/util.c src/modules/graphics/graphics.c PROPERTIES COMPILE_FLAGS /wd4116) # Excuse unsigned negation for flag-magic bit math set_source_files_properties(src/modules/audio/audio.c PROPERTIES COMPILE_FLAGS /wd4146) + set_source_files_properties(src/lib/minimp3/minimp3.c PROPERTIES COMPILE_FLAGS /wd4267) else() set_target_properties(lovr PROPERTIES COMPILE_FLAGS "-MP") endif() diff --git a/deps/msdfgen b/deps/msdfgen index 3f77ce6a..6f7eda06 160000 --- a/deps/msdfgen +++ b/deps/msdfgen @@ -1 +1 @@ -Subproject commit 3f77ce6ac70e8e558e18f638a77b5bcbbf31ca06 +Subproject commit 6f7eda06adc23bc14ca2e14190d69ae1d00f1740 diff --git a/src/api/l_data_blob.c b/src/api/l_data_blob.c index 13c6e395..ccabe18f 100644 --- a/src/api/l_data_blob.c +++ b/src/api/l_data_blob.c @@ -26,10 +26,11 @@ static int l_lovrBlobGetString(lua_State* L) { uint32_t offset = luax_optu32(L, 2, 0); lovrCheck(offset < blob->size, "Blob byte offset must be less than the size of the Blob"); - uint32_t length = luax_optu32(L, 3, blob->size - offset); - lovrCheck(length <= blob->size - offset, "Blob:getString range overflows the length of the Blob"); + lua_Integer length = luaL_optinteger(L, 3, blob->size - offset); + lovrCheck(length >= 0, "Length can not be negative"); + lovrCheck((size_t) length <= blob->size - offset, "Blob:getString range overflows the length of the Blob"); - lua_pushlstring(L, (char*) blob->data + offset, length); + lua_pushlstring(L, (char*) blob->data + offset, (size_t) length); return 1; } diff --git a/src/api/l_data_modelData.c b/src/api/l_data_modelData.c index 9f2553f7..8fcea6df 100644 --- a/src/api/l_data_modelData.c +++ b/src/api/l_data_modelData.c @@ -386,7 +386,7 @@ static int l_lovrModelDataGetMeshVertex(lua_State* L) { ModelAttribute* attribute = mesh->attributes[i]; if (!attribute) continue; - uint32_t stride = model->buffers[attribute->buffer].stride; + size_t stride = model->buffers[attribute->buffer].stride; if (!stride) { switch (attribute->type) { @@ -697,9 +697,9 @@ static int l_lovrModelDataGetAnimationKeyframe(lua_State* L) { uint32_t keyframe = luax_checku32(L, 4) - 1; lovrCheck(keyframe < channel->keyframeCount, "Invalid keyframe index '%d'", keyframe + 1); lua_pushnumber(L, channel->times[keyframe]); - size_t counts[] = { [PROP_TRANSLATION] = 3, [PROP_ROTATION] = 4, [PROP_SCALE] = 3 }; - size_t count = counts[channel->property]; - for (uint32_t i = 0; i < count; i++) { + int counts[] = { [PROP_TRANSLATION] = 3, [PROP_ROTATION] = 4, [PROP_SCALE] = 3 }; + int count = counts[channel->property]; + for (int i = 0; i < count; i++) { lua_pushnumber(L, channel->data[keyframe * count + i]); } return count + 1; diff --git a/src/api/l_event.c b/src/api/l_event.c index 93bfef91..ac6a1920 100644 --- a/src/api/l_event.c +++ b/src/api/l_event.c @@ -45,7 +45,7 @@ void luax_checkvariant(lua_State* L, int index, Variant* variant) { const char* string = lua_tolstring(L, index, &length); if (length <= sizeof(variant->value.ministring.data)) { variant->type = TYPE_MINISTRING; - variant->value.ministring.length = length; + variant->value.ministring.length = (uint8_t) length; memcpy(variant->value.ministring.data, string, length); } else { variant->type = TYPE_STRING; diff --git a/src/modules/data/sound.c b/src/modules/data/sound.c index 475d0d4a..fa3589e1 100644 --- a/src/modules/data/sound.c +++ b/src/modules/data/sound.c @@ -138,7 +138,7 @@ static bool loadOgg(Sound* sound, Blob* blob, bool decode) { void* data = calloc(1, size); lovrAssert(data, "Out of memory"); sound->blob = lovrBlobCreate(data, size, "Sound"); - if (stb_vorbis_get_samples_float_interleaved(sound->decoder, channels, data, size / sizeof(float)) < (int) sound->frames) { + if (stb_vorbis_get_samples_float_interleaved(sound->decoder, channels, data, (int) size / sizeof(float)) < (int) sound->frames) { lovrThrow("Could not decode vorbis from '%s'", blob->name); } stb_vorbis_close(sound->decoder);