iOS Question B4i Random Access File Read Causes App Crash

lymey

Active Member
Licensed User
Longtime User
Hi!
The following code causes the app to crash. The Filenames are all correct. The file was created in the same app and used WriteB4xObject(0) which appears to work. the DefaultDirectory is 'File.DirLibrary'.
Using Try/Catch/End Try does not catch the error. The same code works in the Android version of the app without error.
I am using the current version of B4i, and a real device using hosted builder.
Any thoughts as to why I can't catch the error, and what might be causing it?

B4X:
        Dim unlck_raf As RandomAccessFile
        unlck_raf.initialize(DefaultFileDirectory, locked_LCK_filename, False)
        Log("Initialised raf")
        Dim    unpack_lck_map As Map
        unpack_lck_map.Initialize
        Log("unpack map")
        If unlck_raf.Size <> 0 Then
            unpack_lck_map = unlck_raf.ReadB4XObject(0)
        End If
The line that causes the crash is line 8 highlighted above.

Values at the breakpoint on that line are:
Breakpoint.PNG
 

Attachments

  • Breakpoint.PNG
    Breakpoint.PNG
    8.9 KB · Views: 162

Erel

B4X founder
Staff member
Licensed User
Longtime User
Works fine here:

Application_Start
Application_Active
Getting password
Time: 200
password is: aaaaaaaa
Returned form getting password: aaaaaaaa
Deleted existing .tst file
Create Map for RAF file
EncryptText ABCDEF
Unique ID: sJCxwn3GTDX91XQcvUEW8gMmDX6W255Ja6MqUSIb5mKalPartSM1jg==
Encrypt
Parameters
EncryptText NNN99N
Creating RAF: /Users/ereluziel/Library/Developer/CoreSimulator/Devices/4ADFE98D-4185-48AF-97E6-3F1CA24C9D2C/data/Containers/Data/Application/8647F429-7B2C-4308-8CD4-F2AAAB531A6F/Library/TestDirectory2/Test_01.JPG.tst
File exists
Password Dialog
loadlayout
dialog at top
Time: 199
waited for password
positive
password is: aaaaaaaa
Returned form getting password: aaaaaaaa
Getting ready to unpack .tst file
Creating unpacked file from Test_01.JPG.tst
Test_01.JPG.tst is ready to process!
targetfilename: Test_01.JPG
Delete existing: /Users/ereluziel/Library/Developer/CoreSimulator/Devices/4ADFE98D-4185-48AF-97E6-3F1CA24C9D2C/data/Containers/Data/Application/8647F429-7B2C-4308-8CD4-F2AAAB531A6F/Library/TestDirectory/Test_01.JPG
Unpack .tst
raf is: /Users/ereluziel/Library/Developer/CoreSimulator/Devices/4ADFE98D-4185-48AF-97E6-3F1CA24C9D2C/data/Containers/Data/Application/8647F429-7B2C-4308-8CD4-F2AAAB531A6F/Library/TestDirectory2/Test_01.JPG.tst
Initialised raf
unpack map
map initialise
raf size = 5990333
decrypt raf
DecryptText sJCxwn3GTDX91XQcvUEW8gMmDX6W255Ja6MqUSIb5mKalPartSM1jg==
Unencrypted ID: ABCDEF

Encrypting a large image, converting it to base64 string, and then writing it back with B4XSerializator might cause an out of memory error.
1. Test it with a smaller image.
2. Don't convert the encrypted bytes to a string. You are just wasting memory.
 
Upvote 0

lymey

Active Member
Licensed User
Longtime User
Thanks for your feedback Erel.
What is the spec of the device you are using?
Is there a way to trap out of memory errors?
I can test with a smaller image, but the app itself has to deal with larger images too.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I've tested it on the simulator.

I can test with a smaller image, but the app itself has to deal with larger images too.
It doesn't matter. You should start with a test.

Is there a way to trap out of memory errors?
No.

However you should fix the issue I explained. It will be much more efficient.
 
Upvote 0

lymey

Active Member
Licensed User
Longtime User
Ok, I tried with a much smaller file and it worked as expected.
I then did as you suggested and didn't convert the encrypted bytes to a string. Using the first larger file, the app behaved correctly. Thanks for your help!
 
Upvote 0
Top