memory access violation will happen if dir.size() == 0