Cosmos icon indicating copy to clipboard operation
Cosmos copied to clipboard

File.Exists() causes CPU Exception

Open JeffTheK opened this issue 1 year ago • 9 comments

Area of Cosmos - What area of Cosmos are we dealing with?

FileSystem

Expected Behaviour - What do you think that should happen?

File.Exists should return a bool

Actual Behaviour - What unexpectedly happens?

I get Cosmos CPU Exception, invalid opcode

Reproduction - How did you get this error to appear?

Use System.IO.File.Exists()

Version - Were you using the User Kit or Dev Kit? And what User Kit version or Dev Kit commit (Cosmos, IL2CPU, X#)?

Latest dev kit, running using vmware on linux

Here's my code:

using System;
using System.Collections.Generic;
using System.Text;
using Cosmos.System.FileSystem.VFS;
using Sys = Cosmos.System;

namespace TestKernel
{
    public class Kernel: Sys.Kernel
    {
        Sys.FileSystem.CosmosVFS fs = new Cosmos.System.FileSystem.CosmosVFS();

        protected override void BeforeRun()
        {
            Sys.FileSystem.VFS.VFSManager.RegisterVFS(fs);
            Console.WriteLine("Cosmos booted successfully. Type a line of text to get it echoed back.");
            Console.WriteLine("Testing FileExists");
            try
            {
                Console.WriteLine(System.IO.File.Exists(@"0:\test.txt"));
            }
            catch (System.Exception e)
            {
                Console.WriteLine(e);
            }
        }
        
        protected override void Run()
        {
            Console.Write("Input: ");
            var input = Console.ReadLine();
            Console.Write("Text typed: ");
            Console.WriteLine(input);
        }
    }
}

here's a screenshot of the error image

JeffTheK avatar May 30 '24 15:05 JeffTheK

Try instead of initializing the fs immediately set it to null first and then in beforerun set it to a new instance

blackneeed avatar May 30 '24 15:05 blackneeed

Since it probaly needs to do some more initialization in OnBoot which is called before BeforeRun but if you just init it immediately then its probaly not gonna work. @JeffTheK

blackneeed avatar May 30 '24 15:05 blackneeed

Just tried doing it the way you told me, I still get the same error

JeffTheK avatar May 30 '24 16:05 JeffTheK

In the first code i copied the initialization code from the docs, so i thought it would work

JeffTheK avatar May 30 '24 16:05 JeffTheK

Also Directory.Exists works fine, but File.Exists does not

JeffTheK avatar May 30 '24 16:05 JeffTheK

from memory there is a bug in the exception handler where it will some times kill the system i think it was something to do with stack corruption

zarlo avatar Jun 11 '24 01:06 zarlo

Weird, I'm using old devkit and it's works...

ADev531 avatar Jun 23 '24 03:06 ADev531

it works most of the time

zarlo avatar Jun 23 '24 08:06 zarlo

Try This: if (Sys.FileSystem.VFS.VFSManager.FileExists("0:\Path\To\Your\File")) Console.WriteLine("File Found!"); else Console.WriteLine("File Not Found!"); Or This: if (!Sys.FileSystem.VFS.VFSManager.FileExists("0:\Path\To\Your\File")) Console.WriteLine("File Not Found!"); else Console.WriteLine("File Found!"); If You Did Not Load It Like This Try This: public static CosmosVFS vfs;

protected override void BeforeRun() { vfs = new CosmosVFS(); System.Console.WriteLine("Loaded VFS Part 1 of 2."); // For Debuging Sys.FileSystem.VFS.VFSManager.RegisterVFS(vfs); System.Console.WriteLine("Loaded VFS Part 2 of 2."); // For Debuging }

If It Still Does Not Work Look At My OS On Github: CorgiOS To Try To Fix It If All Else Fails You Can Try: Reinstalling Cosmos Try DevKit Heres A Video I Used When I Needed DevKit: https://www.youtube.com/watch?v=NhTb_Ck6Rfk I Tried As Hard As I Can To Help You Hope This Helped :D

ghost avatar Dec 30 '24 15:12 ghost