The problem is that you have two device variables. One at global scope, and one inside main. When you call createDevice() you assign to the one in main, but the global one is still left pointing to garbage. You then use the garbage device pointer to call getGUIEnvironment() , which crashes. /*Irrli...