iOS Question [SOLVED?] Bug in File.ListFiles in Release mode

JackKirk

Well-Known Member
Licensed User
Longtime User
I feel a bit like chicken little - running around the barnyard screaming "the sky is falling".

This has to be a bug - or at least better be for my own sanity.

If you run this code in debug mode:
B4X:
#Region  Project Attributes
    #ApplicationLabel: Bug
    #Version: 1.0.0
    'Orientation possible values: Portrait, LandscapeLeft, LandscapeRight and PortraitUpsideDown
    #iPhoneOrientations: Portrait, LandscapeLeft, LandscapeRight
    #iPadOrientations: Portrait, LandscapeLeft, LandscapeRight, PortraitUpsideDown
    #Target: iPhone, iPad
    #ATSEnabled: True
    #MinVersion: 7
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public App As Application
    Public NavControl As NavigationController
    Private Page1 As Page

End Sub

Private Sub Application_Start (Nav As NavigationController)
    Dim rl As ReleaseLogger
    rl.Initialize("192.168.1.6", 54323)
    NavControl = Nav
    Page1.Initialize("Page1")
    Page1.Title = "Page 1"
    Page1.RootPanel.Color = Colors.White
    NavControl.ShowPage(Page1)
End Sub

Private Sub Page1_Resize(Width As Int, Height As Int)

    Private wrk_files As List
    Private wrk_str As String
    Private wrk_ptr As Int

    'Get names of files in assets directory
    wrk_files = File.ListFiles(File.DirAssets)

    'For all files...
    For wrk_ptr = 0 To wrk_files.Size - 1

        'Get a file name
        wrk_str = wrk_files.Get(wrk_ptr)
'Log(1)
        'If not another directory...
        If Not(File.IsDirectory(File.DirAssets, wrk_str)) Then
'Log(2)     
            Log(wrk_str)
     
        End If
     
    Next

End Sub

The IDE log says:
Application_Start
Ignoring release logger in debug mode.
Application_Active
_assets_map
beep.mp3
radiobutton_off.png
radiobutton_on.png
wmm2010.cof
wmm2015.cof

Which is what you would expect, given the files in the projects assets.

If you delete the installed Bug app from the phone, uncomment the 2 Log statements in Page1_resize and then run it in release mode it dies a nasty death at the statement:

If Not(File.IsDirectory(File.DirAssets, wrk_str)) Then

The B4iLogger saying:
1
Error getting attributes: Error Domain=NSCocoaErrorDomain Code=260 "The file ?bug? couldn?t be opened because there is no such file." UserInfo={NSFilePath=/var/containers/Bundle/Application/EF720F73-8649-48C5-A294-FDE144B3F99F/Bug.app/bug, NSUnderlyingError=0x15e34450 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}
Stack Trace: (
CoreFoundation <redacted> + 152
libobjc.A.dylib objc_exception_throw + 38
CoreFoundation <redacted> + 0
Bug -[B4IFile GetAttributes::] + 426
Bug -[B4IFile IsDirectory::] + 90
Bug -[b4i_main _page1_resize::] + 1224
CoreFoundation <redacted> + 68
CoreFoundation <redacted> + 300
Bug +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1784
Bug -[B4I raiseEvent:event:params:] + 634
Bug +[B4IObjectWrapper raiseEvent:::] + 220
Bug __30-[B4IPanelView layoutSubviews]_block_invoke + 1040
libdispatch.dylib <redacted> + 10
libdispatch.dylib <redacted> + 22
libdispatch.dylib _dispatch_main_queue_callback_4CF + 902
CoreFoundation <redacted> + 8
CoreFoundation <redacted> + 848
CoreFoundation CFRunLoopRunSpecific + 470
CoreFoundation CFRunLoopRunInMode + 104
GraphicsServices GSEventRunModal + 80
UIKit UIApplicationMain + 150
Bug main + 106
libdyld.dylib <redacted> + 2
)

Additional information - if you reconfigure the last couple of lines as follows:
B4X:
    'For all files...
    For wrk_ptr = 0 To wrk_files.Size - 1

        'Get a file name
        wrk_str = wrk_files.Get(wrk_ptr)
'Log(1)
        'If not another directory...
        'If Not(File.IsDirectory(File.DirAssets, wrk_str)) Then
'Log(2)     
            Log(wrk_str)
     
        'End If
     
    Next

And run it again in release mode, the B4iLogger says:
Bug
[email protected]
[email protected]
[email protected]
Default-Portrait.png
[email protected]
[email protected]
Info.plist
PkgInfo
_CodeSignature
beep.mp3
consolas-bold.ttf
consolas.ttf
embedded.mobileprovision
icon-60.png
[email protected]
icon-76.png
[email protected]
radiobutton_off.png
radiobutton_on.png
wmm2010.cof
wmm2015.cof

Which is decidedly not what is in the assets of the project.

Please tell me this is a bug...
 

Attachments

  • Bug.zip
    444.3 KB · Views: 255
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
Note that you should post bug reports in the bugs forum.
There is no bug here. File.DirAssets is a special folder. In debug mode it is stored as a regular folder (to allow quick deployments).

You shouldn't use File.ListFiles with the assets folder. I will add a note about it in the documentation. Note that it is also true in B4J and B4A.
 
Upvote 0

JackKirk

Well-Known Member
Licensed User
Longtime User
You shouldn't use File.ListFiles with the assets folder. I will add a note about it in the documentation. Note that it is also true in B4J and B4A.

This came about because of my porting a B4A app to B4I - it has been working fine in the B4A app for some months.

I grant that it could be considered unnecessary to use ListFiles on the assets seeing as how the assets are static at compile time - however this means I have to remember to update the alternative everytime I add something to the assets and recompile.
 
Upvote 0
Top