Animation no go in 64 bit compile

  1. ‹ Older
  2. 2 weeks ago

    Dave S

    Oct 11 San Diego, California USA

    @Tim P Wait, so somehow you magically got animation without controlling the redraw rate? You should at least be controlling it with a timer of some sort that tells the canvas to display Z frame Y time after displaying X frame.

    it looks like it animates a sort process... so the swapping of the values is what controls the "animation"
    so it could be

    • its now "too fast" (doubtful)
    • a bug in refreshrect (possible)
    • or 64bit graphics is totally "frelled"

    question I have.... is do you end up seeing the "starting" frame? or the "ending" frame?

  3. Tim P

    Oct 11 Pre-Release Testers, Xojo Pro ⭐️

    I don't see anything that determines frame display time, and there's no mention of anything to that measure in the description of how this functions. The frames need to sit on screen long enough to be seen to become an animation. If it's just a loops with no time delay it's just drawing the frames as quick as it can. This method and RefreshRect might just be working too fast for the computer to display.

  4. Gavin S

    Oct 11 Pre-Release Testers UK

    Have you tried stepping through it in the debugger?

  5. Sam R

    Oct 11 Pre-Release Testers, Xojo Pro Hengchun, Pingtung, Taiwan
    Edited 2 weeks ago by Sam R

    RefreshRect used to force a screen update instantly, which is how it has worked in the past. "Invalidate" would mark an area of a view as 'dirty' and then when the current method completes, the window server would ask the 'dirty' views to redraw.

    I wouldn't be surprised if refreshRect either no longer works like it used to, or perhaps it never worked this way in 64-Bit. Either way I would suggest considering an alternative animation solution.

    An oversimplified version is to use a timer. When you want to animate, you store the object, start value, end value, startTime and duration for the animation. You set the timer's period based upon 1000 / framesPerSecond ( 30 fps is 33 ).

    In the action event you calculate how far into the animation the current time is, then use that to calculate the correct values for the object, update the object (and canvas, use invalidate( left, top, width, height)).

    Once your currentTime exceeds startTime + duration, your animation is over and you can stop the timer.

    Edit: Just want to add that a lot of functions in the recent macOS versions has to be 'scheduled' nowadays, I believe this is because of triple buffering.

  6. Beatrix W

    Oct 11 Pre-Release Testers Europe (Germany)

    Can you post an example project so that we can try this?

  7. Harrie W

    Oct 12 Crossville, Tennessee, USA

    Dave
    In the very beginning I see the randomly sized bars. Once the animate button is clicked the next thing that I see is the finished product. The app allows from 1 to 12 of the sort algorithms to be selected. If I choose more than one I should, as under 32 bit, see the animation of the first algorithm along with the name of the algorithm such as shell. When it finishes I should see the bars set back to there original positions in preparation for the next sort algorithm and then see the animation process for this next sort. This should repeat for each of the selected sort algorithms. Under 64 bit I see the very beginning and at the end of the first sort I see the sorted bars and then no change until however many sorts selected have finished processing.

    It is like it is never allowing the refreshes to be executed like it does in 32 bit mode.

    Seeing this I decided to change over to the non-animated version of the program. This program has the same 12 sort algorithms and again you can choose from 1 to 12 of them to run when the start button is clicked. In this program as each sort completes the information for that algorithm is written in to a line of a list box, showing compares made, swaps made, and time elapsed. But HERE AGAIN IN 64 BIT MODE NON OF THE STATS APPEAR UNTIL ALL OF THE SORTS ARE COMPLETED. In 33 bit mode the lines fill, one by one as each sort completes. This is not a speed thing as the program allows the selection of different array sizes from 1000 elements to 1,000,000 elements.

    I am about to add programming to my retirement as this is ridiculous.

    It just seems that 64 bits is not allowing the refreshes to take their turn in either the program doing the animation or the program simply showing the stats for a given sort in a listbox.

  8. Michael D

    Oct 12 Pre-Release Testers, Xojo Pro

    @Harrie W This all works great when compiled for 32 bit.

    You never specified: is the 32 bit app Carbon or Cocoa?

  9. Harrie W

    Oct 12 Crossville, Tennessee, USA

    Michael, the 32 bit version Cocoa as it is compiled with the latest version of Xojo and was modified not too long ago to do its work with a picture object with the graphic object on the window painting the picture when it's Paint event is invoked. The animation is moving the bars on the picture object that represent the array elements. Choose to compile in 32 bit and it runs beautifully. Choose to compile in 64 bit and no animation occurs.

  10. Norman P

    Oct 12 Xojo Inc

    A loop like this doesn't yield time to the main event loop so that the redraws CAN take place
    And drawing happens on the main event loop

    Try UpdateNow
    http://docs.xojo.com/index.php/Window.UpdateNow

  11. Sam R

    Oct 12 Pre-Release Testers, Xojo Pro Hengchun, Pingtung, Taiwan

    @Harrie W ,
    Don't get discouraged. Take a break and then spend some time trying to understand how to implement time based animation. It's not that difficult, just requires retraining your mind a little bit.

    If you and others are interested, I'll write a tutorial for the xDev magazine.

  12. last week

    Harrie W

    Oct 14 Crossville, Tennessee, USA
    Edited last week by Harrie W

    Not being a professional Xojo programmer and not having a web site where I can post a small sample of this project for others to look at I posted it to Feedback and included a small sample project that only does a comb sort, a good fast sort. To me this problem seems to be that Xojo is not yielding any time for background processes at loop boundaries in 64 bitlike it does in 32 bit. If that is true than hopefully the Xojo folks can remedy my problem. If I am wrong in that assumption hopefully one of you good folks can come up with a remedy. I tried Norman's suggestion of using the Window.UpdateNow method and it changed nothing; however, that may totally be my not setting everything correctly. I turned on implicit instance for the window as the UpdateNow mentions.

    The feedback number is 49889 and is titled: animation that works in 32bit MacOS does not work in 64 bit MacOA

    Yes, I failed to catch the mistype of MacOS at the end of the title. Me bad

  13. Beatrix W

    Oct 14 Pre-Release Testers Europe (Germany)

    I don't see any animation with 32bit on Xojo 2017r1/High Sierra.

  14. Norman P

    Oct 14 Xojo Inc

    I've looked at the sample
    As I suspected the loop to run the sort completely blocks the main event loop of the app
    And ALL UI drawing goes through the main event loop

    It really needs to be split out into a timer that draws one frame at a time or a thread that redraws one frame at a time via a timer
    Or some other way that yields time back to the main thread so each frame of the animation can be drawn

    I've added such a sample to the case for you to peruse
    It basically lifts the "for loop" out and uses a repeatedly firing timer to run the for loop that did the sort

  15. Norman P

    Oct 14 Xojo Inc

    FWIW this has nothing to do with being a professional or not

    It has everything to do with how the OS'es expect applications to work - and this IS very different than it used to be under classic MacOS, Carbon, older versions of Windows and even Linux
    All the OS UI frameworks basically expect to get back to the main even loop of the app and most redraw from that main event loop

    So, when a action (like the code that does the sort) runs for some time & doesn't have a mechanism to yield time back to the main event loop then drawing suffers
    And this is exactly the symptom you see going on

    It definitely requires thinking about how to do things like animations differently than you used to

  16. Jeff T

    Oct 14 Midlands of England, Europe

    Thing is, this kind of app has long been a stable of development language examples.
    Ive seen the same thing rolled out in VB and Delphi in the past
    It shows two things:
    The comparative speed of the sorts, and then the speed of the compiler.

    I saw someone's example a few months back documented as 'of course, it runs too fast today to see the animation'
    But back in the day it was expected that the graphs would trickle away as the sorts were running.
    Dont remember the VB code being peppered with DoEvents, but I wouldnt be surprised.

  17. Harrie W

    Oct 14 Crossville, Tennessee, USA

    Thanks Norman. I will take a look at your example. Still seems, in my mind at least, keeping in mind the my career was all with IBM mainframe programming with PL/I, that it is idiotic that you cannot draw a bar and then issue some command that tells the OS to update it. I find it hard for anyone to think that that would not be an easier approach; but; as I stated earlier, I am an old dude with far less patience than what I had at the age of 21 when I started my programming career. ;-)

  18. Norman P

    Oct 14 Xojo Inc

    Never said that wasnt easier to deal with
    Its just not how things work in modern OSes

    UI updates happen on the main thread and this bit ocf code basically doesn't let the main thread do anything until its done
    So you only see that last thing drawn

  19. Thomas R

    Oct 14 Europe, France, Besancon

    Like Harrie, I'm not professional, I develop in my spare time. As I lost my job, then I decided to take a look in my 11 applications and remove all the DoEvents. I did 9 of them, 2 left (1 simple and the biggest one which I'm afraid to do).
    3 of those applications are game. In the past, I did :

    • Calculate animation
    • MyCanvas.Refresh
    • DoEvents (because if not the Canvas doesn't refresh)
    • Calculate next animation
    • MyCanvas.Refresh
    • DoEvents

    and so on.

    Now, I still don't calculate the time of the animation, it goes as fast as it can, but if I have 10 animation, I do the 10 animations !
    I have a thread.

    • Thread calculate animation.
    • Thread launch a Timer and go to sleep.
    • Timer do MyCanvas.Refresh and Resume the Thread
    • Thread calculate next animation.
    • and so on

    On Windows, it was very very slow (previous it was fastest than on Mac). Then I replaced MyCanvas.Refresh by MyCanvas.Invalidate .
    But if the Thread has a priority higher than 5 (the main Thread), then the Canvas was not completely refresh (only 30%). Then I put my Thread to priority 3 (less than Main Thread which refresh the Canvas), and it works as I want.

    In the Xojo Doc they say it's better to use Invalidate than Refresh because Refresh call to often may cause application to slow down. But when we use Invalidate we don't know if the Refresh has been done or not. If I had an event "My Canvas has been refreshed" then I would resume my Thread in that event. I could do it in the Paint event, but this event fire and redraw only 30% of my Canvas, then it doesn't help me, I need to know "my canvas has been redraw 100%".

    Harrie, yes it's boring, yes I wanted to trash my application and stop to develop. But I reached to make it work and I'm happy. You will do it too.
    And in very old version of Xojo (RealStudio), I'm not sure but I think that MyCanvas.Refresh or a Self?UpdateNow does refresh it even without a DoEvents after it.

  20. Harrie W

    Oct 14 Crossville, Tennessee, USA

    Norman,
    Thanks for the example. Looks like I need to create 12 timers, one for each sort algorithm and do a lot of moving of code in to those timer action events. I am sure that there will be the issuance of some wirty dords during the testing as a means of easing the frustration.

    I still am a little lost here though. You state that this is how modern OSes operate and you are much much more informed here than me. The problem I am having regardless of which compiler option I am setting, 32 or 64 bit. The code is running in the same OS so that tells me that if it works in 32 bit and not in 64 bit the difference is that the 64 bit compiler is written to conform to these new standards and the 32 bit option wasn't.

    I have to admit, it was nice to see it run in 64 bit. Looks like I have to do somewhat the same thing for the non-animated version of the program because when I run it the results written in to the listbox showing number of compares, number of swaps and time to run do not get updated until the last of the chosen sorts completes. Looks like I will simply move the sorting code in to the action event of a timer and that way the respective line in the listbox will fill in when that each sort completes

    I think I just may be seeing a very faint light way down there at the end of the tunnel now. Next big fight will be getting the UTI to work for my budget app; but, seeing as I am the only user of that app I just may have it directly open the file without an open dialog as a work around until the UTI thingy gets figured out. Have tons of dialog concerning that problem stored in the projects folder to help me out. Thanks again, and thanks to all that have tried to help this old guy.

  21. Norman P

    Oct 14 Xojo Inc

    @Harrie W Norman,
    Thanks for the example. Looks like I need to create 12 timers, one for each sort algorithm and do a lot of moving of code in to those timer action events. I am sure that there will be the issuance of some wirty dords during the testing as a means of easing the frustration.

    Not sure that this requires that many timers
    I literally just hacked the example project and reworked it to use a timer instead of a loop
    I'm sure that each of the sort algorithms could be abstracted in a way that they each have a means of performing one "step" of the sort that can then be redrawn

    @Harrie W I still am a little lost here though. You state that this is how modern OSes operate and you are much much more informed here than me. The problem I am having regardless of which compiler option I am setting, 32 or 64 bit. The code is running in the same OS so that tells me that if it works in 32 bit and not in 64 bit the difference is that the 64 bit compiler is written to conform to these new standards and the 32 bit option wasn't.

    Apple doesn't have the exact same code paths in the OS for 32 and 64 bit code
    That much I'm quite sure of
    Others, like Sam Rowlands, have reported other differences in Apple implementations between 32 and 64 bit

    @Harrie W I have to admit, it was nice to see it run in 64 bit. Looks like I have to do somewhat the same thing for the non-animated version of the program because when I run it the results written in to the listbox showing number of compares, number of swaps and time to run do not get updated until the last of the chosen sorts completes. Looks like I will simply move the sorting code in to the action event of a timer and that way the respective line in the listbox will fill in when that each sort completes

    That would be a similar problem
    The UI doesn't update while running - only when it gets to the end of the code that is stopping the main UI from updating

    @Harrie W I think I just may be seeing a very faint light way down there at the end of the tunnel now. Next big fight will be getting the UTI to work for my budget app; but, seeing as I am the only user of that app I just may have it directly open the file without an open dialog as a work around until the UTI thingy gets figured out. Have tons of dialog concerning that problem stored in the projects folder to help me out. Thanks again, and thanks to all that have tried to help this old guy.

    I'm not exactly a "spring chicken" any more myself
    I've started getting seniors discounts without even asking for them at some places :P

or Sign Up to reply!