Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Line2D2Vecs constructor 'createAndSetupBuffers' not checking size when empty casuing crash in MSVC #4

Open
BisonLeo opened this issue Aug 19, 2023 · 5 comments

Comments

@BisonLeo
Copy link

BisonLeo commented Aug 19, 2023

createAndSetupBuffers(vertDataSizeBytes, indicesDataSizeBytes,

    /* 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 :

  1. 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"
  2. rebuild glfw using MSVC
  3. change the LIBS file names to match the built freetype and glfw libs
  4. 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!

@tbattz
Copy link
Owner

tbattz commented Aug 19, 2023

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?

@BisonLeo
Copy link
Author

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.

  1. msvc_dirent.h is for src/textures/TextureManager.cpp as it does not exist in MSVC
  2. The precompiled static library version of freetype and glfw3 was added, you can give it a try.
    BisonLeo@5fdd6ef
    the freetype was from freetype/freetype@4d8db13

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.

@BisonLeo
Copy link
Author

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()

@tbattz
Copy link
Owner

tbattz commented Aug 20, 2023

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..

set(CMAKE_TOOLCHAIN_FILE ${CMAKE_TOOLCHAIN_FILE} "C:/dev/vcpkg/scripts/buildsystems/vcpkg.cmake")

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.

@BisonLeo
Copy link
Author

  1. I installed vcpkg using the link https://github.com/microsoft/vcpkg/blob/master/README.md at c:/dev/vcpkg
  2. 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]));

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants