Bug?

RaspberryDJ

Member
Joined
Jun 3, 2019
I tried this example in MacOS Desktop, and I saw these black squares around the arrows?
HTML works as it should. I haven't had opportunity to try other platforms yet.
Maybe someone could try this on Windows Desktop and see if they get the same black squares?

624


Cerberus X:
Import mojo2

Global blockw:Int=32
Global blockh:Int=32

Class block
    Field x:Int
    Field y:Int   
    Field tx:Int
    Field ty:Int
    Field movedown:Bool=False
    Method New(x:Int,y:Int)
        Self.x = x
        Self.y = y
    End Method
End Class

Class machine
    Field map:Bool[][]
    Field mapwidth:Int
    Field mapheight:Int
    Field myblock:List<block> = New List<block>
    Method New(mapwidth:Int,mapheight:Int)   
        Self.mapwidth = mapwidth
        Self.mapheight = mapheight
        map = New Bool[mapwidth][]
        For Local i=0 Until mapwidth
            map[i] = New Bool[mapheight]
        Next
        For Local i=0 Until 50
            Local x:Int=Rnd(0,mapwidth)
            Local y:Int=Rnd(0,mapheight)
            createblock(x,y)
        Next
    End Method
    
    Method update()
        addblocks()
        destroyblocks()
        For Local i1:=Eachin myblock
            i1.movedown = False
            If i1.y+1 < mapheight Then
                i1.movedown = True
                If map[i1.x][i1.y+1] = True Then i1.movedown = False
            End If
        Next
        For Local i1:=Eachin myblock
            If i1.movedown = True
                map[i1.x][i1.y] = False
                map[i1.x][i1.y+1] = True
                i1.y += 1   
            End If
        Next
    End Method
    
    Method destroyblocks()
        Local ch:Int=(GetDate[5]*10)+5       
        For Local i:=Eachin myblock
            If Rnd(0,ch)<2
                map[i.x][i.y] = False
                myblock.Remove(i)
            End If
        Next
    End Method
    
    Method addblocks()
        Local gw:Int[mapwidth]
        For Local i:=Eachin myblock
            gw[i.x]+=1
        Next
        For Local i=0 Until mapwidth
            If Rnd(0,100)<3
                If gw[i] < mapheight/1.2
                    createblock(i,0)
                End If
            End If
        Next
    End Method
    
    Method createblock(x:Int,y:Int)
        If map[x][y] = True Then Return
        map[x][y] = true
        myblock.AddLast(New block(x,y))
    End Method
    
    Method blockexists:Bool(x:Int,y:Int)
        For Local i:=Eachin myblock
            If i.x = x And i.y = y Then Return True
        Next
        Return False
    End Method
    
    Method draw(imagecanvas:Canvas)
        'DebugLog 15.0/10.0
        Local cy:Float = 1.0/15.0
        For Local i:=Eachin myblock
            Local a:Float = cy*i.y
            imagecanvas.SetColor(a,a,0)
            imagecanvas.DrawRect(i.x*blockw,i.y*blockh,blockw,blockh)
        Next
    End Method
    
End Class

Class grid
    Field image:Image
    Field imagecanvas:Canvas
    Field gridw:Int
    Field gridh:Int
    Field cellw:Int
    Field cellh:Int
    
    Method New(width:Int,height:Int,cellw:Int,cellh:Int)
        Self.gridw = width
        Self.gridh = height
        Self.cellw = cellw
        Self.cellh = cellh
        image = New Image(width,height)
        image.SetHandle(0,0)
        imagecanvas = New Canvas(image)
        createimage()       
    End Method
    
    Method createimage()
        Local x:Int=0
        Local y:Int=0
        Local exitloop:Bool=False
        'imagecanvas.SetColor(1,1,1)
        Local cy:Float=1.0/gridh
        While exitloop = False
            imagecanvas.SetColor(1-cy*y,0,0)
            imagecanvas.DrawLine(x,y,x+cellw,y)
            imagecanvas.DrawLine(x,y,x,y+cellh)
            x+=cellw
            If x>gridw Then
                x=0
                y+=cellh
            End If
            If y>gridh Then exitloop = True
        Wend
        imagecanvas.Flush()
    End Method
End Class

Class arrow
    Field image:Image
    Field imagecanvas:Canvas
    Method New(width:Int,height:Int)
        image = New Image(width,height)
        imagecanvas = New Canvas(image)
        createimage()
    End Method
    
    Method createimage()
        imagecanvas.SetColor 1,1,1
        Local w:Float=image.Width()
        Local h:Float=image.Height()
        Local pol:Float[14]
        pol[0] = 0
        pol[1] = h/2       
        pol[2] = w/3
        pol[3] = h       
        pol[4] = w/3
        pol[5] = h/1.5       
        pol[6] = w
        pol[7] = h/1.5       
        pol[8] = w
        pol[9] = h/3       
        pol[10] = w/3
        pol[11] = 0+h/3       
        pol[12] = w/3
        pol[13] = 0
        imagecanvas.DrawPoly(pol)
        imagecanvas.Flush
    End Method
