There’s a new D tutorial on the block. Announced a few days back, the Pragmatic D Tutorial…
…is aimed at people who can already program well in other
languages. This means nothing about loops or structs, because I expect most people to know this stuff. I do not consider D to be a language for beginners anyways.
Maintained by Andreas Zwinkau, the tutorial consists of several section covering a range of D features and usage. If you’re coming to D from C++, Java or elsewhere, the Pragmatic D Tutorial is one more resource to add to your bookmarks.
In my last post, I described an issue I was having with the DerelictSDL2 binding. The short version: SDL2 windows in programs created with the binding were getting resized to 160×24 when minimized and keeping that size when restored. According to the original report, this wasn’t happening with the same code in C++. I verified this with a C code base I work on from time to time.
My initial thought was it might have something to do with bad definitions in the binding. Experience has shown that this sort of thing can lead to weird behavior. But I dug around a bit a few days ago and couldn’t find anything that was off. I managed to pick some some new info about the problem, but that didn’t lead anywhere. Then I stepped away.
Today, I came back to it and learned something new. The problem didn’t occur when the SDL_WINDOW_RESIZABLE flag was passed to the SDL_CreateWindow function. Actually, a resize to 160×24 was still happening on minimize, but the original size was being reset when the window was restored. When I added the same flag in the C code base, nothing changed. But as I compiled and executed with and without the resizable flag in quick succession, I noticed a major difference. The window created in the C code had a border when the resizable flag wasn’t specified, while the window in the D code did not. This led to a wild goose chase, starting with a search for invalid window flag values in the D binding. Just as I was about to give up, I had a thought. Could it have something to do with executing as a console app? Then a light bulb went off.
My C code base uses premake4 for the build system. It suddenly dawned on me that when you specify a Windowed app in the premake config, then premake automatically compiles your app as a windows subsystem app. This allows you to forego WinMain and use a main function instead, but without a console window popping up when your app executes. I’m using dub for my D code base. It doesn’t use the windows subsystem configuration automatically and I wasn’t specifying it. I wasn’t 100% sure this was the actual problem, but it seemed like a safe bet. So I added a line to my dub config file to make the linker link a windows subsystem executable (“lflags”: ["/SUBSYSTEM:WINDOWS:5.01"]). The problem went away.
I’m relieved on two fronts. First, that the issue is solved and I don’t have to bang my head on the desk about it anymore. Second, that once more a fundamental flaw in binding D with C libraries did not actually manifest, something I’ve been worried about now and again when these unusual issues crop up with Derelict.
I hope someone out there finds this info helpful!
An interesting, but frustrating, issue with the DerelictSDL2 binding was recently brought to my attention. You can read the issue thread over at github, but I’ll summarize it here.
When using SDL2 with Derelict on Windows, minimizing a window causes its size to be changed. For me, the new size is consistently 160×24, no matter the original size of the window. This does not happen when similar code is compiled and executed in C or C++ nor does it happen on Linux.
In C, SDL sends the events SDL_WINDOWEVENT_MINIMIZED when the window is minimized and SDL_WINDOWEVENT_RESTORED when it’s restored. The size never changes. With Derelict, it sends the following sequence: SDL_WINDOWEVENT_SIZE_CHANGED, SDL_WINDOWEVENT_RESIZED, SDL_WINDOWEVENT_MINIMIZED, SDL_WINDOWEVENT_RESTORED. If I manually change the size via SDL_SetWindowSize when handling the minimize event, it gets changed back to 160×24 and the size_changed and resized events are again sent just before the restored event.
This one has me good and well stumped at the moment, so I’m coming here to ask anyone using SDL2 with Derelict, or anyone who’s interested in a debugging challenge, and who can reproduce the problem, to lend a hand in finding the culprit. My first guess was that something was off with an event ID or event structure size on the Derelict side, but that didn’t pan out. Of course, it could be something not related to the event system. But I just don’t know where to look.
I appreciate any help anyone can give on this.
John Colvin has started a new blog on D. His intent is to show off the language through the construction of simple programs, specifically Unix utilities. His first post demonstrates using two different paradigms in D, a couple of language features and a little bit of Phobos.
Ali Çehreli has announced that more chapters of his book Programming in D have been translated from the original Turkish into English. He says that the book is not 88% translated. See the announcement for the details.
If you are looking to learn D, I don’t know of a better free resource. It’s an excellent piece of work and you can’t go wrong by starting your D journey there.