objectbox-dart icon indicating copy to clipboard operation
objectbox-dart copied to clipboard

`IndexError (RangeError (byteOffset) ...` error on iOS

Open JaffaKetchup opened this issue 1 year ago • 6 comments
trafficstars

This report is based on a 3rd party private report to https://github.com/JaffaKetchup/flutter_map_tile_caching. As much info is supplied as is known, let me know if more is required!

Is there an existing issue?

  • [x] I have searched existing issues
  • https://www.reddit.com/r/flutterhelp/comments/199qsff/flutter_object_box/ reports the same error (but with different numbers)

Build info

  • objectbox version: 4.0.1
  • Flutter/Dart version: unsure
  • Build OS: 2020 Mac Mini M1
  • Deployment OS or device: iOS 17.4 (iPhone 11 & SE)

Steps to reproduce

FMTC allows users to export parts of the database, then re-import them. There is practically no difference to a standard read/write operation though. Note that an import is not the same as a complete replacement of the existing 'data.mdb' file with a new one. Both databases are open at the same time, and the needed data is transferred manually between them.

When importing the attached database into the OP's app, or the FMTC example app (https://github.com/JaffaKetchup/flutter_map_tile_caching), the following error is thrown, on iOS only:

image (1)

Raw ObjectBox file: https://drive.google.com/file/d/133UXCBJDydiN_kYlbQjrHYygdK16S82V/view?usp=sharing (do not distribute)

FMTC compatible file (contains the ObjectBox file, but with extra footer information): https://drive.google.com/file/d/1x5JoqnTvqD_QRr2bpIVcYuh6tQKt3KXu/view?usp=sharing (do not distribute)

To reproduce with the example app, clone the repo, run the example app, then follow the screenshots:

step1 step2

Select to import the FMTC compatible file, choose any conflict resolution mode (skip/merge/etc.), then tap the FAB.

Expected behavior

The same behaviour should occur on the iOS platform as on other platforms: that is, the import operation succeeds without error.

Actual behavior

The error in the screenshot is thrown.

Code

It is difficult to provide an MRE. The import algorithm can be found at https://github.com/JaffaKetchup/flutter_map_tile_caching/blob/9268675e19d246da2a9bb298aa00812e09c5891e/lib/src/backend/impls/objectbox/backend/internal_workers/standard/worker.dart#L874-L1279, but it is somewhat context dependent (note, for example, 'store' in FMTC terminology is not the same as an ObjectBox 'store'). The code runs within an isolate.

Logs, stack traces

As well as the screenshot above, see these screenshots as well - not sure if they're useful or not:

image (2)

image (3)

JaffaKetchup avatar Jul 20 '24 11:07 JaffaKetchup

Thanks for reporting!

Some basics: it looks like this happens when reading url from ObjectBoxTile:

  @Index()
  @Unique(onConflict: ConflictStrategy.replace)
  String url;

Then FlatBuffers errors because the byte offset is too large.

I tried to run the example app, but it appears it does not support iOS or macOS? Had to run flutter create . to add required files. Then flutter run on an iOS simulator worked.

I dragged the fmtc file onto the simulator and tried to select it. However, it is grayed out. Is there something I am missing?

Anyhow, I analyzed the data.mdb file with Admin and the url strings seem to be around 30 characters. So unlikely related to length. Will have to look at this further.

greenrobot-team avatar Jul 23 '24 13:07 greenrobot-team

Yes, you'll need to change some things in the widget so the file is not grayed out.

image

Soap-141 avatar Jul 23 '24 14:07 Soap-141

I tried to run the example app, but it appears it does not support iOS or macOS? Had to run flutter create . to add required files. Then flutter run on an iOS simulator worked.

I don't have any Apple devices, so I didn't include any of those platform files.

As @Soap-141 said (thanks :)), the file's probably greyed out because the file picker stuff is quite hard to get right across all platforms. Hopefully that works.

JaffaKetchup avatar Jul 23 '24 14:07 JaffaKetchup

Hello, any update on this? Can I provide anything else?

Soap-141 avatar Aug 06 '24 14:08 Soap-141

OK, finally had time to try to reproduce this again. @Soap-141 thanks, your suggestion allowed me to import the file!

However, running a few times with flutter run using the iOS simulator I can only get a different exception:

[ERROR:flutter/runtime/dart_isolate.cc(1291)] Unhandled exception:
Bad state: Cannot add event after closing
#0      _StreamController.addError (dart:async/stream_controller.dart:612:24)
#1      Query._streamIsolate.<anonymous closure> (package:objectbox/src/native/query/query.dart:1403:28)
#2      _RootZone.runUnaryGuarded (dart:async/zone.dart:1594:10)
#3      _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:365:11)
#4      _BufferingStreamSubscription._add (dart:async/stream_impl.dart:297:7)
#5      _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:784:19)
#6      _StreamController._add (dart:async/stream_controller.dart:658:7)
#7      _StreamController.add (dart:async/stream_controller.dart:606:5)
#8      _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)

And when running through Visual Studio Code (with "Uncaught Exceptions" enabled) I always get Error._throw (in flutter/bin/cache/pkg/sky_engine/lib/_internal/vm/lib/errors_patch.dart) and can't load additional stack frames.

Next week at the earliest I'll try to have a look at why FlatBuffers might throw the above exception, maybe that gives a useful hint.

greenrobot-team avatar Aug 07 '24 08:08 greenrobot-team

@greenrobot-team Thanks! Yes I understand, I also had a hard time debugging iOS on my Mac using VS Code and Xcode, by playing around with exception settings and breakpoints I managed to have multiple exceptions and errors similar to this, you are on the right path.

Feel free to let me know if I can help more.

Soap-141 avatar Aug 07 '24 12:08 Soap-141

Is this still an issue with the 4.3.0 release? The database library received improvements to make sure a Store will wait with closing until all database operations have finished. This theoretically should prevent the EXC_BAD_ACCESS error while results are streaming.

greenrobot-team avatar Jul 30 '25 08:07 greenrobot-team

Without additional information, we are unfortunately not sure how to resolve this issue. Therefore this issue has been automatically closed. Feel free to comment with additional details and we can re-open this issue.

github-actions[bot] avatar Aug 21 '25 01:08 github-actions[bot]