End Class

Global myarrow:arrow
Global mygrid:grid
Global mymachine:machine

Class MyApp Extends App
    Field canvas:Canvas
    Field angle:Int=0
    
    Method OnCreate()
        SetUpdateRate(60)
        myarrow = New arrow(100,50)
        mygrid = New grid(DeviceWidth(),DeviceHeight(),32,32)
        mymachine = New machine(32,15)
        canvas=New Canvas
    End Method
    
    Method OnUpdate()
        angle+=1
        If angle>359 Then angle = 0
        mymachine.update
    End Method
    
    Method OnRender()
        canvas.Clear 0,0,0
        canvas.SetColor(1,1,1)
        canvas.DrawImage(mygrid.image,0,0)   
        mymachine.draw(canvas)
        canvas.SetColor(0,0,1)
        Local x:Int,y:Int
        Local exitloop:Bool=False
        Local switch:Int=0
        While exitloop = False
            Local myangle:Int
            If switch=0 Then myangle=angle Else myangle=360-angle
            canvas.DrawImage(myarrow.image,x,y,myangle)
            switch+=1           
            If switch=2 Then switch=0
            x+=164       
            If x>DeviceWidth()+164
                x=0
                y+=96
                If y>DeviceHeight()+96 Then exitloop = True
            End If           
        Wend
        canvas.Flush
    End
End Class

Function Main()
    New MyApp
End
 

MikeHart

Administrator
Staff member
Joined
Jun 19, 2017
Location
Germany
On my mac mini, running OSX 10.14.5 HTML5 and Desktop look the same. No black boxes.
 

RaspberryDJ

Member
Joined
Jun 3, 2019
A third time gives a third result. This one should give a clue for someone I hope. You can see letters very clearly.
It is as if the arrows are drawn on some residue each time instead of on top of a clear canvas.

I might add that Mojo2 always works great otherwise. It's just this example that behaves like this.


626
 

RaspberryDJ

Member
Joined
Jun 3, 2019
This fixed it.

Fixed:
Method createimage()
        imagecanvas.Clear 0,0,0,0  '  clear
        imagecanvas.SetColor 1,1,1
        Local w:Float=image.Width()
        Local h:Float=image.Height()
        Local pol:Float[14]
        pol[0] = 0
        pol[1] = h/2       
        pol[2] = w/3
        pol[3] = h       
        pol[4] = w/3
        pol[5] = h/1.5       
        pol[6] = w
        pol[7] = h/1.5       
        pol[8] = w
        pol[9] = h/3       
        pol[10] = w/3
        pol[11] = 0+h/3       
        pol[12] = w/3
        pol[13] = 0
        imagecanvas.DrawPoly(pol)
        imagecanvas.Flush
    End Method
End Class
 

rickychus

Member
Joined
Sep 26, 2017
Hello,
Under Linux (Lubuntu 18.04 32 bits) these graphic errors are not seen.
Regards R.-

628
 

RaspberryDJ

Member
Joined
Jun 3, 2019
@MikeHart @rickychus
Thanks for validating!

Wonder if it is graphiccard-specific then? I got a Intel HD 6000 (Mid 2015 MacBook Air).
I had this demo for a while and.I can add that I've never seen this error on other machines or under Monkey-X.
 

MikeHart

Administrator
Staff member
Joined
Jun 19, 2017
Location
Germany
Wonder if it is graphiccard-specific then? I got a Intel HD 6000 (Mid 2015 MacBook Air).
Good morning. Guess what, I got this weird behaviour now too.

629


And the image below the arrow is the logo from the help pages. So the memory of the image is already preloaded with something.
Without clearing it, it will draw whatever it finds.
 

rickychus

Member
Joined
Sep 26, 2017
Hello,
My Netbook has an intel atom N2600 (2012), graphics GMA 3600. Pretty old compared to what there is now. It works well in this PC on Linux.
Mike made the error happen on his PC, But in mine it does not happen.
Maybe it's the way the OS manages the graphic memory?
Regards R.-
 

MikeHart

Administrator
Staff member
Joined
Jun 19, 2017
Location
Germany
Maybe it's the way the OS manages the graphic memory?
I think that is exactly what is happening here. OSX is doing it differently. And I am not tempted to dig into this. Sooner or later I will have to look into implementing Metal for Apple's platforms and then we will see how it is behaving.
 

RaspberryDJ

Member
Joined
Jun 3, 2019
I'm certain that this bug came around when Mark made Monkey 87a. It will always work in 86e, for you who have Monkey-X 86e you can try it yourself. On all hardware and OS I own it works.

In version 87a it went unstable like above. Mojo2 also became slower.
 
Top Bottom