After Boleslaus Yuriy of Masovia and Halych death in 1340, the rights to his domain were passed to his fellow Piast dynast and cousin, king Casimir III of Poland. The local nobles elected one of their own, Dmytro Dedko, as ruler, and repulsed a Polish invasion during the wars over the succession of Galicia-Volhynia Principality when King Casimir III undertook an expedition to conquer Lviv in 1340, burning down the old princely castle.