SpecialFolder.GetResource CRASHES on Windows

I discovered that calling SpecialFolder.GetResource on Windows CRASHES on the second attempt, giving a Windows Access Violation exception.

In the example below both files are correctly copied into the resources folder via a CopyFiles build step. And either file can be located correctly if it’s tried first. But the second attempt will always crash regardless of which file is tried first vs second. So the issue isn’t related to the particular files. FWIW The ShellPath to the first file seems a bit wonky, the last character is missing. However the NativePath and the AbsolutePath seem correct. So something may be corrupted from the first GetResource call resulting in a crash on the second call.

The workaround I found is to use the Parent folderitem from the first call to directly create my own reference to the second file.

[code]dim CityFile, ISPFile as FolderItem
Try
// The second call to SpecialFolder.GetResource crashes on Win7, both 32 and 64 bit Xojo builds
’ CityFile = GetFolderItem (Xojo.IO.SpecialFolder.GetResource(“GeoLite2-City.mmdb”).Path, FolderItem.PathTypeNative)
’ ISPFile = GetFolderItem (Xojo.IO.SpecialFolder.GetResource(“GeoIP2-ISP.mmdb”).Path, FolderItem.PathTypeNative)

 // This code works OK
  CityFile = GetFolderItem (Xojo.IO.SpecialFolder.GetResource("GeoLite2-City.mmdb").Path, FolderItem.PathTypeNative)
  ISPFile = CityFile.Parent.Child("GeoIP2-ISP.mmdb")
  
Catch
  Log "LocationLookup_GeoLite2: Unable to find MaxMind mmdb database"
End Try[/code]

Please file a bug report.

I had added my comments onto an existing similar report <https://xojo.com/issue/40076>

I hope to come up with a small demo program to help easily reproduce the problem which I’ll attached to a separate report.

Indeed GetResource cannot be used like other SpecialFolder. This was discussed during the beta of iOS : the file MUST be there. AFAIK this is intended.

The solution is to use a Try Catch when you are not sure the resource is actually present.

Yes, but it shouldn’t crash.

Well, it did crash very well in iOS , I filed a report during 2015R1 beta, and got a “by design” reply explaining it did trigger an exception. that should be handled Maybe that is the same here.
<https://xojo.com/issue/37504>

Your example fires an exception on iOS. Unhandled exceptions (regardless of cause) on iOS always terminate. That is different from the Windows platform issue being discussed here.

Just tried on Windows. The execution is xojo.Core.InvalidArgumentException and it can be trapped very nicely in Try Catch.

What is more surprising is that App.Unhandled Exception does not fire.

Michel Yes I had read the separate issue with the file needing to exist. (And note that this code DOES use Try Catch for just that reason.)

In this case BOTH files do exist, either one can be obtained successfully if it’s the FIRST call to GetResource. But it’s the SECOND call to GetResource that crashes (Windows Access exception), even though that file does exist.

This behavior is 100% reproducible in my app, and I hope it stays that way in a small demo app. FWIW It occurs via the remote debugger and also in built 32 bit and 64 bit apps when run on Windows 7.

Also note that both calls to GetResource work fine on OSX builds.

Michel Did you try it with TWO separate files both of which DO exist?

And running on WINDOWS?

JoeR: OK I created a very simple two line demo app that crashes 100% of the time. I submitted a Feedback item.

(https://xojo.com/issue/43588)>]43588 - SpecialFolder GetResource crashes when called twice on Windows

The Xojo folks have confirmed and fixed this crash.

William, thanks for the quick attention to this.

Cheers, Joe

<https://xojo.com/issue/43588>

you dont need to wrap the URL in URL tags

That’s good to know.

That was 3 days ago so I don’t remember exactly what I did at the time. Nor even what I had for breakfast this morning. :slight_smile:

But next time I’ll try to not do whatever it was that I did this time… :slight_smile:

Cheers,
Joe Huber

In feedback you can just use the “Copy Sharing link” and paste it in the forum
Nothing special needs to be done with it beyond that