weird screen flicker

So - I don’t know if this is a bug in Codify or my code, but if it’s my code, I sure don’t see it - which may mean it’s obvious. :slight_smile:

Here’s the source:

This is a subset of my Hershey Font drawer, chopped down enough to show the bug without lots of extra.

In a nutshell, if you run this as it is, you get a “#” drawn on the screen (a bit offscreen), looks fine. If you comment that out and uncomment the “drawcharacter” subroutine call above, you get a horribly flickery screen. They both do, so far as I can tell, the exact same line draws - it’s just that one of them pulls the coordinates from a table, while the other is hardcoded. More importantly, perhaps, is that both set up and do their background and stroke stuff the same.

So - why is the “drawcharacter” version so flickery? Am I doing something lame, or am I just exposing something obscure?

PS. One other thing to mention in passing - when working with classes in separate tabs, it doesn’t always bring you to the error when you have one, so you end up having to search thru the tabs and source trying to find them. (And the font data is a couple hundred lines, so that becomes pretty slow…)

PPS. Things really dog down when you get close to 500 lines of code; almost unusable. I have an older ipad, maybe it’s just a memory issue. But - if you didn’t know, now you do.

Just loaded codify and I have been having a similar problem. I wrote simple program to draw an ellipse and it either doesn’t work, screen flickers showing the previous drawing, and sometimes I see weird background color effects. Same thing happens when I try drawing a rectangle.

Let me add that if I comment my program so that nothing should happen, I still see the drawing left over from the last time I ran the program.

Soggybag, you probably need a ‘background’ command near the start of your draw call.

Hmmm, imade a new project and test it and… I still see the flickering from last project!

As Dave said, add this line to the start of your draw function:


Let us know how that goes.

Bortels - yeah that error issue is annoying for me too. I plan to make it highlight tabs which contain errors. There is a bug which is clearing the errors at the moment when you change a tab.

Bortels - just tried your code and found your bug.

You are overwriting the draw() function in your drawchar() code. Lua is global by default, which is a little tricky to get used to. So in your drawchar() you have the line:

draw = 1

This overwrites the global draw function and sets it to 1. Which causes the screen to stop drawing since Codea now no longer can see the draw function.

You’ll want to change this line to:

local draw = 1

Which will declare it as a locally scoped variable. This fixes the issue.

Add a background() to setup() and the background flickers constantly?

This was the first thing I tried with my first program. The background flickered constantly I assumed I was doing something wrong. I assume this app works for some people.

Soggybag - not to setup(), add it to draw()

Codea is heavily inspired/influenced by Processing ( The Codea’s API and programming paradigm is very similar to Processing. Hence the setup(), draw(), and touched() special functions which are not common on other programming languages, even on other Lua IDEs/frameworks. For people who never heard/use Processing might have some problems in the beginning of using Codea. Unfortunately, there’s not enough explanation about this in Codea’s documentation. So, you need to learn it from Processing. Good luck! :slight_smile:

After some experimentation looks like the background needs to be redrawn each frame.

Though I wonder why the screen would flicker with one call to background in setup() ?

Bortels, nice work on the font code, I took the data you posted the other day and wrote a function to draw a whole string and it works a treat. Do you mind if I post it back up?

Also on the iPad 2 I notice a bit of slowdown on the file containing the font data but it doesn’t get unusable, strangely I have much bigger files that have no slowdown at all so I’m wandering if it’s something to do with parsing all the commas and braces…?


I suspect, if there’s a lot of numbers, then it’s the numbers. As each number gets its own draggable highlight view.

Could you add a macro type command to disable this for particular files?

e.g. add a comment at the top of the file like…


How about disabling syntax highlighting by touch-holding the tab and selecting disable/enable from the popup menu?

This setting would be saved in the project’s info.plist, meaning it would be shared with the project. Though not with the source code, hmm

Yep, that sounds better, although it might be nice sometimes to keep syntax highlighting and just disable the draggable parts (if possible)

I prefer to keep the syntax highlighting on and slider on/off options saved in project options.

Simeon - W00t! I love it when it’s my own bug - makes it easy to fix! Funny part is, the back of my mind has been saying “you really should go look at lua scope rules and make sure you have it right, instead of faking it”. I stared at that code for 2 full hours trying to spot that. Thanks!

vocieoftreason - go for it! I don’t put up anything on gist that I don’t hope and expect people to build on and hopefully re-share. I think Simeon is right about the “lot of numbers” theory - it’s a ton of numbers. I have been thinking of re-massaging the data to encode it as a packed string of characters, which will both make it much smaller, and should prevent the editor from wanting to do a dragable on each of them. But feel free to add and publish whatever you have; in the end, more code is good code, and we’ll be able to pick from the best bits. :slight_smile:

Bortels - new version here

How do you get github to do the syntax highlighting btw?