Line2D2Vecs constructor 'createAndSetupBuffers' not checking size when empty casuing crash in MSVC
https://github.com/tbattz/openGLPlotLive/blob/26ef4142f88370a62414b519b5d729d430a88165/src/lines/Line2D2Vecs.cpp#L21
/* Setup Buffers */
updateInternalData();
int vertDataSizeBytes = internalData.size()*sizeof(internalData[0]);
int indicesDataSizeBytes = internalIndices.size()*sizeof(internalIndices[0]);
createAndSetupBuffers(vertDataSizeBytes, indicesDataSizeBytes,
&internalData[0], &internalIndices[0],
2*sizeof(internalData[0]));
although it compiles and runs OK under windows using GCC compiler, the code above fails in MSVC 2019 compiled executable 'movingTimeframe.exe'
I guess it should be preallocated to contain certain size? I don't know why it runs OK when compiled with g++ toolchain under windows.
The procedure to completely build using MSVC is tedious including :
- git clone newest freetype 1.1 disable the following options and rebuild with MSVC "-DFT_DISABLE_HARFBUZZ=ON", "-DFT_DISABLE_PNG=ON", "-DFT_DISABLE_BZIP2=ON", "-DFT_DISABLE_BROTLI=ON"
- rebuild glfw using MSVC
- change the LIBS file names to match the built freetype and glfw libs
- add 'msvc_dirent.h' from https://gitcode.net/mirrors/tronkko/dirent/-/blob/master/include/dirent.h
But without doubt, this is a terrific example of OpenGL that I'm learning from. Thank you!
I haven't really used MSVC much before (or Visual Studio for that matter), so I've given it a go compiling it with Visual Studio. Haven't quite go everything compiling correctly, though it does seem that at least for freetype, we can use the .slm project file provided in ft271\freetype-2.7.1\builds\windows\vc2010?
I'm tryingto determine if we can make an installer script, similar to the other installer scripts, just for MSVC, though it seems due to the older version of freetype with it being setup for MSVC 2010 and earlier, rather than the later versions that we might have an issue. If you get it working, do you think you could setup a script similar to https://github.com/tbattz/openGLPlotLive/blob/26ef4142f88370a62414b519b5d729d430a88165/Installers/installDependenciesWindows-part2.bat?
It is a bit weird that it compiles fine under gcc, but fails in MSVC.
Do you get the same issue with line 21, if you put a dummy first point into the std::vector that the Line2D2Vecs is created off? If so then it'll probably need a preallocation, or to wait until there's some data before setting up the buffer. I can't really check at the moment, as I can't get things compiled with MSVC.
I'm not quite understanding, why is the msvc_dirent.h needed to get it compiling?
By MSVC I mean the compiler. All the lib and executables are built using CMake with Ninja as generator and VS2019 toolchain with vcpkg managing packages.
-
msvc_dirent.his forsrc/textures/TextureManager.cppas it does not exist in MSVC - The precompiled static library version of freetype and glfw3 was added, you can give it a try. https://github.com/BisonLeo/openGLPlotLive/commit/5fdd6ef0d9485301c63dfd7230b39942bba28683 the freetype was from https://github.com/freetype/freetype/commit/4d8db130ea4342317581bab65fc96365ce806b77
Let's see if it all goes well and get tested on your side. It would be a bit early to write the batch file to prepare the full automation as it will be a separate issue.
It looks like Grid::verts and Axesarea::interactorDataX not get proper initialized with default values. Could these get called only until needed? Grid::createAndSetupAxesLineBuffers() AxesArea::createInteractor()
I've checked out your fork, and tried to compile it. I have a few issues, as I don't think I have my environment set up the same way.
I had to change the following line to point to my vcpkg.. https://github.com/tbattz/openGLPlotLive/blob/5fdd6ef0d9485301c63dfd7230b39942bba28683/CMakeLists.txt#L7
are built using CMake with Ninja as generator and VS2019 toolchain with vcpkg managing packages.
To make sure we're on the same page, you're compiling from command line using
mkdir build && cd build
cmake ../ -G Ninja
Or using
mkdir build && cd build
cmake ../ -G "Visual Studio 16 2019"
Or something else altogether?
How did you install vcpkg? I'd assume standalone and not through Visual Studio?
It looks like Grid::verts and Axesarea::interactorDataX not get proper initialized with default values. Could these get called only until needed? Grid::createAndSetupAxesLineBuffers() AxesArea::createInteractor()
It's been a while since I wrote the code, though I remember there being an issue with the interactor if there wasn't any existing data. I think it was to do with no real axes limits getting set, and then having zero range causing issues with the interactor position calculator. Though I thought I had implemented something to stop that being an issue.
Really, if there's no data yet existing, then there's no point in having an interactor. Initialising it with dummy values will likely result in them getting overwritten on the first frame when the position would get recalculated. It's a bit hard for me to narrow down the issue without having the same environment and compiled using MSVC/ninja.
Potentially as a temporary fix, if you just want to get the plot working, would be to disable the interactor. If I can get my environment sorted, I'll have a deeper look at it.
- I installed vcpkg using the link https://github.com/microsoft/vcpkg/blob/master/README.md at c:/dev/vcpkg
- building was done by
mkdir build && cd build
cmake ../ -G Ninja
CMakeCache.txt
This is the CMakeCache.txt from my build folder
3. The major issue here is I dont understand why the behavious is different between G++ and MSVC.
When the Grid::verts and Axesarea::interactorDataX initialized, if it is empty, how could the code &internalData[0] gets run properly in G++ compiled version?
createAndSetupBuffers(vertDataSizeBytes, indicesDataSizeBytes,
&internalData[0], &internalIndices[0],
2*sizeof(internalData[0]));