Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File.Exists() causes CPU Exception #3028

Open
JeffTheK opened this issue May 30, 2024 · 8 comments
Open

File.Exists() causes CPU Exception #3028

JeffTheK opened this issue May 30, 2024 · 8 comments
Labels

Comments

@JeffTheK
Copy link

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 JeffTheK added the Bug label May 30, 2024
@blackneeed
Copy link
Contributor

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

@blackneeed
Copy link
Contributor

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

@JeffTheK
Copy link
Author

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

@JeffTheK
Copy link
Author

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

@JeffTheK
Copy link
Author

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

@zarlo
Copy link
Member

zarlo commented Jun 11, 2024

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

@ADev531
Copy link

ADev531 commented Jun 23, 2024

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

@zarlo
Copy link
Member

zarlo commented Jun 23, 2024

it works most of the time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants