A well regulated Militia, being necessary to the security of a free State, the right of the people to keep and bear Arms, shall not be infringed.
A way of resolving the problem would be for the Supreme Court to apply the opening phrase: "A well regulated Militia". Individuals shooting in schools, churches, or nightclubs, or while committing crimes are not "well regulated".
The US military requires soldiers' guns to be stored securely - "well regulated" - when not being used. Something similar for non-soldiers is needed.