Free hardware cursor plugin for windows

Every good game engine supporting desktop systems should have a mechanism for easily setting custom cursors. This functionality is not freely available in solar2D so I made a plugin to enable it.

I do not own a mac or have any knowledge of apple development so I could only target windows.

Unfortunately there is a bug where the game crashes on exit if the plugin is not “freed” a few moments before exiting.
I do not know how to fix this problem and hope one of the forum members here has an idea what might be causing this and how it can be fixed. @vlads perhaps?

I suspect it has something to do with how the engine frees up memory when exiting.

The plugin is open source (but very bare bones as of now) if anyone would like to take a look.
https://github.com/ANSH3LL/plugin_hwcursor

2 Likes

Updated the github page. Also the plugin is now usable.

Hi.

On the shutdown side of things, you might have some luck making a userdata (possibly just a singleton) and registering the appropriate cleanup behavior as its __gc metamethod.

There are also separate issues as far as hardening against the simulator itself crashing, since some cursor calls operate at more of an OS granularity. I don’t know what the proper procedure is there.

Also, there were a couple of guys playing with this sort of thing a while back. Maybe I can dig up some links later. That said, there is also something of a cursor wishlist on desktop platforms. :slight_smile:

1 Like

Thank you for the suggestion. It seems like it might help even though I don’t really know how to implement it as I have little knowledge of the lua C API. I will look into it though.

The crashing only occurs if the window subclass procedure is not yet removed when the engine is shutting down. Oddly, even attempting to remove the subclassing at the WM_CLOSE and WM_DESTROY window messages does not help. Maybe it’s too late by then and the engine crashes with an access violation error.

Integrating this functionality directly into the engine would be a good idea… Anyone is free to use my code as a springboard should they decide to do this.

Update: the __gc metamethod did not stop the crashing, but I’ve found a workaround with only a minor inconvenience. The user will have to click the close button twice instead of just once, but there will be no more crashes whatsoever. The programmatic way is still available and preferred, but no longer necessary.

I’ve updated the plugin to v0.2 as well, so if anyone was already using it, please update the URL in your build.settings.

1 Like

I’ve updated the plugin to v0.3, with support for windows-provided cursors such as the pointing hand cursor and more. Check out the README on github as well as the example project to find out how to make use of this feature.

Don’t forget to also update the URL in your build.settings to https://github.com/ANSH3LL/plugin_hwcursor/releases/download/v0.3/win32-sim.tgz

1 Like

I’ve updated the plugin to v0.4, the error where the application would crash on exit as well as the inconvenient workaround have both been fixed.

Everything should now be working perfectly smoothly and the end user should experience no inconveniences whatsoever. Clicking the close button once should now close the application as expected.

Should there be any issues, feel free to open an issue on github or reply to this thread.

Don’t forget to update the URL in your build.settings to https://github.com/ANSH3LL/plugin_hwcursor/releases/download/v0.4/win32-sim.tgz

3 Likes

I’ve updated the plugin to v0.5.
Changelog

  • Cursors must now be preloaded before use. An example of how to do this is available at https://github.com/ANSH3LL/plugin_hwcursor/blob/main/Corona/main.lua

  • Cursor handles can be destroyed at will using the plugin.destroyCursor(cursor) method

  • Load a cursor of any size without downscaling, i.e: 256x256 size cursor will load at this size and be very big as you’d expect

Should there be any issues, feel free to open an issue on github or reply to this thread.

Don’t forget to update the URL in your build.settings to https://github.com/ANSH3LL/plugin_hwcursor/releases/download/v0.5/win32-sim.tgz if you’d wish to make use of the new features.

Plugin updated to v0.6
Various things have changed since v0.5. The full list is available here: https://github.com/ANSH3LL/plugin_hwcursor/blob/main/README.md

As usual, don’t forget to update the URL in your build.settings to https://github.com/ANSH3LL/plugin_hwcursor/releases/download/v0.6/win32-sim.tgz if you’d wish to make use of the v0.6 update.

1 Like

Hi,
I’m using v0.6 but am still getting crashes on exit unless I free the plugin first.
What tends to happen is that I’m working on my app happily using your plugin and then I’ll make a change to my code and save. And since I have simulator set to automatically relaunch on save, the app crashes (after a pause, the simulator closes) since your plugin has not been freed. I could of course have a temp button on my ui that I have to press that frees the plugin before I make any changes but this is quite disruptive to work flow. In an earlier post you said you had fixed ther crash problem in v.04 (which I have also tried – still crashes), so perhaps my crash is something different?

Note added later: as a work-around, I am using the system event listener to check for event type applicationExit and then freeing the plugin, but would be good to know why these crashes are still happening.

I’m sorry to hear the crashes are still occurring. The last time I tested the plugin on the simulator was a long while ago and it worked fine, so something might have changed. I honestly don’t know.

Anyway, I’m glad you found a work-around. In the usage example, you’ll find I had implemented something similar, although it was just for freeing cursors rather than the entire plugin. You might want to take a look in case it provides value.