简体   繁体   中英

C++ member variables are not initialized when using a debug version static library

  • Environment: Windows10, cpp17, visual studio 2019, debug version static library

Recently I tried to use Cesium-Native to read 3DTiles files in my project, but there was a confusing problem that some member variables are not initialized correctly. As following codes show, Tileset() use initializer list to initialize its member variables, but some of them like _loadsInProgress , _previousFrameNumber are initialized to random value which shoule have been 0. However some of them are initialize correctly like _url , _options , and it works well in Release Library and the same code in its original project. What a strange bug!

Tileset::Tileset(
    const TilesetExternals& externals,
    const std::string& url,
    const TilesetOptions& options)
    : _externals(externals),
      _asyncSystem(externals.asyncSystem),
      _userCredit(
          (options.credit && externals.pCreditSystem)
              ? std::optional<Credit>(externals.pCreditSystem->createCredit(
                    options.credit.value(),
                    options.showCreditsOnScreen))
              : std::nullopt),
      _url(url),
      _isRefreshingIonToken(false),
      _options(options),
      _pRootTile(),
      _previousFrameNumber(0),
      _loadsInProgress(0),
      _subtreeLoadsInProgress(0),
      _overlays(*this),
      _tileDataBytes(0),
      _supportsRasterOverlays(false),
      _gltfUpAxis(CesiumGeometry::Axis::Y),
      _distancesStack(),
      _nextDistancesVector(0) {
  if (!url.empty()) {
    CESIUM_TRACE_USE_TRACK_SET(this->_loadingSlots);
    this->notifyTileStartLoading(nullptr);
    LoadTilesetDotJson::start(*this, url).thenInMainThread([this]() {
      this->notifyTileDoneLoading(nullptr);
    });
  }
}

Through debugging, I found that _loadsInProgress was 0 at first, and it changes when a vector construct function is called. Maybe it's because generation of debug static lib?

Any suggestions will be appreciated!

The problem solved by carefully checking all setting in running correctly original project and my project. And try to clean Visual Studio Cache and rebuild project and lib may be helpful for the problem.

At first I used the different library version for inlucde and lib files, then I found that, I change the same version library include files to my project. But due to VS cache and the same file name(I guess), the change failed to apply to my project actually.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM