[SOLVED] UTF-8 Troubles

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
junkghost
Prole
Posts: 3
Joined: Mon Jul 22, 2013 11:24 pm

[SOLVED] UTF-8 Troubles

Post by junkghost »

I've hit a snag making my first game, a tiled roguelike. I started out coding in SublimeText2 and have since switched to TextWrangler - unfortunately I don't have access to Notepad++ because I'm usually coding on my Macbook. When I try to run my game, this is the error I get:

Code: Select all

Error
graphics.lua.1273: Decoding error: Invalid UTF-8 

Traceback
[C]: in function 'printf1'
graphics.lua.1273: in function 'printf'
[C]: ?
[C]:in function 'require'
[C]: in function 'xpcall'
I've already tried the fix that involves saving the code in UTF-8 w/o BOM - that should be the state the attached code is in. This is pretty strange to me because I had my game running for a long time before something switched on me and caused this to start happening. Another fix I saw involved taking out invalid characters from the path, but that doesn't seem to apply to my situation either since my game is stored in OSX_user_root_folder/game. Any suggestions are greatly appreciated!
Attachments
ghostworld.love
(10.97 KiB) Downloaded 183 times
Last edited by junkghost on Tue Jul 23, 2013 4:43 pm, edited 1 time in total.
:3
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: UTF-8 Troubles

Post by Robin »

If I run it in the terminal, I get:

Code: Select all

Error: Syntax error: main.lua:211: unexpected symbol near '�'

stack traceback:
	[C]: ?
	[C]: in function 'require'
	[string "boot.lua"]:331: in function <[string "boot.lua"]:227>
	[C]: in function 'xpcall'
Error: [string "graphics.lua"]:1273: Decoding error: Invalid UTF-8
stack traceback:
	[C]: in function 'printf1'
	[string "graphics.lua"]:1273: in function 'printf'
	[string "boot.lua"]:723: in function 'draw'
	[string "boot.lua"]:727: in function <[string "boot.lua"]:682>
	[C]: ?
	[C]: in function 'require'
	[string "boot.lua"]:331: in function <[string "boot.lua"]:227>
	[C]: in function 'xpcall'
That suggests you have a weird character in main.lua near line 211.
Help us help you: attach a .love.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: UTF-8 Troubles

Post by bartbes »

Oh yes, that is kind of awkward, the error handler is trying to display your error, but that isn't valid utf-8, probably because the character parsing fails on isn't.
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: UTF-8 Troubles

Post by Boolsheet »

In main.lua on line 211 you have 2 no-break spaces that, in UTF-8, are encoded with two bytes (file offset 5596: 0xC2 0xA0). Lua doesn't understand that and errors with the unexpected byte in the message. The LÖVE error handler doesn't like the byte above 127 and explodes.

A few other things.

Don't call love.graphics.newFont every frame. This creates a lot of font objects that will take up a lot of memory and you only need one. Load them in love.load or once when the game state changes.

Try not to use a variable called 'string'. The global variable 'string' points to the Lua string library and you may want still be able to access it in a comfortable way. ;)

The function require has a specific syntax for module names. Instead of slashes, use periods to separate directories.

Code: Select all

require("structures.entlist")
Shallow indentations.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: UTF-8 Troubles

Post by Robin »

Boolsheet wrote:In main.lua on line 211 you have 2 no-break spaces that, in UTF-8, are encoded with two bytes (file offset 5596: 0xC2 0xA0). Lua doesn't understand that and errors with the unexpected byte in the message. The LÖVE error handler doesn't like the byte above 127 and explodes.
That raises the question: why the hell does the error message for invalid UTF-8 include the invalid byte sequence, unescaped and everything? Who thought that was a good idea?
Help us help you: attach a .love.
User avatar
junkghost
Prole
Posts: 3
Joined: Mon Jul 22, 2013 11:24 pm

Re: UTF-8 Troubles

Post by junkghost »

Thank you all for the help! I've eliminated the offending characters, I'm not even sure how they got in there.
Boolsheet wrote: Don't call love.graphics.newFont every frame. This creates a lot of font objects that will take up a lot of memory and you only need one. Load them in love.load or once when the game state changes.

Try not to use a variable called 'string'. The global variable 'string' points to the Lua string library and you may want still be able to access it in a comfortable way. ;)

The function require has a specific syntax for module names. Instead of slashes, use periods to separate directories.

Code: Select all

require("structures.entlist")
I'll keep those suggestions in mind. I didn't notice that I left newFont inside draw(), I learned my lesson about not leaving incrementing calls in draw() the hard way after I had an infinitely-looping info dialog giving me grief. Thanks again!
:3
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: UTF-8 Troubles

Post by bartbes »

Robin wrote: That raises the question: why the hell does the error message for invalid UTF-8 include the invalid byte sequence, unescaped and everything? Who thought that was a good idea?
Because that's how lua generates it?
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot], Semrush [Bot] and 7 guests