Text not printed properly in android version

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
mudmirror
Prole
Posts: 3
Joined: Tue Nov 10, 2020 8:26 pm

Text not printed properly in android version

Post by mudmirror »

I have problems rendering text when I port my game to android (doesn't matter if I use the zip method or run it directly as a lovegame folder). Only some of the characters are displayed. This happens in any app I make, not just this one!
For the record, my android version is 6.0.1 and löve is updated to the last version.

UPDATE: I found a workaround. Creating a Text object instead of printing the string directly. Still, I would like an explanation. Does anybody knows why this happen? Am I always supposed to use Text objects instead of strings in löve?
Nope, that doesn't work either. :death: :ultrashocked:

The guilty code looks like this:

Code: Select all

function love.draw()
  if text.show then
    lg.setColor(0,0,0.05,0.9)
    lg.rectangle("fill",text.x,text.y,text.w,text.h)
    lg.setColor(1,1,1,1)
    for i=1,#text.ls do
      lg.print(text.ls[i],text.x+5,text.y+5+text.rowsep*(i-1))
    end
  end
  
  if menu.show then
    for i=1,#menu.opt do
      lg.setColor(0,0,0.05,0.9)
      local y= menu.y+(menu.h+5)*(i-1)
      lg.rectangle("fill",menu.x,y,menu.w,menu.h)
      lg.setColor(1,1,1,1)
      lg.print(menu.opt[i],menu.tx,y+menu.ty)
    end
  end
end
This is how it is displayed in windows: :cool:
Good boy
Good boy
screenshot_Windows.png (269.35 KiB) Viewed 3812 times
And this one is android: :crazy:
Bad boy
Bad boy
screenshot_Android.png (597.42 KiB) Viewed 3812 times
What am I doing wrong?
Last edited by mudmirror on Mon Jul 05, 2021 4:07 pm, edited 3 times in total.
User avatar
GVovkiv
Party member
Posts: 192
Joined: Fri Jan 15, 2021 7:29 am
Contact:

Re: [SOLVED] Text not printed properly in android version

Post by GVovkiv »

maybe missing fonts?
are you tried to change fonts?
User avatar
Gunroar:Cannon()
Party member
Posts: 606
Joined: Thu Dec 10, 2020 1:57 am

Re: [SOLVED] Text not printed properly in android version

Post by Gunroar:Cannon() »

Do all the apps you make make use that text.ls thingy. I wish I could see more code related to the text causee now I'm curious too :brows:
-It might look like nonsense :roll: but there's so much proof.
-Some more if you pls... :? .
It has to be real then, all that talk about the end :shock: .
-How to be saved :huh:
User avatar
mudmirror
Prole
Posts: 3
Joined: Tue Nov 10, 2020 8:26 pm

Re: [SOLVED] Text not printed properly in android version

Post by mudmirror »

GVovkiv wrote: Sun Jul 04, 2021 8:28 pm maybe missing fonts?
are you tried to change fonts?
I tried using a custom font and the problem persists. Does it only happen to me? lmao
Gunroar:Cannon() wrote: Mon Jul 05, 2021 5:51 am Do all the apps you make make use that text.ls thingy. I wish I could see more code related to the text causee now I'm curious too :brows:
The "text" object is the message box where dialog is displayed. It looks like this:

Code: Select all

text= {
    ls={}, buffer={}, bufferi=1, show=true, wait=false,
    x=SCR_X+5, y=SCR_Y+SCR_H*0.6, w=SCR_W-10, h=SCR_H*0.4-10,
    rowsep=12
  }
New strings are added to text.buffer, and then added character by character into text.ls.
But I don't use this in all my games, only in those who has dialog boxes.

With "This happens in any app I make, not just this one!" I meant the love.graphics.print() bug.

--------------------------------------------------------------------
Hold up, I found how to replicate the bug.
Look at what happens if I try to print multiple strings in the same love.draw call.
CODE:

Code: Select all

lg= love.graphics

function love.load()
  font= lg.setNewFont("cour.ttf")
end

function love.draw()
  lg.print("Hello World! This is a test.",0,30+12*1)
  lg.print("abcdefghijklmnopqrstuvwxyz",0,30+12*2)
  lg.print("ABCDEFGHIJKLMNOPQRSTUVWXYZ",0,30+12*3)
  lg.print("1234567890.,:;-_+*=/|\\?!#",0,30+12*4)
end
OUTPUT:
out1.png
out1.png (6.46 KiB) Viewed 3747 times
It only prints the last character I requested: #. The exact same happens if I put all those strings in a table and iterate over them.

Code: Select all

function love.draw()
  for i=1,#toadd do
    lg.print(toadd[i],0,30+12*i)
  end
end
However, if I use this code to add a new line each time the user taps the screen:

Code: Select all

lg= love.graphics

function love.load()
  font= lg.setNewFont("cour.ttf")
  toadd= {
    "Hello World! This is a test.",
    "abcdefghijklmnopqrstuvwxyz",
    "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
    "1234567890.,:;-_+*=/|\\?!#"
  }
  str= {}
  toaddi= 0
  keydown= true
end

function love.update()
  if love.mouse.isDown(1) then keydown= true
  elseif keydown then
    keydown= false
    toaddi= toaddi+1
    table.insert(str,toadd[toaddi])
    if toaddi > 3 then toaddi= 0 end
  end
end

function love.draw()
  for i=1,#str do
    lg.print(str[i],0,30+12*i)
  end
end
It works just fine? OUTPUT:
out2.png
out2.png (23.27 KiB) Viewed 3747 times
Hell, it also works if I replace the empty table with the full one!

Code: Select all

function love.update()
  if love.mouse.isDown(1) then keydown= true
  elseif keydown then
    keydown= false
    str= toadd
  end
end
This is so weird. It's like strings that are "compiled" into the program are erased/corrupted, while those generated dynamically are displayed fine? But my app uses generated strings, so that's not it? I have no clue.
User avatar
GVovkiv
Party member
Posts: 192
Joined: Fri Jan 15, 2021 7:29 am
Contact:

Re: Text not printed properly in android version

Post by GVovkiv »

Can you provide full source code and your phone's characteristics?
User avatar
pgimeno
Party member
Posts: 2829
Joined: Sun Oct 18, 2015 2:58 pm

Re: Text not printed properly in android version

Post by pgimeno »

Full source was provided.

I wonder if this is yet another auto-batcher bug. Too bad it can't be disabled.
User avatar
slime
Solid Snayke
Posts: 2954
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Text not printed properly in android version

Post by slime »

pgimeno wrote: Mon Jul 05, 2021 7:44 pm I wonder if this is yet another auto-batcher bug. Too bad it can't be disabled.
It's much more likely to be a graphics driver bug than a problem in love's higher level batching code, given how platform- and device-specific it is. love started using more "modern" (8-12+ year old) OpenGL APIs at the same time as it introduced auto-batching, the majority of graphics issues in 11.x have been related to those APIs.

Details about the device you're testing on would be helpful. Also if you're testing on a simulator/emulator/android development environment on your PC instead of an actual phone that would be useful information too - emulators tend to have a lot more bugs in their OpenGL backend code than real phones do.

You could verify whether it 100% only happens with text or whether it happens with other types of batched draws too, by drawing the same image twice with no other code between the draws, with the second draw offset so you can see it.

Another possible thing that might help is using a love 11.4 prerelease build instead of 11.3 - it has a few workarounds for graphics driver bugs, although I don't remember any that had those exact symptoms. The love-android github page automatically makes builds - the latest available one is downloadable via the 'artifacts' button here: https://github.com/love2d/love-android/runs/2538144141
User avatar
mudmirror
Prole
Posts: 3
Joined: Tue Nov 10, 2020 8:26 pm

Re: Text not printed properly in android version

Post by mudmirror »

It's a shame that we work in different timezones, you guys reply when I'm not at my PC.

I'm taking screenshots from a physical phone: HTC Desire 820, Android 6.0.1.
There is another bug that I deemed unimportant but may give some clues: when an app is launched nothing shows on screen; I have to pause/drop it to the background then back up again for the graphics to start.

About drawing in batches, it works with images and polygons but interestingly enough not with imagefonts. In the image below you can see only the D (no pun intended) from the word WORLD.
Screenshot_20210706-170913.png
Screenshot_20210706-170913.png (30.85 KiB) Viewed 3677 times
And about the 11.4 release, I can't download it since it's just text not a link.

So neither love.graphics.print, nor using Text or Imagefont works.
If push comes to shove I can use a font image, split it into quads and use them as if they were sprites, but if you dudes want to know why is this happening, I'll gladly collaborate.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 18 guests