Browsed by
Category: Programming

C# App hangs when BitmapDecoder.CreateAsync is called

C# App hangs when BitmapDecoder.CreateAsync is called

Calling ASync functions from UI event handling routines/the main UI thread in C# turns out to require some basic knowledge to avoid getting into deadlocks. I sort of jumped in without doing much learning, so here were some of my learning resources as I made the inevitable mistakes:

https://stackoverflow.com/questions/12507749/winrt-app-hangs-when-bitmapdecoder-createasyncstream-is-called

https://social.msdn.microsoft.com/Forums/en-US/8bed034e-a8f6-4322-a801-79f014815dd9/bitmapencodercreateasync-never-returns?forum=winappswithcsharp

https://stackoverflow.com/questions/12235085/winrt-loading-static-data-with-getfilefromapplicationuriasync

Debugging tips:

https://medium.com/bynder-tech/c-why-you-should-use-configureawait-false-in-your-library-code-d7837dce3d7f

https://docs.microsoft.com/en-us/dotnet/api/system.threading.tasks.task-1.result?view=netframework-4.8

C# and Universal Windows App file handling:

https://docs.microsoft.com/en-us/windows/uwp/get-started/fileio-learning-track

https://docs.microsoft.com/en-us/windows/uwp/files/file-access-permissions

The details of fighting game logic

The details of fighting game logic

Making a button-mashing fighting game like Street Fighter has some surprisingly sophisticated logic when it comes to frame-perfect animation hits and combos. Strange Wire does an awesome job describing the difficulties and some ways to solve them.

What are those difficulties? Problems like checking hit and hurt boxes at the right parts of animation frames. Attaching events at the right parts of the animations can be tricky – especially if animators are still tweaking them. And the ever-present issue of keep the code clean.

Definitely worth a read whether you’re doing 2D to 3D fighters.

https://strangewire.blogspot.com/2019/09/frame-specific-attacks-in-unity.html

This is how graphics used to be done kids

This is how graphics used to be done kids

Back in the day when I was learning, there wasn’t much (or any) hardware acceleration for graphics. Programming graphics back then, on 8088/286/386 processors was much like this. Bisqwit gives it a shot.

In this tool-assisted education video I create a simple FPS style walking and jumping scene for OpenGL, with DJGPP, in DOS. In a 256 colors 320×200 VGA mode. This is my first OpenGL exercise. Apologies about some little mistakes in the program (such as reloading the textures on every frame). I noticed them when this video was already late in production, and it would take several days before the new version would be available if I were to fix them, and I’m itching to get this video out and into making the next video already, and none of the mistakes actually prevent the content being understood, so I’ll leave them be. Most people don’t even notice. Twitter: https://twitter.com/RealBisqwit Patreon: https://patreon.com/Bisqwit (alternatives at https://iki.fi/bisqwit/donate.html) Twitch: https://twitch.tv/RealBisqwit Homepage: https://iki.fi/bisqwit/ I wrote a FAQ after this video was picked up on Reddit the first time in 2012. Here it is: https://bisqwit.iki.fi/jutut/kuvat/pr… Source code and prebuilt lightmaps: (Compiles and runs on Linux): https://bisqwit.iki.fi/jutut/kuvat/pr… (includes also a superior ellipsoid-based collision testing, and a buggy WIP for portal rendering: I’m not good with the math.)

Google hand tracking now open source

Google hand tracking now open source

Google has made its hand detection and tracking tech open-source, giving developers the opportunity to poke around in the tech’s code and see what makes it tick.

“We hope that providing this hand perception functionality to the wider research and development community will result in an emergence of creative use cases, stimulating new applications and new research avenues,” reads a blog post from the team.

That post over on the Google AI Blog dives into exactly how the tech works, and devs interested in getting a closer look at it can find the project over on Google’s Github repository.

MacOS 10.14 Mojave in VMWare

MacOS 10.14 Mojave in VMWare

