Android Question How do you check if a canvas is initialized?

NeoTechni

Well-Known Member
Licensed User
Longtime User
Because I get rare cases where it won't be initialized when I try to draw to it. My code won't really help

B4X:
Sub INITBG
	'API.Trace("INITBG", True)
	If BG = Null Then LCAR.BGisInit = False 
	If Not(LCAR.BGisInit) Then
		BG.Initialize(Activity)
		LCAR.BGisInit=True
		If LCAR.VolText.Length = 0 AND LCAR.VolTextList.Size>0 Then
			LCAR.VolSeconds=0 
			LCAR.VolOpacity=0 
			LCAR.PullNextToast(BG)
		End If
	End If
End Sub

Sub DrawScreen(Interval As Int)
	INITBG	
	If LCAR.NeedsClearing Then LCAR.ClearScreen(BG)
	If NeedsShowFrame Then
		ShowFrame(False,LCARSeffects.NeedsLeftBar)
		NeedsShowFrame=False
		LCAR.IsKeyboardVisible(BG,10,False )
	End If
	
	If Interval> 0 Then LCAR.IncrementLCARs(LCARSpeed , 1,Interval )
	If LCAR.DrawLCARs(BG, 0) Then 	Activity.Invalidate 
End Sub
 
Upvote 0

Walter Adriano da Silva

Member
Licensed User
Longtime User
I always used a canvas in some sub that a draw it. Then I never needed check if it's initialized.

In your case, try initialize the canvas each time you use it
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I don't understand.
Who is the programmer ?
If it's you, I hope you know what you are doing.
Your code snippet is of no use, where do you use the Canvas?
What type of object is LCAR ?
I suspect that the problem is here.

If you really need it, add the canvas as a parameter in the calling sub.
But, for me this is interesting if want to use a same routine with different canvases.
 
Upvote 0

NeoTechni

Well-Known Member
Licensed User
Longtime User
I can't initialize it every time I use it, as that causes a severe drop in framerate. I run at over 70 fps. It only gets initialized when the activity opens, or resumes

Who is the programmer ?
Well that's an odd question. Everyone on this site is a programmer...

I said the code would be of no use, it's not relevant. No the LCAR module is not the problem. That's what uses the canvas. IF ITS INITIALIZED FIRST. So how do I check that?

I just need to know how to check if it's initialized.
 
Upvote 0

NeoTechni

Well-Known Member
Licensed User
Longtime User
I am using a global variable (LCAR.BGisInit) but it's not 100% accurate.
I also check if it's null (If BG = Null Then LCAR.BGisInit = False)
 
Upvote 0

NeoTechni

Well-Known Member
Licensed User
Longtime User
I init it with the activity. But one of my users caught it being null at one point somehow. Null drives me nuts. I can't seem to get "if variable = null then makeitnotbenull" to work...
 
Upvote 0

NeoTechni

Well-Known Member
Licensed User
Longtime User
You'd think so, but he sent me a crash log showing a null pointer.
code module, it's what draws onto the canvas.
 
Upvote 0
Top