We compute the maximum mass a growing planetary embryo can reach depending on the size of accreted planetesimals or pebbles, to infer the possibility of growing the cores of giant planets, and giant planets themselves. We compute the internal structure of the gas envelope of planetary embryos, to determine the core mass that is necessary to bind an envelope large enough to destroy planetesimals or pebbles while they are gravitationally captured. We also consider the effect of the advection wind originating from the protoplanetary disk, following the results of Ormel et al. (2015). We show that for low mass pebbles, once the planetary embryo is larger than ~1 Mearth, the envelope is large enough to destroy and vaporize pebbles completely before they can reach the core. The material constituting pebbles is therefore released in the planetary envelope, and later on dispersed in the protoplanetary disk, if the advection wind is strong enough. As a consequence the growth of the planetary embryo is stopped at a mass that is so small that Kelvin-Helmholtz accretion cannot lead to the accretion of significant amounts of gas. For larger planetesimals, a similar process occurs but at much larger mass, of the order of ten Earth masses, and is followed by rapid accretion of gas. If the effect of the advection is as efficient as described in Ormel al. (2015), the combined effect of the vaporization of accreted solids in the envelope of forming planetary embryos, and of this advection wind, prevents the growth of the planets at masses smaller or similar to the Earth mass in the case of formation by pebble accretion, up to a distance of the order of 10 AU. In the case of formation by accretion of large mass planetesimals, the growth of the planetary core is limited at masses ~10 Mearth but further growth of the planet can proceed by gas accretion.