Thread Already Started

    private void Start()
    {
        PAINTER = new Thread(PROCESSPIX);
    }
Thread PAINTER;
void Update()
    {
       if (PAINTER != null && PAINTER.IsAlive == false)
           PAINTER.Start();
    }

Error ThreadStateException: Thread has already been started.

But I thought checking for null and is alive would confirm it was started and to not try to start it.

    void PROCESSPIX()
    {
        PIXEL.PAINTPIX2(MOUSEX, MOUSEY, PAINTER);
    }

at the end of the above method i also attempted to abort when the function is complete.

The purpose is so that the update can keep up with the mouse cursor. As currently Mouse X and Mouse Y cannot modify my pixels array at the same speed the System Cursor uses. As it would do in built in paint software, or third party paint software, all seem to contain the ability to smoothly update and register. So I assumed threading was the solution. I have no problem with how to go about applying texture on the main thread, but the sub thread is used to update the raw pixels array. And although i get the one dot on screen the thread is able to return exception error proclaiming the thread has already started and i am requesting to start it multiple times. Which as you may tell by above code, it appears that is not what i am doing. So not sure if i just don’t understand threading yet, i forgot, or if that check is unreliable or what.

Any idea’s please throw them this way.

Threads cannot be restarted after they terminate.

I don’t really see how multithreading could be a solution here? You’re also only starting this thread once per frame anyway so… I don’t really understand what you think this is going to do really.

The solution here is just to interpolate the line between the positions the mouse was at between frames.

1 Like

Issue is that mouse position can move faster and further than update method can register changes.

For example

Mouse X = 200

on mouse move next value is 202.

So the system sensitivity of the mouse is faster than update detection of change. or so it seems.

I am just trying out methods to get around it or else I will have to write program window from scratch on VS studio and not use Unity.

that’s not really your issue at all actually. The mouse can skip pixels even if you have 1/1 hardware tracking. You need to interpolate your line between the new point and the last known point.

1 Like

Il give a go.

On get mouse il grab current position load it to prev position and then interpolate between the values repeatedly for each missing area that is produced for some limit. Though not sure it will be as fluid as it sounds. As fluid as Microsoft paint for example.
But

I have nothing better to do.

The problem with interpolate is that I draw an arc or a straight line in place during the missing time skip. And so this does not fluidly follow, and gives laggy looking results. Draws attention to the lag. For example if i rapidly scribble. The in betweens are not actually following what I did.

i guess il try something else

Thanks anyway

What do you say if I suggest Core instead of Mono? Or an alternative to mono? Do you Suspect any change in update speed?

So i ran some tests.

I ran Coroutine and conclude it runs at same speed as update. No additional frames.
I ran fixed update and made it update at lowest possible speed. Some additional frames.
Still can’t perform this functionality though. The info isn’t in the public domain.
Various reasons why is that you can profit from the information. One such method to profit from the information would be to produce art software using the technique. And as it seems in the modern world profit is preserved exclusively for the authority.

Coroutine, and Update, and Fixed Update will not run at operating system mouse speed in this coding language.

Sorry in advance for the tripple post here.

Could it be possible i need to check mouse position on all of :

Coroutine
Update,
Fixed Update
and
Late Update
Every Frame

The answer is no. There will be some other method not known. Or a different language

You stil have the wrong idea how mouse input works. As PraetorBlue already said, even the hardware mouse cursor does not move continuously but jumps as well. MS Paint does draw straight lines between points when you use the free hand pen / pencil. I’ve written a simple script for the question over here which essentially asks the same thing.
8443184--1119272--TextureLineDrawing.gif

1 Like

Thanks buns I’ll sleep on it and fresh mind it in the morning

So this is simple interpolation.
Prev position
Fix in between
Looks smooth as hell.

I didn’t raycast my mouse click I created image then set it’s rect to screen width and height and grabbed that mouse position raw without ray and used that. But I see the logic I’ll get something productive done about it tomorrow

my circle brush is a circle within circles if you get what I mean. Up to the brush width. I have a square brush aswell that is scaled to the same size as the circle brush. If you know what I mean.

thanks for the example I honestly see that cursor on screen in windows moving real fast lol and it looks perfect so maybe I am pessimistic about the lines I shall just proceed to obtain the quality of the above example.

         float X = PREVX;
         float Y = PREVY;
         for (int x = 0; x < JOINSENS; x++)
         {
             X = Mathf.Lerp(X, MOUSEX, 0.001f);
             Y = Mathf.Lerp(Y, MOUSEY, 0.001f);
             if (!SPARES.Contains(new Vector2Int((int)X, (int)Y)))
                 SPARES.Add(new Vector2Int((int)X, (int)Y));
         }

        for (int i = 0; i < SPARES.Count; i++)
        {
            PIXEL.PAINTPIX(SPARES[i].x, SPARES[i].y);
        }
        // if (SPARES.Count > 0)
        // SPARES.RemoveAt(0);
        SPARES = new List<Vector2Int>();

Yeah i’m on track guys Thanks you both. I did a Trib in the video

edit
Here is an Optimal SQR pretty good

1 Like

In know it’s a mess and looks like a bunch of scribbles to most. But there’s quite abit of freedom here to build interesting things on top.

Circles within circles for a pixel based circle brush is the wrong way to go. It is not optimal works at small sizes won’t work with the joiner algorithm. So you’d probably want a diamond brush knock the corners off a square. And then mould that into a circle. For optima. I imagine.

or create a few lists containing data of preset circle sizes regarding how many either side from each row relevant to mouse position to paint out the circle. Instead of actually math pi’ing it at runtime

here is final end of night version
Auto adjust sensitivity vs brush size and speed of mouse movement _-- >

realistically though