Monthly Archives: September 2016

Thread is waiting for init_thread_header and init_thread_wait

The other day I ran into an issue where a thread got stuck on accessing a singleton. It was quite curious because there was no locking with mutexes or critical sections going on, yet the thread stalled. The callstack showed init_thread_header and init_thread_wait as the top most functions of the callstack, so the thread was definitely waiting for something... As it turns out, the constructor of the singleton class was calling some functions, which in turn would try to access the singleton again, this would of course result in an endless loop, depending on which implementation of singletons you use.
If you would instantiate the singleton with new, there would be an endless loop, and the stack would overflow. But if you used a static instance, the thread would simply stall at completion of the first loop, and Visual Studio would not complain, warn, or break.

Here is a simple example of how you can recreate this issue.

class MySingleton
{
public:
	static MySingleton& GetInstance()
	{
		static MySingleton instance;
		return instance;
	}

	MySingleton()
	{
		MySingleton::GetInstance(); // This is obviously bad
	}

	~MySingleton()
	{
	}
};

int main(void)
{
	MySingleton::GetInstance();
}

Of course the code I was working with was not so straightforward. So you would definitely have to look at the entire callstack to find the source of the problem.

Interesting issue, something to look out of in case your code stalls while accessing a singleton. But then again, we probably shouldn't be calling any functions in constructors anyway... 🙂

Unity blurry or fuzzy icons

Lately I have been using Unity and today when I ran the editor on my laptop I noticed that most of the icons were very fuzzy or blurry.

Example of blurry or fuzzy Unity editor icons

Example of blurry or fuzzy Unity editor icons

I tried to mess around with the quality settings in the Unity Editor itself, but that didn't to fix the problem, so I looked around on the internet and several people reported the same issue, only after updating their graphics drivers. I'm using a quite old laptop with two video cards in it (NVIDIA GT555M and Intel HD Graphics 3000), unfortunately the NVIDIA card died a while back so I can only use the slower Intel card. Because it's such a slow graphics chip I used to set all graphics settings to prefer performance over quality. So I checked to see if that may have caused the blurry icons. I opened the Intel Graphics control panel and set the 3D Preference slider from "Performance" to the middle setting.

Prefer performance setting

Prefer performance setting

Middle performance setting

Middle performance setting

After this, the icons were sharp again 🙂 So I guess the graphics settings were influencing the method in which the icons are rendered.