Invalid Device Signature, was working before

Hi i am trying to program atmega328p-au using arduino mega as an isp. I was able to burn boot loader and upload a blink sketch. Which was working.

Later i tried to upload other sketches and i would get invalid signature error with signature being some random value. But after some tries the sketch would upload.

After that signature would always verify and but i would get byte mismatch on location 0x0000.

Now i am getting Invalid Device signature error with signature being 0x000000 always.

My wiring:(it's correct as i did upload blink sketch and bootloader using this)

328p ------------ Mega
15(MISO) -------->51
16(MOSI) -------->50
17 (SCK) -------->52
29(Reset)-------->10------->10k ohm ------->5v

328p is powered using external supply.
All grounds are common.
cap between 5v and ground.
cap between reset and ground of Mega

Help will be really appreciated.