Skip to content

Creating GUI gives an error with COSMOS. #3035

@SanskarSontakke

Description

@SanskarSontakke

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions