B4J Question Error B4XCanvas.DrawRect

ivanomonti

Expert
Licensed User
Longtime User
mi ritrovo sempre questo errore quando faccio il debug su Microsoft Surface pro, cosa che non capita su tradizionali computer da tavolo pentuim i5 (lenovo), e non so dove sbattere la testa.

I always find this mistake when I debug on Microsoft Surface pro, something that doesn't happen on traditional pentuim i5 (lenovo) desktop computers, and I don't know where to hit my head.


B4X:
Waiting for debugger to connect...
Program started.
apr 14, 2020 9:35:13 PM com.sun.javafx.css.parser.CSSParser term
WARNING: CSS Error parsing file:/C:/Users/Surface%20Pro%204/Desktop/LavagbaB4XUI/Files/dark.css: Unexpected token ';' at [64,25]
Errore nella linea: 175 (Main)
java.lang.NullPointerException
    at anywheresoftware.b4a.objects.B4XCanvas.DrawRect(B4XCanvas.java:93)
    at b4j.example.main._linegroup(main.java:420)
    at b4j.example.menusx._bt_action(menusx.java:178)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:632)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
    at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
    at anywheresoftware.b4a.BA$1.run(BA.java:216)
    at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
    at java.lang.Thread.run(Thread.java:748)



incriminated code, again under B4XCanvas:
Sub iniGriglia As Boolean
    griglia.Initialize(lavagna)
    background( griglia, 252526)
    Dim x0,y0,x1,y1
    x0=0
    y0=0
    x1=0
    y1=lavagna.Height
    For i=0 To lavagna.Width
        griglia.DrawLine(x0,y0,x1,y1,xui.Color_DarkGray,0.5)
        x0 = x0+10
        x1=x0
    Next
    x0=0
    y0=0
    x1=lavagna.Width
    y1=0
    For i=0 To lavagna.Height
        griglia.DrawLine(x0,y0,x1,y1,xui.Color_DarkGray,0.5)
        y0 = y0+10
        y1=y0
    Next
    Return True
End Sub

'-------------------------- gioco di linee gruppo ----------------------------------------------------------

Sub iniGroup As Boolean
    groupline.Initialize(lavagna)
    background( groupline,252526)
    Return True
End Sub

Sub LineGroup
    
    Dim  cvsRect As B4XRect
    cvsRect.Left=0
    cvsRect.Top=0
    cvsRect.Width=lavagna.Width
    cvsRect.Height=lavagna.Height
    
    groupline.ClearRect(cvsRect)
    groupline.Invalidate
    
    background( groupline,252526)
    
    If groupValue = False Then Return
    
    'crea base rettangolare colorata
    
    listSlave.Clear
    listMaster.Clear
    
    For i = 0 To lavagna.NumberOfViews-1
        If lavagna.GetView(i) Is Button Then
            Dim ls As List = lavagna.GetView(i).Tag
            ' leggo appartenenza se master or slave
        If ls.Get(18) = "master"  Then
                listMaster.Add(ls)
            Else
                listSlave.Add(ls)
            End If
            ' credo il rect da disegnare
            Dim  cvsRect As B4XRect
            cvsRect.Left=lavagna.GetView(i).Left-1
            cvsRect.Top=lavagna.GetView(i).Top-1
            cvsRect.Width=lavagna.GetView(i).Width+2
            cvsRect.Height=lavagna.GetView(i).Height+4
            groupline.DrawRect(cvsRect,HexToColor(ls.Get(17)) , True,3)
            groupline.Invalidate
        End If
    Next
    
    Dim x,y,x2,y2 As Int
    
    ' crea linee gruppo
    
    For i=0 To listMaster.Size-1
        Dim lsM As List = listMaster.Get(i)
        x = lsM.Get(0) +( lsM.Get(2)/2)
        y = lsM.Get(1) +( lsM.Get(3)/2)
        For ii=0 To listSlave.Size-1
            Dim lsS As List = listSlave.Get(ii)
            If lsS.Get(16) = lsM.Get(16) Then
                x2=lsS.Get(0) + ( lsS.Get(2)/2)
                y2=lsS.Get(1) + ( lsS.Get(3)/2)
                groupline.DrawLine(x, y, x2, y2, HexToColor(lsS.Get(17)) ,1)
                groupline.Invalidate
            End If
        Next
    Next

End Sub

'------------------------------------------------------------- codici funzioni -----------------------------------------------

Private Sub ColorToHex(clr As Int) As String
    Dim bc As ByteConverter
    Return bc.HexFromBytes(bc.IntsToBytes(Array As Int(clr)))
End Sub

Private Sub HexToColor(Hex As String) As Int
    Dim bc As ByteConverter
    If Hex.StartsWith("#") Then
        Hex = Hex.SubString(1)
    Else If Hex.StartsWith("0x") Then
        Hex = Hex.SubString(2)
    End If
    Dim ints() As Int = bc.IntsFromBytes(bc.HexToBytes(Hex))
    Return ints(0)
End Sub

