AsSalaamu Aalaykum
Hmm, first thing..boils down to your niyyah/intention, the opening of many books of hadeeths are first with the hadeeth of 'actions are judged by intentions, reported by Umar ibn Khattab (ra).....this hadeeth can be related to the topic...keep both your intentions and actions correct. Reminds me of a saying by the great Imam Shaafi'ee (along these lines) you can't do a good deed through the means of doing something bad...for example, to give sadaqah/charity, something Islam encourages us to do; so fulaan ibn fulaan has the intention of giving sadaqah, however he got the money through the means of stealing it and then gave it feesabililah,and on top expects some sort of ajar gained from it...that isn't correct..so always think whenever doing something, is your intention correct..if not, rectify it, and if you can't do that..leave the action.
Back to the topic of invalidation of deeds..these ayaat come to mind:
So woe to those who pray; those who are heedless of their prayer, those who make show [of their deeds];[Surah Ma'oon, verses 4-7]
Indeed, the hypocrites [think to] deceive Allah , but He is deceiving them. And when they stand for prayer, they stand lazily, showing [themselves to] the people and not remembering Allah except a little … [Surah Nisaa, verse 142]
---Riyya/Showing off...subhanAllah..one of the worst things to do..totally destroys ones deeds...
May Allah protect us from such evil whispers of shaytaan,Allahoma ameen