2 Little Things

Monkey Forums/Monkey Programming/2 Little Things

Duke87(Posted 2016) [#1]
Hey monks,

I'm coding my own little Font and it's nearly finished for little example purposes.
So Imdoing some stresstest at the moment, and i noticed 2 things, I can't explain.

first:
When i set the SetUpdateRate(600) my program runs about +/- 140 fps.
Same with 300 and so on.
But when i set it on 240, it increases my FPS to 240.
(No matter if release or debug mode)
Why ?

Using this simple FPS-Algo within OnUpdate()


Second:

When I run my program in DebugMode it's no problem to do thing like:
For Local i:Int = 0 To 300	
   mFont.drawAreaText("ABCDEFGHIJKLMNOPQRSTUVWXYZ",DW*0.2,DH*0.45,DW*0.6,DH*0.3,32,32)
Next 

But when i switch to release mode, I only can draw 2x the alphabet, when i draw it a third time (Monkey Runtime Error : Memory access violation).
Why ?
Could it be a GC thing?
At the moment, for testpurpose, my font-Algo is calculating & creating for each draw the whole Text character for character and then creates a new List storing their positions and stuff.



thank you.

Bye Duke


muddy_shoes(Posted 2016) [#2]
The "framerate" issue seems likely to be a side effect of how mojo deals with the update timing and tries to maintain some link with the actual rendered frames. I don't know what you mean by a program running at "+/- 140fps" though so it's hard to say.

Without a specific line reference it's difficult to address the memory access issue. You should post a working (as in compilable and runnable) example for the best chance of an answer.


Gerry Quinn(Posted 2016) [#3]
It's unlikely to be anything to do with GC, I think. Probably whatever is happening with updates and rendering, something is not getting initialised before it's used.


dawlane(Posted 2016) [#4]
I suspect that the irregular frame rates are more down to the fact that Duke87 is trying to do all his calculations and drawing in the OnRender method instead using the OnUpdate method to pre-calculate what's needed and then calling the draw method separately in the OnRender method.


dawlane(Posted 2016) [#5]
If you want to see a little example of parsing a string on the fly with coloured text. Then look at this (see my solution). You should also look at the link about strings.

Cut down on the use of New,lists and loops. They come at a price.
There is also a price to pay for using multiple images instead of using a texture/sprite atlas.


Gerry Quinn(Posted 2016) [#6]
Well, he is doing a stress test, so that usually involves a bit of looping...


dawlane(Posted 2016) [#7]
Well, he is doing a stress test, so that usually involves a bit of looping...

There's stress testing and then there is going loopy with stress while stress testing.

@Duke87: If I was you. I would reevaluate how you have parsed the string passed. Looping the whole string twice is wasted time. Keeping track of the current index and two points in most cases for searching should be a lot faster. Plus there should be no need to convert a string into an array of integers. Indexing a string would return the character code.