CosmosOS / Cosmos

Cosmos is an operating system "construction kit". Build your own OS using managed languages such as C#, VB.NET, and more!
https://www.goCosmos.org
BSD 3-Clause "New" or "Revised" License
2.88k stars 543 forks source link

Creating GUI gives an error with COSMOS. #3035

Open SanskarSontakke opened 1 week ago

SanskarSontakke commented 1 week ago

I was creating a simple COSMOS 2022 GUI with C# .

COSMOS version : 2022 (latest which is available on the COSMOS website). Visual Studio version : 2022 (latest). After running the code it says "NULL reference exception occurred. halting Now" Here's the screen shot

image_2024-06-28_200758535

Here is my Code in Before Run and Run function :

using System;
using System.Collections.Generic;
using System.Text;
using Sys = Cosmos.System;
using CosmosKernel.Commands;
using Cosmos.System.FileSystem;
using Cosmos.System.Graphics;
using Cosmos.System.Graphics.Fonts;
using Cosmos.System.Graphics.Extensions;
using Cosmos.System;
using System.Drawing;

namespace CosmosKernel
{
    public class Kernel : Sys.Kernel
    {

        private Canvas canvas;
        private Pen pen;
        private List<Tuple<Sys.Graphics.Point, Color>> savedPixels;
        private MouseState prevMouseState;

        private UInt32 px, py;

        void DelayInMS(int ms) // Stops the code for milliseconds and then resumes it (Basically It's delay)
        {
            for (int i = 0; i < ms * 100000; i++)
            {
                ;
                ;
                ;
                ;
                ;
            }
        }

        protected override void BeforeRun()
        {
            System.Console.Clear();
            System.Console.WriteLine("\n\n");
            System.Console.ForegroundColor = System.ConsoleColor.Green;
            System.Console.WriteLine("VFS                  :OK");
            System.Console.WriteLine("Command manager      :OK");
            System.Console.WriteLine("Cosmos boot          :OK");

            DelayInMS(10000);
            System.Console.ForegroundColor = System.ConsoleColor.White;
            System.Console.Clear();

            System.Console.WriteLine("Booted successfully you can write any command. \n");
        }

        protected override void Run()
        {
            Canvas canvas = FullScreenCanvas.GetCurrentFullScreenCanvas();
            canvas.Clear(Color.Black);
            System.Console.WriteLine(response);
        }
    }
}

The compiler does not give me ant error while compiling. The only thing I know that it runs totally fine until it executes this line : Canvas canvas = FullScreenCanvas.GetCurrentFullScreenCanvas();

The DelayInMS() function is already declared and has no problems.

Area of Cosmos - I am using COSMOS 2022 user kit (trying to create GUI).

Expected Behaviour - I think so that the screen should turn completely black.

Actual Behaviour - It gives an CPU Execption

Reproduction - Just use the same configuration and the same code

Version - I am using COSMOS 2022 user kit.

selkij commented 1 week ago

Please do not use the user kit as it is severely outdated. I'd recommend using the devkit instead, there is a tutorial on how to do it here:

https://cosmosos.github.io/articles/Installation/DevKit.html