abbruzze / kernal64

A Scala Commodore 64, 128, VIC20, CBM2 and SuperCPU emulator
MIT License
112 stars 12 forks source link

java.lang.NullPointerException when attaching disk images #18

Closed silverdr closed 2 years ago

silverdr commented 2 years ago

When attaching disk image with --drive8-file diskimage.d64 an exception is thrown (even thought the image seems to get attached correctly):

java.lang.NullPointerException
    at ucesoft.cbm.CBMComputer.attachDiskFile(CBMComputer.scala:439)
    at ucesoft.cbm.CBMComputer.attachDiskFile$(CBMComputer.scala:420)
    at ucesoft.cbm.c64.C64.attachDiskFile(C64.scala:23)
    at ucesoft.cbm.CBMComputer.$anonfun$setDrivesSettings$3(CBMComputer.scala:2100)
    at ucesoft.cbm.CBMComputer.$anonfun$setDrivesSettings$3$adapted(CBMComputer.scala:2099)
    at ucesoft.cbm.misc.Preferences$Preference$$anon$1.preferenceHasChanged(Preferences.scala:103)
    at ucesoft.cbm.misc.Preferences$Preference.$anonfun$notifyListeners$1(Preferences.scala:108)
    at ucesoft.cbm.misc.Preferences$Preference.$anonfun$notifyListeners$1$adapted(Preferences.scala:108)
    at scala.collection.immutable.List.foreach(List.scala:312)
    at ucesoft.cbm.misc.Preferences$Preference.notifyListeners(Preferences.scala:108)
    at ucesoft.cbm.misc.Preferences$Preference.load(Preferences.scala:128)
    at ucesoft.cbm.misc.Preferences$Preference.load(Preferences.scala:117)
    at ucesoft.cbm.misc.Preferences.parseAndLoad(Preferences.scala:202)
    at ucesoft.cbm.CBMComputer.loadSettings(CBMComputer.scala:397)
    at ucesoft.cbm.CBMComputer.loadSettings$(CBMComputer.scala:391)
    at ucesoft.cbm.c64.C64.loadSettings(C64.scala:23)
    at ucesoft.cbm.c64.C64.turnOn(C64.scala:474)
    at ucesoft.cbm.CBMComputer$.turnOn(CBMComputer.scala:41)
    at ucesoft.cbm.c64.C64$.delayedEndpoint$ucesoft$cbm$c64$C64$1(C64.scala:20)
    at ucesoft.cbm.c64.C64$delayedInit$body.apply(C64.scala:19)
    at scala.Function0.apply$mcV$sp(Function0.scala:39)
    at scala.Function0.apply$mcV$sp$(Function0.scala:39)
    at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:17)
    at scala.App.$anonfun$main$1(App.scala:75)
    at scala.App.$anonfun$main$1$adapted(App.scala:75)
    at scala.collection.IterableOnceOps.foreach(IterableOnce.scala:576)
    at scala.collection.IterableOnceOps.foreach$(IterableOnce.scala:574)
    at scala.collection.AbstractIterable.foreach(Iterable.scala:904)
    at scala.App.main(App.scala:75)
    at scala.App.main$(App.scala:73)
    at ucesoft.cbm.c64.C64$.main(C64.scala:19)
    at ucesoft.cbm.c64.C64.main(C64.scala)
[Disk attaching error] java.lang.NullPointerException
abbruzze commented 2 years ago

Hi @silverdr and happy to see you again. Which version are you using ? I tried with the latest one and have no issue.

I checked the line of code that generated the problem: it get the parent directory of the selected file; sometimes happens that, depending on the OS, this directory is not retrivied and JDK returns null. Can you send me the path of the selected file ?

Please, can you try with the same file on a different directory ?

Bye

silverdr commented 2 years ago

Alessandro, I apologise for not mentioning the version, I obviously tried the latest released one:

https://github.com/abbruzze/kernal64/releases/tag/v1.7.3b4

Full path to the disk image file is: /Users/silverdr/sources/silverdr/64er_sources/jema_n_silver/jema_n_silver.d64 and I start k64.sh with: /Applications/local/emu/kernal64/k64.sh --warponload --beam-racer-enabled --drive8-file jema_n_silver.d64 --run-file jema_n_silver.c64 When I move up one level and start with: /Applications/local/emu/kernal64/k64.sh --warponload --beam-racer-enabled --drive8-file jema_n_silver/jema_n_silver.d64 --run-file jema_n_silver.c64 The exception is in fact NOT thrown

abbruzze commented 2 years ago

Ok, don't why but seems an OS's filesystem related issue.

Hey, if you have new BeamRacer demo, please, send me a preview!

silverdr commented 2 years ago

Hm, there are no fancy characters in the path, not even spaces… regular POSIX stuff works normally. Can't say what that could be. Right, I am trying to build a small demo. Shall remember to send you! ;-)

silverdr commented 2 years ago

FWIW - I don't think this is a filesystem issue. As I mentioned all regular POSIX stuff works on that filesystem, but a wild guess... I didn't check your sources on that but might it be that whatever method you use there does not utilise any POSIX functions for filesystem traversal but rather decomposes the path string? In such case that could explain the behaviour where there's more than one path component, then the parent is not null but if there's only one (the actual filename) then there's no parent there.. does this make any sense? ;-)

silverdr commented 2 years ago

I just confirmed - I am getting the same exception thrown on two different OS/filesystem combinations. Whether Macos and APFS or GNU/Linux and ext4fs the exception is there.

abbruzze commented 2 years ago

I got it: the problem arises when you specify a file relative to the current directory (without any path). Unfortunately, the Java API File.getParentFile returns null in this case. A stupid workaround is to prefix it with ./ I will check this case and force the prefix on the filename.

silverdr commented 2 years ago

Actually I can do relative path spec. My guess is what I mentioned above - that the path string is decomposed to get whatever is before the filename. If you add "something" like ./ or ../parent_dir/ then it gets "something" and returns it instead of nil. Glad to be able to help :-)