Category Archives: troubleshooting

First-chance exception at {address} (ntdll.dll) in {exename}.exe: 0xC0000139: Entry Point Not Found

Writing a plugin for a Windows application using Visual Studio?

You had the smarts to define the application’s exe as the debug executable in Visual Studio project options?

While reading the output, you saw the error from the post’s title?

First-chance exception at <address> (ntdll.dll) in <exename>.exe: 0xC0000139: Entry Point Not Found

You’ve probably got a classic case of app-uses-one-version-of-dll-while-one-of-my-plugin’s-dependencies-wants-another-one. In my case, I had to replace zlib1.dll in the app with the one that came with Igor Zlatković’s Win32 builds of libxml2, xmlsec, etc.

Read a bit more about the error, including different causes.

Mini tip on clearing iCloud bookmarks and starting over

I’ve got a backup of my several thousand bookmarks (mostly junk, but who’s got time to dig through it?), but I’ve played a bit with importing and exporting bookmarks from all over the place so the syncing with iCloud never ends. Too many changes!

So, how did I just finish dealing with that?

What follows is error prone, and if followed, may cause data loss. I’m not documenting this for your benefit, but for my own. Consider this a letter to myself in the future. Please don’t follow this unless you yourself know exactly what you’re doing and have three backups of your important data. Everything that has to do with syncing is error prone out of the box, even without a user messing with it.

As previously discussed, iCloud’s bookmark sync actually involves WebDAV and XBEL. It also involves a file containing all bookmarks: ~/Library/Safari/Bookmarks.plist.

So after ruthlessly murdering the SafariDAVClient process (and ensuring it doesn’t wake up until I want it to: watch -n1 killall SafariDAVClient), I opened the aforementioned file. There were over 30000 pending changes. That’s unacceptable.

So I went and deleted all bookmarks using Safari, for convenience. The plist editor I used didn’t allow selection of multiple items, so deleting bookmarks would take a while. I left alone the Reading List, because I didn’t have a proper backup of that. I took note of what the remote folder name of the Reading List was.

Then I mounted the root WebDAV mount point, and went and deleted every folder and bookmark except for the Reading List — thus bringing iCloud into sync with the local dataset.

Then I watched the progress as the changes were applied, and imported the bookmarks several times using a certain tool I use that also reduplicates bookmarks and keeps a copy of bookmarks, etc. I watched the progress by opening Bookmarks.plist and looking at how many changes were in the ./Sync/Changes array.

Mac App Store: “An unknown error has occurred”, iCloud: “Unable to sign in because of a problem communicating with iCloud. ” on genuine Mac

So perhaps you’re getting these errors?

iCloud
Unable to sign in because of a problem communicating with iCloud.
Try signing again.

App Store
An unknown error has occurred.

FaceTime
The server encountered an error processing registration. Please try again later.

Messages
The server encountered an error processing registration. Please try again later.

Perhaps you may say, “Gasp! This is supposed to be a hackintosh issue, and not an issue on genuine Macs!”

Fear not, my friend, if you have committed the ‘grievous sin’ of moving your Mac’s hard disk into another Mac. (As a penance, say 10 hailmarys quickly.) For you see, on occasion, Mac may get confused about your networking devices when you do this.

What do networking devices have to do with all this? If you read hackintosh forums, you’ll see that Apple seems to use your primary ethernet network card’s MAC address to identify the machine. And communicates the identity in some shape or form when you log into the aforementioned services.

Problem arises when your Mac’s primary ethernet card cannot be identified.

Cure for your transgression? Aside from those hailmaries, you’ll also want to delete (or move aside, or rename) /Library/Preferences/SystemConfiguration/NetworkInterfaces.plist. Then reboot. Behold! This file should be magically regenerated, and your access to iCloud and Mac App Store should be restored.

You’re welcome.

Naturally I’m not responsible if deleting this file harms your Mac, or if you do it yourself in process of deleting this file. Have an expert around. Then again, if you did move the disk around, you probably are the expert.

Accessing contents of a directory with App Sandbox temporary file exception

If you really, really need access to a path that Apple doesn’t want you to access while sandboxed (i.e. everywhere except what user selected, or a few paths like Documents, Music, Downloads) — you need to add a temporary file exception entitlement.

While these are intended as a stop-gap measure and are not intended for long-term use, they may help you solve your short-term problem.

