vengi-voxel / vengi

free and open source voxel art tools - editor, thumbnailer and format converter
http://vengi-voxel.github.io/vengi/
Other
1.08k stars 90 forks source link

VOXELFORMAT: GLTF: assert when importing gltf #270

Closed mgerhardy closed 1 year ago

mgerhardy commented 1 year ago

command line:

vengi-voxconvert --export-layers --input ~/Downloads/4543Skull.gltf --output Skull_4543.vxm

without --export-layers the export works. The stack runs out of entries.

stacktrace:

ERROR: (0) Stack trace (most recent call last):
ERROR: (0) #19   Object "", at 0xffffffffffffffff, in 
ERROR: (0) #18   Object "/home/mgerhardy/dev/engine/build/Debug/voxconvert/vengi-voxconvert", at 0x55e2ae257d00, in _start
ERROR: (0) #17   Source "../csu/libc-start.c", line 381, in __libc_start_main_impl
ERROR: (0) #16   Source "../sysdeps/nptl/libc_start_call_main.h", line 58, in __libc_start_call_main
ERROR: (0) #15   Source "/home/mgerhardy/dev/engine/src/tools/voxconvert/VoxConvert.cpp", line 739, in main
ERROR: (0)         736:     const io::FilesystemPtr& filesystem = core::make_shared<io::Filesystem>();
ERROR: (0)         737:     const core::TimeProviderPtr& timeProvider = core::make_shared<core::TimeProvider>();
ERROR: (0)         738:     VoxConvert app(filesystem, timeProvider);
ERROR: (0)       > 739:     return app.startMainLoop(argc, argv);
ERROR: (0)         740: }
ERROR: (0) #14   Source "/home/mgerhardy/dev/engine/src/modules/app/App.cpp", line 105, in startMainLoop
ERROR: (0)         102:     emscripten_set_main_loop(runFrameEmscripten, 0, 1);
ERROR: (0)         103: #else
ERROR: (0)         104:     while (AppState::InvalidAppState != _curState) {
ERROR: (0)       > 105:         onFrame();
ERROR: (0)         106:     }
ERROR: (0)         107: #endif
ERROR: (0)         108:     return _exitCode;
ERROR: (0) #13   Source "/home/mgerhardy/dev/engine/src/modules/app/App.cpp", line 165, in onFrame
ERROR: (0)         162:             Log::debug("AppState::BeforeInit");
ERROR: (0)         163:             onBeforeInit();
ERROR: (0)         164:             Log::debug("AppState::Init");
ERROR: (0)       > 165:             _nextState = onInit();
ERROR: (0)         166:             Log::debug("AppState::AfterInit");
ERROR: (0)         167:             onAfterInit();
ERROR: (0)         168:             Log::debug("AppState::Init done");
ERROR: (0) #12   Source "/home/mgerhardy/dev/engine/src/tools/voxconvert/VoxConvert.cpp", line 323, in onInit
ERROR: (0)         320:         if (infiles.size() > 1) {
ERROR: (0)         321:             Log::warn("The format and path of the first input file is used for exporting all layers");
ERROR: (0)         322:         }
ERROR: (0)       > 323:         exportLayersIntoSingleObjects(sceneGraph, infiles[0]);
ERROR: (0)         324:     }
ERROR: (0)         325: 
ERROR: (0)         326:     if (_mergeVolumes) {
ERROR: (0) #11   Source "/home/mgerhardy/dev/engine/src/tools/voxconvert/VoxConvert.cpp", line 509, in exportLayersIntoSingleObjects
ERROR: (0)         506:         scenegraph::copyNode(node, newNode, false);
ERROR: (0)         507:         newSceneGraph.emplace(core::move(newNode));
ERROR: (0)         508:         const core::String& filename = getFilenameForLayerName(inputfile, node.name(), n);
ERROR: (0)       > 509:         if (voxelformat::saveFormat(filesystem()->open(filename, io::FileMode::SysWrite), nullptr, newSceneGraph, saveCtx)) {
ERROR: (0)         510:             Log::info(" .. %s", filename.c_str());
ERROR: (0)         511:         } else {
ERROR: (0)         512:             Log::error(" .. %s", filename.c_str());
ERROR: (0) #10   Source "/home/mgerhardy/dev/engine/src/modules/voxelformat/VolumeFormat.cpp", line 449, in saveFormat
ERROR: (0)         446:     }
ERROR: (0)         447: 
ERROR: (0)         448:     io::FileStream stream(filePtr);
ERROR: (0)       > 449:     if (!saveFormat(sceneGraph, filePtr->name(), desc, stream, ctx)) {
ERROR: (0)         450:         Log::warn("Failed to save file %s - saving as vengi instead", filePtr->name().c_str());
ERROR: (0)         451:         VENGIFormat vengiFormat;
ERROR: (0)         452:         const core::String &newName = core::string::replaceExtension(filePtr->name(), "vengi");
ERROR: (0) #9    Source "/home/mgerhardy/dev/engine/src/modules/voxelformat/VolumeFormat.cpp", line 430, in saveFormat
ERROR: (0)         427:         if (desc->matchesExtension(ext) /*&& (type.empty() || type == desc->name)*/) {
ERROR: (0)         428:             core::SharedPtr<Format> f = getFormat(*desc, 0u, false);
ERROR: (0)         429:             if (f) {
ERROR: (0)       > 430:                 if (f->save(sceneGraph, filename, stream, ctx)) {
ERROR: (0)         431:                     Log::debug("Saved file for format '%s' (ext: '%s')", desc->name.c_str(), ext.c_str());
ERROR: (0)         432:                     return true;
ERROR: (0)         433:                 }
ERROR: (0) #8    Source "/home/mgerhardy/dev/engine/src/modules/voxelformat/Format.cpp", line 184, in save
ERROR: (0)         181:         splitVolumes(sceneGraph, newSceneGraph, maxsize);
ERROR: (0)         182:         return saveGroups(newSceneGraph, filename, stream, ctx);
ERROR: (0)         183:     }
ERROR: (0)       > 184:     return saveGroups(sceneGraph, filename, stream, ctx);
ERROR: (0)         185: }
ERROR: (0)         186: 
ERROR: (0)         187: bool Format::load(const core::String &filename, io::SeekableReadStream& stream, scenegraph::SceneGraph& sceneGraph, const LoadContext &ctx) {
ERROR: (0) #7    Source "/home/mgerhardy/dev/engine/src/modules/voxelformat/MeshFormat.cpp", line 445, in saveGroups
ERROR: (0)         442:         state = false;
ERROR: (0)         443:     } else {
ERROR: (0)         444:         Log::debug("Save meshes");
ERROR: (0)       > 445:         state = saveMeshes(meshIdxNodeMap, sceneGraph, nonEmptyMeshes, filename, stream, scale, marchingCubes ? false : quads, withColor, withTexCoords);
ERROR: (0)         446:     }
ERROR: (0)         447:     for (MeshExt& meshext : meshes) {
ERROR: (0)         448:         delete meshext.mesh;
ERROR: (0) #6    Source "/home/mgerhardy/dev/engine/src/modules/voxelformat/GLTFFormat.cpp", line 437, in saveMeshes
ERROR: (0)         434:             {
ERROR: (0)         435:                 tinygltf::Node gltfNode;
ERROR: (0)         436:                 gltfNode.mesh = (int)gltfModel.meshes.size();
ERROR: (0)       > 437:                 saveGltfNode(nodeMapping, gltfModel, gltfNode, gltfScene, node, stack, sceneGraph, scale,
ERROR: (0)         438:                              exportAnimations);
ERROR: (0)         439:             }
ERROR: (0) #5    Source "/home/mgerhardy/dev/engine/src/modules/voxelformat/GLTFFormat.cpp", line 140, in saveGltfNode
ERROR: (0)         137:     gltfModel.nodes.push_back(gltfNode);
ERROR: (0)         138:     nodeMapping.put(node.id(), idx);
ERROR: (0)         139: 
ERROR: (0)       > 140:     if (stack.back().second != -1) {
ERROR: (0)         141:         gltfModel.nodes[stack.back().second].children.push_back(idx);
ERROR: (0)         142:     } else {
ERROR: (0)         143:         gltfScene.nodes.push_back(idx);
ERROR: (0) #4    Source "/home/mgerhardy/dev/engine/src/modules/core/collection/DynamicArray.h", line 328, in back
ERROR: (0)         325:     }
ERROR: (0)         326: 
ERROR: (0)         327:     TYPE& back() {
ERROR: (0)       > 328:         core_assert(_size > 0u);
ERROR: (0)         329:         return _buffer[_size - 1u];
ERROR: (0)         330:     }
ERROR: (0) #3    Source "/home/mgerhardy/dev/engine/src/modules/core/Assert.cpp", line 20, in core_report_assert
ERROR: (0)          18: bool core_report_assert(AssertData &data, const char *file, int line, const char *function) {
ERROR: (0)          19:     if (data.always_ignore == 0) {
ERROR: (0)       >  20:         core_stacktrace();
ERROR: (0)          21:     }
ERROR: (0)          22:     const SDL_AssertState state = SDL_ReportAssertion((SDL_AssertData *)&data, function, file, line);
ERROR: (0)          23:     if (state == SDL_ASSERTION_RETRY) {
ERROR: (0) #2    Source "/home/mgerhardy/dev/engine/src/modules/core/Assert.cpp", line 36, in core_stacktrace
ERROR: (0)          33: #ifdef HAVE_BACKWARD
ERROR: (0)          34:     std::ostringstream os;
ERROR: (0)          35:     backward::StackTrace st;
ERROR: (0)       >  36:     st.load_here(32);
ERROR: (0)          37:     backward::Printer printer;
ERROR: (0)          38:     printer.print(st, os);
ERROR: (0)          39:     std::string stacktrace = os.str();
ERROR: (0) #1    Source "/home/mgerhardy/dev/engine/contrib/libs/backward/backward.h", line 878, in load_here
ERROR: (0)         875:       return 0;
ERROR: (0)         876:     }
ERROR: (0)         877:     _stacktrace.resize(depth);
ERROR: (0)       > 878:     size_t trace_cnt = details::unwind(callback(*this), depth);
ERROR: (0)         879:     _stacktrace.resize(trace_cnt);
ERROR: (0)         880:     skip_n_firsts(0);
ERROR: (0)         881:     return size();
ERROR: (0) #0    Source "/home/mgerhardy/dev/engine/contrib/libs/backward/backward.h", line 860, in unwind<backward::StackTraceImpl<backward::system_tag::linux_tag>::callback>
ERROR: (0)         858: template <typename F> size_t unwind(F f, size_t depth) {
ERROR: (0)         859:   Unwinder<F> unwinder;
ERROR: (0)       > 860:   return unwinder(f, depth);
ERROR: (0)         861: }
ERROR: (0)         862: 
ERROR: (0)         863: } // namespace details
WARN: 

Assertion failure at back (/home/mgerhardy/dev/engine/src/modules/core/collection/DynamicArray.h:328), triggered 1 time:
  '_size > 0u'
mgerhardy commented 1 year ago

the assert is fixed with the given commit - I'll close this for now. The stack usage in the format implementation is going to be refactored anyway.