0
  • 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!

7
  • What does it change to? 0xcc or 0xcd? Commented Apr 22, 2022 at 13:20
  • Maybe it's because generation of debug static lib? I would expect a bug in your code somewhere would be more likely than a build issue or a compiler bug. Commented Apr 22, 2022 at 13:21
  • This is hardly a minimal example, and it's certainly not complete. Commented Apr 22, 2022 at 13:22
  • 1
    You cannot link together a debug version of a static lib with a release version of an app/another static lib. Everything should be build with the same settings that go into a single executable. Commented Apr 22, 2022 at 13:30
  • @drescherjm it changes to a random value like 0xe4ff3a10, which seems like a block of memory just allocated. And this is their libray code, my code actually are very short. But I really don't understand why constructor don't initialize member variables correctly Commented Apr 23, 2022 at 4:30

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.