Developing a iOS app used to require buying a Macbook or Mac mini. With VMWare, it is no longer necessary. I used VMWare Workstation 15.0 Pro and was able to develop an app and debug it on real iPad/iPhone hardware. Setup instructions are here:
https://techsviewer.com/install-macos-mojave-vmware-windows/

Here’s the latest VMWare Mojave 10.14.4, 18E226 (March 25, 2019) image:

Further tips after the above setup

Eulerian Video Magnification

Eulerian Video Magnification

Back in the ‘early’ days (2012) of video processing, before we had AI algorithms, we often just pursued straight video processing techniques to tease out interesting information.

Enter MIT’s work on Eulerian Video Magnification. The underlying concept is to take small per-pixel differences from frame to frame, then magnify the changes, to detect things not ordinarily visible to the human eye.

One of the most powerful effects is the ability to accurately detect the pulse of someone, or the vibration of objects by sound – with just normal video footage. Check it out in their original demonstration video below:

In 2014 they did a Ted talk that shows some further interesting applications – including re-generating the sound going on in a room from the vibrations of the objects in it.

So, since 2014, you can even recover sound from a discarded bag of chips behind soundproof glass.

Program old standup arcade systems from your browser!

Program old standup arcade systems from your browser!

The folks over at 8-bit workshop have some neat resources. Learn to write 8-bit code for a ton of old standup arcades and tv console systems – right from your browser.

I’m personally a big fan of the 6502 Vector systems, but these are available for you to try out

  • Atari 2600 (6502)
  • VIC Dual (Z80)
  • Midway 8080 (Z80)
  • Galaxian/Scramble (Z80)
  • Atari arcade vector system – (6502)
  • Williams (Motorola 6809)
  • Apple II+

https://8bitworkshop.com/

Your first game

Your first game

Time for me to shake my fist and tell you darn kids to get off my lawn. Lets set the wayback machine to the 1980’s…

Ralph Koster shares the first video game he ever wrote as well as a great flashback to what almost everyone that wanted to learn to program did back in the 80’s and 90’s. We typed in long programs by hand from books we got at the library and computer magazines. We taught ourselves BASIC and smatterings of assembly. If you were really cool, you even tried to sell your games: which was done by copying them to a floppy, printing a dot-matrix label for it, and trying to sell it in a ziplock baggie.

I started by fiddling around with the programs I typed in to see if I could change them or make them do different things.

My very first video ‘game’ on my TSR-80 consisted of a bunch of black and white dots that would fall down from the top of the screen, and you moved your dot ‘ship’ back and forth to avoid them as the enemies rained down. They came down one at a time. Ridiculously slowly. But it was probably my very first ‘game’.

My second, more ‘real’ game was a castle adventure game. You were the sole heir of a long-lost uncle and had to search his castle to find the deed within 24 hours. It was a text adventure at its heart, but there was opening graphics. I even wrote my own graphics editor with which I drew those opening screens. I believe I still have the graph paper I used.

Anyway, for anyone who learned to program in the 80’s, Koster’s video will tug some familiar heartstrings. For you younger kids, this is how it was done back in the day…

LD_PRELOAD and stealing function calls

LD_PRELOAD and stealing function calls

There is a clever little trick that one can use for a variety of purposes on Linux. It involves overriding or hijacking function calls. It’s called LD_PRELOAD.

Lets say you create a file called unrandom.c that includes an implementation of the rand() function. It matches the function rand() in standard C.

unrandom.c:
1
2
3
int rand(){
    return 42; //the most random number in the universe
}

We’ll compile it into a shared library.

gcc -shared -fPIC unrandom.c -o unrandom.so

Now… just run a program (my_program) that uses random numbers like this, and you’ll find that the rand function only generates 42.

LD_PRELOAD=$PWD/unrandom.so ./my_program

This trick can be used in a variety of ways. A good write-up can be found here, and is worth a read:

Dynamic linker tricks: Using LD_PRELOAD to cheat, inject features and investigate programs