How to use

After adding entitlements to your app (by marking that checkbox in Xcode), and after turning on Sandbox (again, by marking another checkbox in Xcode), you can see that a new plist-formatted file has appeared in your project with a single entry, com.apple.security.app-sandbox set to true.

Now add a new entry com.apple.security.temporary-exception.files.home-relative-path.read-only (or any of the other combinations of home-relative-path, absolute-path, read-only and read-write). Its type needs to be Array, and its contents need to be Strings.

I only used a single read-only, home-relative path. It needs to be formatted as follows: /Library/Somewhere/Some Data/

Gotchas

First of all… as mentioned, it’s not a String value, it’s an Array value containing strings.

Second… with NSFileManager, you are getting actual values for the first level of contents (e.g. folders), but when accessing subfolders you’re getting nil returnvalue and the error set to The file “2011-07-28” couldn’t be opened because you don’t have permission to view it.? Heh. See that slash on the end? It NEEDS to be there. It absolutely, 100% needs to be there, or else you’re getting the aforementioned permission denied error.

Third… you may be wondering, “How the hell am I going to get the user folder? NSHomeDirectory() is returning a path inside the sandbox container, and so do all other methods!”

Sure, if you stick to Cocoa. Apple has wrapped everything nicely, and I actually commend them on thoroughness. Even getpwent() returns incorrect values – I got /var/virusmail as the home folder.

There’s one thing that does return the username, however: NSUserName(). Don’t be easily tempted to construct the path by simply prepending /Users/. On my external drive, I tend to keep “recent cats” and “future cats”, in order to try everything out, but avoid breaking my workflow. However, it’s worthless unless I bring over the home folder, so on that installation, my home folder is not /Users/ivucica but /Volumes/Macintosh HD/Users/ivucica. Be careful, and use this solution.

#include <sys/types.h>
#include <pwd.h>

NSString * IVHomeDirectory()
{
  const struct passwd * passwd = getpwnam([NSUserName() UTF8String]);
  if(!passwd)
    return nil; // bail out cowardly
  const char *homeDir_c = getpwnam([NSUserName() UTF8String])->pw_dir;
  NSString *homeDir = [[NSFileManager defaultManager] 
                      stringWithFileSystemRepresentation:homeDir_c
                      length:strlen(homeDir_c)];
  return homeDir;
}

// simple drop-in replacement for NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
NSArray * IVLibraryDirectory()
{
  NSArray * libraryDirectories = [NSArray arrayWithObject: [IVHomeDirectory() stringByAppendingPathComponent:@"Library"]];
  return libraryDirectories;
}

Above solution is inspired by this answer on StackOverflow.

If this helped you, leave me a comment here, and perhaps upvote those comments I made on StackOverflow. Everyone deserves encouragement now and then, right? :)

Avoiding memory leak in OpenAL and crash in OpenAL for Mac

UPDATE: We’re still seeing the crash on Mac. Procedure described does fix the memory leak, though.

UPDATE 2: Crash on Mac is caused by what appears to be a bug in Apple’s code relating to queueing commands for execution on dedicated audio thread, and mutex lock breaking down. Since mutex lock seems to stop working, it’s only natural that a threading-related crash occurs.


When calling alSourceStop(), you might forget to unbind a buffer from the source. Did you unbind it?

alSourcei(this->sourceId, AL_BUFFER, AL_NONE);

If you get a crash on Mac with call stack containing OALSource::Play() and/or ending with OALSource::PrepBufferQueueForPlayback(), this is most probably a good fix. Looks like OpenAL on Mac might have a race condition somewhere unless you do this.

See difference between revision 293 and 294 in libxal, in file audiosystems/OpenAL/OpenAL_Player.cpp.

Half Life 2: “Failed to load the launcher DLL”

All of a sudden, without touching anything (in fact, without booting Windows during last few days) I got this upon trying to launch Half Life 2:

Failed to load the launcher DLL: 



The specified procedure could not be found. 




Verifying files did not help me. The solution (for me)? I went to:


C:\Program Files\Steam\steamapps\ivucica\half-life 2\bin


and I moved all the .dll files away. Then I relaunched the game. Steam happily recreated all .dlls, and the game now works. I safely removed old copies of the DLLs.


Since I didn’t think of making a screenshot, image from http://www.hl2world.com/bbs/-vp666240.html