Public Sub background(cv As B4XCanvas, color As Int)
    Dim  cvsRect As B4XRect
    cvsRect.Left=0
    cvsRect.Top=0
    cvsRect.Width=lavagna.Width
    cvsRect.Height=lavagna.Height
    cv.DrawRect(cvsRect,color , True,3)
    cv.ClearRect(cvsRect)
    cv.Invalidate
End Sub
 

ivanomonti

Expert
Licensed User
Longtime User
[QUOTE = "Erel, post: 727180, membro: 1"]
Stai usando l'ultima versione di B4J? Il numero di riga in B4XCanvas sembra errato.

L'unica cosa che posso dire dalle informazioni fornite è che una delle tele non è stata inizializzata.
[/CITAZIONE]

all canvases are active (initialized) the problem occurs only on microsoft surface pro, which is not the case on lenovo desktop with same operating system, same b4j, same java

this screen and on desktop

008.jpg
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
[QUOTE = "Erel, post: 727180, membro: 1"]
Stai usando l'ultima versione di B4J? Il numero di riga in B4XCanvas sembra errato.

L'unica cosa che posso dire dalle informazioni fornite è che una delle tele non è stata inizializzata.
[/CITAZIONE]

all canvases are active (initialized) the problem occurs only on microsoft surface pro, which is not the case on lenovo desktop with same operating system, same b4j, same java

this screen and on desktop

View attachment 91887
Even if the error does not present it to you on all platforms, it could still be a programming error.

Initialization Towers Canvas, how many canvases do you use? Do you create a web for each spider web?
Do you initialize it every time you make a change?
Griglia is B4XCanvas? background (grid, 252526) what is it for? Attach the B4XCanvas to a view? Do you use the canvas on a Panel or on an ImageView?

The ideal is to initialize it only at the beginning and along the course of the flow cancel and redraw.

These are all questions that allow me to understand how B4XCanvas works. We need a little more code and information
 
Upvote 0

ivanomonti

Expert
Licensed User
Longtime User
Even if the error does not present it to you on all platforms, it could still be a programming error.

Initialization Towers Canvas, how many canvases do you use? Do you create a web for each spider web?
Do you initialize it every time you make a change?
Griglia is B4XCanvas? background (grid, 252526) what is it for? Attach the B4XCanvas to a view? Do you use the canvas on a Panel or on an ImageView?

The ideal is to initialize it only at the beginning and along the course of the flow cancel and redraw.

These are all questions that allow me to understand how B4XCanvas works. We need a little more code and information


I think at this point that I associated 3 canvases in a single panel and this crashes, because I thought that the canvases were indipendent objects.

b4J 8.10
java 8
windows pro 10

in both pc
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
I think at this point that I associated 3 canvases in a single panel and this crashes, because I thought that the canvases were indipendent objects.

b4J 8.10
java 8
windows pro 10

in both pc
The canvases on B4j are different than ba4a / b4i.

Whenever you initialize a panel with canvas, it adds an ImageView to the panel. If you initialize it multiple times, multiple imageviews overlap.

If instead you initialize an ImageView, the canvas is associated with the background image of the view.

Lavagna what view is it?
 
Upvote 0

ivanomonti

Expert
Licensed User
Longtime User
I found the problem that is not in the code but in a setting of the B4XCanvas, my canvas goes in horizonatle since I put many subjects, not wanting to scroll vertically (but without thinking about it) I put a value that exceeded 4100px then I discovered that setting it up to a maximum of Width=4096 the error disappears.

The maximum px is 4096 otherwise the error returns.

What I don't understand and why does it happen on microsoft surface and not also on the desktop?


B4X:
#Region Project Attributes
    #MainFormWidth: 600
    #MainFormHeight: 600
#End Region

Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private cv As B4XCanvas
    Private pn As B4XView
    Private sv As ScrollPane
    Private xui As XUI
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.Show
    MainForm.Stylesheets.Add(File.GetUri(File.DirAssets, "dark.css"))
    pn=xui.CreatePanel("")
    sv.Initialize("")
    sv.InnerNode = pn
    MainForm.RootPane.AddNode(sv,0,0,600,600)
    pn.Width=4096 ' <<<<<<<<<<<<<<<<<<<<<< error pn.Width = 4097 or >
    pn.Height=600*2
    cv.Initialize(pn)
    iniGriglia
End Sub

'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Return True
End Sub

Sub iniGriglia As Boolean
    Dim x0,y0,x1,y1
    x0=0
    y0=0
    x1=0
    y1=pn.Height
    For i=0 To pn.Width
        cv.DrawLine(x0,y0,x1,y1,xui.Color_DarkGray,0.5)
        x0 = x0+10
        x1=x0
    Next
    x0=0
    y0=0
    x1=pn.Width
    y1=0
    For i=0 To pn.Height
        cv.DrawLine(x0,y0,x1,y1,xui.Color_DarkGray,0.5)
        y0 = y0+10
        y1=y0
    Next
    Return True
End Sub
 
Upvote 0
Top