From 06eb9bb2432de621bb6d61e8161d0f87ce7ce9ce Mon Sep 17 00:00:00 2001 From: Aaron Colwell <300262+acolwell@users.noreply.github.com> Date: Tue, 1 Oct 2024 16:57:41 -0700 Subject: [PATCH] Fix warnings and MSVC errors (#991) * Fix HostOverlay enum to bool cast. * Fix warnings and MSVC compiler errors. --- CMakeLists.txt | 6 ++- Engine/CLArgs.cpp | 4 ++ Engine/CMakeLists.txt | 2 +- Engine/HostOverlaySupport.h | 2 + Engine/Knob.h | 8 ---- Engine/KnobImpl.h | 7 +-- Engine/NodeGroup.cpp | 4 +- Engine/NodePrivate.h | 1 + Engine/StandardPaths.cpp | 2 +- Engine/Timer.h | 2 +- Engine/TrackerContext.cpp | 1 + Global/Macros.h | 3 ++ Global/ProcInfo.cpp | 6 ++- Gui/CMakeLists.txt | 2 +- Gui/FileTypeMainWindow_win.cpp | 3 +- Gui/HostOverlay.cpp | 83 ++++++++++------------------------ Tests/OSGLContext_Test.cpp | 11 +++++ 17 files changed, 68 insertions(+), 79 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 47ac24840..13c18c12a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -83,7 +83,11 @@ set(QTWIDGETS_INCLUDE_DIRS ${Qt5Widgets_INCLUDE_DIRS}) #for QString(const char*) assumes ASCII strings, we may run into troubles add_compile_definitions(QT_NO_CAST_FROM_ASCII) -if (NOT MSVC) +if (MSVC) + # Allow __cplusplus to properly reflect the c++ standard version. + add_compile_options(/Zc:__cplusplus) + add_compile_definitions(__STDC_LIMIT_MACROS WIN32_LEAN_AND_MEAN _USE_MATH_DEFINES) +else() SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-prototypes" ) add_compile_options(-Wall -Wextra -Wmissing-declarations -Wno-multichar -Winit-self -Wno-long-long -Wvla -Wdate-time -Wshift-overflow=2 diff --git a/Engine/CLArgs.cpp b/Engine/CLArgs.cpp index 649c9d3f5..c5f6dd61e 100644 --- a/Engine/CLArgs.cpp +++ b/Engine/CLArgs.cpp @@ -31,6 +31,10 @@ #include #include +#ifdef __NATRON_WIN32__ +#include // CommandLineToArgvW +#endif + #include #include #include diff --git a/Engine/CMakeLists.txt b/Engine/CMakeLists.txt index dfd0ae1fc..bd9eebda1 100644 --- a/Engine/CMakeLists.txt +++ b/Engine/CMakeLists.txt @@ -110,7 +110,7 @@ target_include_directories(NatronEngine ) target_compile_definitions(NatronEngine PRIVATE - NATRON_CUSTOM_BUILD_USER_TOKEN=${BUILD_USER_NAME} + NATRON_CUSTOM_BUILD_USER_TOKEN="${BUILD_USER_NAME}" NATRON_BUILD_NUMBER=0 ${XDG_DEFS} ) diff --git a/Engine/HostOverlaySupport.h b/Engine/HostOverlaySupport.h index ef4bbd0d3..b34d0a1be 100644 --- a/Engine/HostOverlaySupport.h +++ b/Engine/HostOverlaySupport.h @@ -26,6 +26,8 @@ #include // ***** END PYTHON BLOCK ***** +#include + #include "Global/Macros.h" #include "Engine/EngineFwd.h" diff --git a/Engine/Knob.h b/Engine/Knob.h index b27268840..27d82d106 100644 --- a/Engine/Knob.h +++ b/Engine/Knob.h @@ -1938,12 +1938,6 @@ class Knob ViewSpec view, int dimension); - /** - * @brief This is called by the plugin when a set value call would happen during an interact action. - **/ - void requestSetValueOnUndoStack(const T & value, - ViewSpec view, - int dimension); /** * @brief Calls setValueAtTime with a reason of eValueChangedReasonNatronInternalEdited. @@ -2147,8 +2141,6 @@ class Knob void makeKeyFrame(Curve* curve, double time, ViewSpec view, const T& v, KeyFrame* key); - void queueSetValue(const T& v, ViewSpec view, int dimension); - virtual void clearExpressionsResults(int dimension) OVERRIDE FINAL { QMutexLocker k(&_valueMutex); diff --git a/Engine/KnobImpl.h b/Engine/KnobImpl.h index 153a829d9..9df9943c9 100644 --- a/Engine/KnobImpl.h +++ b/Engine/KnobImpl.h @@ -2588,9 +2588,10 @@ Knob::copyValueForTypeAndCheckIfChanged(Knob* other, int dimMin = std::min( getDimension(), other->getDimension() ); std::vector v = other->getValueForEachDimension_mt_safe_vector(); for (int i = 0; i < dimMin; ++i) { - if (_values[i] != v[i]) { - _values[i] = v[i]; - _guiValues[i] = v[i]; + const T convertedV = static_cast(v[i]); + if (_values[i] != convertedV) { + _values[i] = convertedV; + _guiValues[i] = convertedV; ret = true; } } diff --git a/Engine/NodeGroup.cpp b/Engine/NodeGroup.cpp index ab0cfd5ef..609d36592 100644 --- a/Engine/NodeGroup.cpp +++ b/Engine/NodeGroup.cpp @@ -2836,12 +2836,12 @@ NodeCollection::exportGroupToPython(const QString& pluginID, WRITE_STATIC_LINE(NATRON_PYPLUG_MAGIC); QString descline = QString( QString::fromUtf8(NATRON_PYPLUG_GENERATED "%1 PyPlug exporter version %2.") ).arg( QString::fromUtf8(NATRON_APPLICATION_NAME) ).arg(NATRON_PYPLUG_EXPORTER_VERSION); WRITE_STRING(descline); - WRITE_STATIC_LINE(); + WRITE_STATIC_LINE(""); QString handWrittenStr = QString::fromUtf8("# Hand-written code should be added in a separate file named %1.py").arg(extModule); WRITE_STRING(handWrittenStr); WRITE_STATIC_LINE("# See http://natron.readthedocs.org/en/master/devel/groups.html#adding-hand-written-code-callbacks-etc"); WRITE_STATIC_LINE("# Note that Viewers are never exported"); - WRITE_STATIC_LINE(); + WRITE_STATIC_LINE(""); WRITE_STATIC_LINE("import " NATRON_ENGINE_PYTHON_MODULE_NAME); WRITE_STATIC_LINE("import sys"); WRITE_STATIC_LINE(""); diff --git a/Engine/NodePrivate.h b/Engine/NodePrivate.h index 06c8528b5..d78813a1b 100644 --- a/Engine/NodePrivate.h +++ b/Engine/NodePrivate.h @@ -29,6 +29,7 @@ #include "Global/Macros.h" #include "Node.h" +#include "Timer.h" // gettimeofday() #include #include diff --git a/Engine/StandardPaths.cpp b/Engine/StandardPaths.cpp index 8c95536c6..ae7549246 100644 --- a/Engine/StandardPaths.cpp +++ b/Engine/StandardPaths.cpp @@ -37,7 +37,7 @@ #include // for Q_OS_* #if defined(Q_OS_WIN) -#include +#include #include #include #ifndef CSIDL_MYMUSIC diff --git a/Engine/Timer.h b/Engine/Timer.h index e4de35988..ae58ae72a 100644 --- a/Engine/Timer.h +++ b/Engine/Timer.h @@ -35,7 +35,7 @@ //---------------------------------------------------------------------------- #if defined(__NATRON_WIN32__) && !defined(__NATRON_MINGW__) -#include +#include #else #include #endif diff --git a/Engine/TrackerContext.cpp b/Engine/TrackerContext.cpp index 4461dffde..0ddad33c3 100644 --- a/Engine/TrackerContext.cpp +++ b/Engine/TrackerContext.cpp @@ -46,6 +46,7 @@ CLANG_DIAG_ON(uninitialized) #include "Engine/KnobTypes.h" #include "Engine/Project.h" #include "Engine/Curve.h" +#include "Engine/Timer.h" // gettimeofday() #include "Engine/TLSHolder.h" #include "Engine/Transform.h" #include "Engine/TrackMarker.h" diff --git a/Global/Macros.h b/Global/Macros.h index f0018890a..4462278f5 100644 --- a/Global/Macros.h +++ b/Global/Macros.h @@ -455,6 +455,9 @@ GCC_ONLY_DIAG_OFF(pragmas) // warning: unknown option after '#pragma GCC diagno ///////////////////////////////////////////////////////////////////////////////////////////// /* COMPILER() - the compiler being used to build the project */ +#ifdef COMPILER +#undef COMPILER +#endif #define COMPILER(NATRON_FEATURE) (NATRON_COMPILER_ ## NATRON_FEATURE) /* COMPILER_SUPPORTS() - whether the compiler being used to build the project supports the given feature. */ diff --git a/Global/ProcInfo.cpp b/Global/ProcInfo.cpp index c03ff98a8..244423077 100644 --- a/Global/ProcInfo.cpp +++ b/Global/ProcInfo.cpp @@ -38,6 +38,10 @@ #include // strdup #endif +#ifdef __NATRON_WIN32__ +#include // CommandLineToArgvW +#endif + #include "StrUtils.h" NATRON_NAMESPACE_ENTER @@ -499,7 +503,7 @@ ProcInfo::getenv_wrapper(const char *varName) std::vector buffer; getenv_s(&requiredSize, 0, 0, varName); if (requiredSize == 0) - return buffer; + return std::string(); buffer.resize(requiredSize); getenv_s(&requiredSize, &buffer[0], requiredSize, varName); // requiredSize includes the terminating null, which we don't want. diff --git a/Gui/CMakeLists.txt b/Gui/CMakeLists.txt index 68c7e248e..d20159d93 100644 --- a/Gui/CMakeLists.txt +++ b/Gui/CMakeLists.txt @@ -90,7 +90,7 @@ target_include_directories(NatronGui ) target_compile_definitions(NatronGui PRIVATE - NATRON_CUSTOM_BUILD_USER_TOKEN=${BUILD_USER_NAME} + NATRON_CUSTOM_BUILD_USER_TOKEN="${BUILD_USER_NAME}" NATRON_BUILD_NUMBER=0 QT_NO_KEYWORDS ) diff --git a/Gui/FileTypeMainWindow_win.cpp b/Gui/FileTypeMainWindow_win.cpp index 570054f4e..025f0fea1 100644 --- a/Gui/FileTypeMainWindow_win.cpp +++ b/Gui/FileTypeMainWindow_win.cpp @@ -45,7 +45,8 @@ #include // —— general includes ————————————————————————— -#include +#include + #include #include #include diff --git a/Gui/HostOverlay.cpp b/Gui/HostOverlay.cpp index 6395c5e07..922046de8 100644 --- a/Gui/HostOverlay.cpp +++ b/Gui/HostOverlay.cpp @@ -77,6 +77,18 @@ NATRON_NAMESPACE_ENTER // // TODO: This is a bug, there is no reason to not use setValues(). // OpenFX plugins are not affected, because instanceChanged does not pass the dimension information. +namespace { + +void nonBlockingSetValues(Natron::KnobDoublePtr& knob, const double x, const double y, const ValueChangedReasonEnum reason) { + knob->setValue(x, ViewSpec::all(), 0, reason, nullptr); + knob->setValue(y, ViewSpec::all(), 1, reason, nullptr); +} + +inline void nonBlockingSetValues(Natron::KnobDoublePtr& knob, const OfxPointD& point, const ValueChangedReasonEnum reason) { + nonBlockingSetValues(knob, point.x, point.y, reason); +} + +} // namespace DefaultInteractI::DefaultInteractI(HostOverlay* overlay) @@ -994,41 +1006,6 @@ PositionInteract::draw(double time, glTranslated(direction * shadow.x, -direction * shadow.y, 0); glMatrixMode(GL_MODELVIEW); // Modelview should be used on Nuke -#warning TODO -#if 0 - int numKeys = knob->get; - - if (numKeys > 0) { - const double darken = 0.5; - glColor3f(pR * l * darken, pG * l * darken, pB * l * darken); - - glPointSize(pointSize() * screenPixelRatio); - glBegin(GL_POINTS); - for (int i=0; i < numKeys; ++i) { - double time = p->getKeyTime(i); - OfxPointD pt; - p->getValueAtTime(time, pt.x, pt.y); - glVertex2d(pt.x, pt.y); - - } - glEnd(); - glLineWidth(1.5 * screenPixelRatio); - glBegin(GL_LINE_STRIP); - double time = p->getKeyTime(0); - for (int i = 1; i < numKeys; ++i) { - double timeNext = p->getKeyTime(i); - for (int j = (i == 1 ? 0 : 1); j <= steps; ++j) { - double timeStep = time + j * (timeNext - time) / steps; - OfxPointD pt; - p->getValueAtTime(timeStep, pt.x, pt.y); - glVertex2d(pt.x, pt.y); - } - time = timeNext; - } - glEnd(); - } -#endif - glColor3f(pR * l, pG * l, pB * l); glPointSize(pointSize() * screenPixelRatio); glBegin(GL_POINTS); @@ -1750,8 +1727,7 @@ PositionInteract::penMotion(double time, EffectInstancePtr holder = _overlay->getNode()->getNode()->getEffectInstance(); holder->setMultipleParamsEditLevel(KnobHolder::eMultipleParamsEditOnCreateNewCommand); // Do not use setValues(x,y) (see note at the top of this file). - knob->setValue(p[0], ViewSpec::all(), 0, eValueChangedReasonNatronGuiEdited); - knob->setValue(p[1], ViewSpec::all(), 1, eValueChangedReasonNatronGuiEdited); + nonBlockingSetValues(knob, p[0], p[1], eValueChangedReasonNatronGuiEdited); holder->setMultipleParamsEditLevel(KnobHolder::eMultipleParamsEditOff); } @@ -2196,20 +2172,17 @@ TransformInteract::penMotion(double time, if (centerChanged) { KnobDoublePtr knob = _center.lock(); // Do not use setValues(x,y) (see note at the top of this file). - knob->setValue(center.x, ViewSpec::all(), 0, eValueChangedReasonNatronGuiEdited); - knob->setValue(center.y, ViewSpec::all(), 1, eValueChangedReasonNatronGuiEdited); + nonBlockingSetValues(knob, center, eValueChangedReasonNatronGuiEdited); } if (translateChanged) { KnobDoublePtr knob = _translate.lock(); // Do not use setValues(x,y) (see note at the top of this file). - knob->setValue(translate.x, ViewSpec::all(), 0, eValueChangedReasonNatronGuiEdited); - knob->setValue(translate.y, ViewSpec::all(), 1, eValueChangedReasonNatronGuiEdited); + nonBlockingSetValues(knob, translate, eValueChangedReasonNatronGuiEdited); } if (scaleChanged) { KnobDoublePtr knob = _scale.lock(); // Do not use setValues(x,y) (see note at the top of this file). - knob->setValue(scale.x, ViewSpec::all(), 0, eValueChangedReasonNatronGuiEdited); - knob->setValue(scale.y, ViewSpec::all(), 1, eValueChangedReasonNatronGuiEdited); + nonBlockingSetValues(knob, scale, eValueChangedReasonNatronGuiEdited); } if (rotateChanged) { KnobDoublePtr knob = _rotate.lock(); @@ -2330,14 +2303,12 @@ CornerPinInteract::penMotion(double time, KnobDoublePtr knob = _from[_dragging].lock(); assert(knob); // Do not use setValues(x,y) (see note at the top of this file). - knob->setValue(from[_dragging].x, ViewSpec::all(), 0, eValueChangedReasonPluginEdited); - knob->setValue(from[_dragging].y, ViewSpec::all(), 1, eValueChangedReasonPluginEdited); + nonBlockingSetValues(knob, from[_dragging], eValueChangedReasonPluginEdited); } else { KnobDoublePtr knob = _to[_dragging].lock(); assert(knob); // Do not use setValues(x,y) (see note at the top of this file). - knob->setValue(to[_dragging].x, ViewSpec::all(), 0, eValueChangedReasonPluginEdited); - knob->setValue(to[_dragging].y, ViewSpec::all(), 1, eValueChangedReasonPluginEdited); + nonBlockingSetValues(knob, to[_dragging], eValueChangedReasonPluginEdited); } holder->setMultipleParamsEditLevel(KnobHolder::eMultipleParamsEditOff); } @@ -2403,8 +2374,7 @@ PositionInteract::penUp(double time, EffectInstancePtr holder = _overlay->getNode()->getNode()->getEffectInstance(); holder->setMultipleParamsEditLevel(KnobHolder::eMultipleParamsEditOnCreateNewCommand); // Do not use setValues(x,y) (see note at the top of this file). - knob->setValue(p[0], ViewSpec::all(), 0, eValueChangedReasonNatronGuiEdited); - knob->setValue(p[1], ViewSpec::all(), 1, eValueChangedReasonNatronGuiEdited); + nonBlockingSetValues(knob, p[0], p[1], eValueChangedReasonNatronGuiEdited); holder->setMultipleParamsEditLevel(KnobHolder::eMultipleParamsEditOff); } @@ -2441,20 +2411,17 @@ TransformInteract::penUp(double /*time*/, { KnobDoublePtr knob = _center.lock(); // Do not use setValues(x,y) (see note at the top of this file). - knob->setValue(_centerDrag.x, ViewSpec::all(), 0, eValueChangedReasonPluginEdited); - knob->setValue(_centerDrag.y, ViewSpec::all(), 1, eValueChangedReasonPluginEdited); + nonBlockingSetValues(knob, _centerDrag, eValueChangedReasonPluginEdited); } { KnobDoublePtr knob = _translate.lock(); // Do not use setValues(x,y) (see note at the top of this file). - knob->setValue(_translateDrag.x, ViewSpec::all(), 0, eValueChangedReasonPluginEdited); - knob->setValue(_translateDrag.y, ViewSpec::all(), 1, eValueChangedReasonPluginEdited); + nonBlockingSetValues(knob, _translateDrag, eValueChangedReasonPluginEdited); } { KnobDoublePtr knob = _scale.lock(); // Do not use setValues(x,y) (see note at the top of this file). - knob->setValue(_scaleParamDrag.x, ViewSpec::all(), 0, eValueChangedReasonPluginEdited); - knob->setValue(_scaleParamDrag.y, ViewSpec::all(), 1, eValueChangedReasonPluginEdited); + nonBlockingSetValues(knob, _scaleParamDrag, eValueChangedReasonPluginEdited); } { KnobDoublePtr knob = _rotate.lock(); @@ -2509,14 +2476,12 @@ CornerPinInteract::penUp(double /*time*/, KnobDoublePtr knob = _from[_dragging].lock(); assert(knob); // Do not use setValues(x,y) (see note at the top of this file). - knob->setValue(_fromDrag[_dragging].x, ViewSpec::all(), 0, eValueChangedReasonPluginEdited); - knob->setValue(_fromDrag[_dragging].y, ViewSpec::all(), 1, eValueChangedReasonPluginEdited); + nonBlockingSetValues(knob, _fromDrag[_dragging], eValueChangedReasonPluginEdited); } else { KnobDoublePtr knob = _to[_dragging].lock(); assert(knob); // Do not use setValues(x,y) (see note at the top of this file). - knob->setValue(_toDrag[_dragging].x, ViewSpec::all(), 0, eValueChangedReasonPluginEdited); - knob->setValue(_toDrag[_dragging].y, ViewSpec::all(), 1, eValueChangedReasonPluginEdited); + nonBlockingSetValues(knob, _toDrag[_dragging], eValueChangedReasonPluginEdited); } holder->setMultipleParamsEditLevel(KnobHolder::eMultipleParamsEditOff); } diff --git a/Tests/OSGLContext_Test.cpp b/Tests/OSGLContext_Test.cpp index 5744f9ce7..271cb3a49 100644 --- a/Tests/OSGLContext_Test.cpp +++ b/Tests/OSGLContext_Test.cpp @@ -33,6 +33,17 @@ NATRON_NAMESPACE_USING +#if defined(__NATRON_WIN32__) && !defined(__NATRON_MINGW__) +namespace { + +// Define nullptr_t operator since MSVC dosn't appear to have one by default. +std::ostream& operator<<(std::ostream& os, const std::nullptr_t p) { + return os << ""; +} + +} // namespace +#endif + TEST(OSGLContext, Basic) { if (!appPTR->isOpenGLLoaded()) {