ITADN

Index out of range: index should be less than 1175964: 1179937898 [Error on loading .glb file in iOS]

#79OpenMohammad-R-Rashid 创建于 2025-08-03
Tested multiple .glb files. Added a modelCache.dart method to try to cache and load. Validated .glb files to make sure it is valid. Here are some logs: flutter: Loading Blaster6 model in powerups with improved error handling... flutter: Loading Blaster6.glb from assets... flutter: Loaded ByteData: 1175964 bytes flutter: Created Uint8List: 1175964 bytes flutter: Written to temp file: /var/mobile/Containers/Data/Application/FA451963-34DF-4EF1-8C60-0DBF291F0EAF/Library/Caches/Blaster6.glb flutter: Verified written file: 1175964 bytes flutter: Model preloaded successfully, attempting direct load... flutter: RangeError with preloaded approach: RangeError (byteOffset): Index out of range: index should be less than 1175964: 1179937898 flutter: Trying direct asset loading with delay... flutter: RangeError with delayed approach: RangeError (byteOffset): Index out of range: index should be less than 1175964: 1179937898 flutter: Clearing cache and trying again... flutter: Model cache cleared flutter: Blaster6 final attempt failed: RangeError (byteOffset): Index out of range: index should be less than 1175964: 1179937898 flutter: All Blaster6 approaches failed. Trying DefaultBlaster as fallback... flutter: Loading DefaultBlaster.glb from assets... flutter: Loaded ByteData: 1010104 bytes flutter: Created Uint8List: 1010104 bytes flutter: Written to temp file: /var/mobile/Containers/Data/Application/FA451963-34DF-4EF1-8C60-0DBF291F0EAF/Library/Caches/DefaultBlaster.glb flutter: Verified written file: 1010104 bytes flutter: RangeError loading DefaultBlaster fallback: RangeError (byteOffset): Index out of range: index should be less than 1010104: 1179937898 flutter: All loading approaches failed, proceeding without 3D model Render model code: Future<void> _loadModel() async { try { print('Loading DefaultBlaster model with validation...'); // First, validate the GLB file final isValid = await GlbValidator.validateGlbFile('assets/DefaultBlaster.glb'); if (!isValid) { print('DefaultBlaster.glb failed validation, skipping 3D model'); setState(() { model = null; isLoading = false; }); return; } final glbInfo = await GlbValidator.getGlbInfo('assets/DefaultBlaster.glb'); print('DefaultBlaster GLB info: $glbInfo'); // Try multiple approaches to load the model Node? loadedModel; // Approach 1: Try loading with cached model path (preloading) try { await ModelCacheManager.preloadDefaultBlasterModel(); print('Model preloaded successfully, attempting direct load...'); loadedModel = await Node.fromAsset('assets/DefaultBlaster.glb'); print('Successfully loaded DefaultBlaster model with preloading'); } on RangeError catch (e) { print('RangeError with preloaded approach: $e'); print('Problematic byte offset: ${e.toString().contains('1179937898') ? 'Known GLB parser bug detected' : 'Unknown offset'}'); loadedModel = null; } // Approach 2: Try direct loading with delay if (loadedModel == null) { try { print('Trying direct asset loading with delay...'); await Future.delayed(const Duration(milliseconds: 200)); loadedModel = await Node.fromAsset('assets/DefaultBlaster.glb'); print('Successfully loaded DefaultBlaster model with delay'); } on RangeError catch (e) { print('RangeError with delayed approach: $e'); loadedModel = null; } } // Approach 3: Try clearing cache and loading again if (loadedModel == null) { try { print('Clearing cache and trying again...'); await ModelCacheManager.clearCache(); await Future.delayed(const Duration(milliseconds: 300)); loadedModel = await Node.fromAsset('assets/DefaultBlaster.glb'); print('Successfully loaded DefaultBlaster model after cache clear'); } catch (e) { print('Final attempt failed: $e'); loadedModel = null; } } if (loadedModel != null) { setState(() { model = loadedModel; scene.add(model!); isLoading = false; }); } else { print('All loading approaches failed - GLB file may be incompatible with flutter_scene package'); setState(() { model = null; isLoading = false; }); }
0 条评论