Colour Picking issue

Hey guys I have had picking working for a while but noticed a problem, not sure if it common and easy to fix but i noticed if something is behind what i pick it will pick that even though from what i can see in the viewport it is not there.

So basically if i’m looking at a table with an apple and an orange lined up on the X and Y axis and lets say the apple is in front of me and the orange is behind me i’m for some reason picking the orange.

I have no idea why this is happening though i set my view and drawning up the same way for both drawing the scene and the colour picking, so shouldn’t it be impossible for me to pick an object like the orange?

Sorry if this makes no sence I just tryed to explain whats happening the best i can.


Nevermind sorted the problem out.