A good way to have avoided this would be to not smoke all of your weed in one night, so that you know you'll have more for the next day. Also, it helps to not smoke all your weed with other people. Set aside some for yourself.