Avoid possible crash in rendering loop
As soon as QgsMapLayer::setCacheImage is called while rendering is active, a crash occurs.
Due to the fact, that processEvents is called from the main rendering loop, such situations cannot always be foreseen.