It's a common misconception that he passed away while working on the film. While he was diagnosed with stomach cancer during the production, he actually died *after* the movie was completed, on June 11, 1979.
This misunderstanding likely stems from the fact that "The Shootist" was one of his final films, and his illness was quite public by the time it was released. It's easy to see how people would connect the two, especially given the movie's themes of mortality.
Let me know if you have any other questions about John Wayne or his films!