c - aspect ratio of image crashing the program -


here code code maintain aspect ratio of image crashes when control goes int windowratio = widthofpreviewpane / heightofpreviewpane; can give idea why ??

int widthofpreviewpane = rectwidth(m_rcparent);  int heightofpreviewpane = rectheight(m_rcparent) ;   int imageratio = widthofimage / heightofimage; int windowratio = widthofpreviewpane / heightofpreviewpane;  if (windowratio > imageratio && widthofpreviewpane< widthofimage) {     m_ifinalheight = heightofpreviewpane;     m_ifinalwidth = m_ifinalheight * imageratio;     messagebox(null, l"1",l"error",              mb_iconerror | mb_ok); } else if (windowratio < imageratio && widthofpreviewpane< widthofimage) {     m_ifinalwidth = widthofpreviewpane;     m_ifinalheight = m_ifinalwidth / imageratio;         messagebox(null, l"2",l"error",              mb_iconerror | mb_ok); } else if(windowratio > imageratio && widthofpreviewpane> widthofimage) {     m_ifinalheight = heightofimage;     m_ifinalwidth = widthofimage;         messagebox(null, l"3",l"error",              mb_iconerror | mb_ok);  } else if(windowratio < imageratio && widthofpreviewpane> widthofimage) {     m_ifinalheight = heightofimage;     m_ifinalwidth = widthofimage;         messagebox(null, l"4",l"error",              mb_iconerror | mb_ok);  } 

the logic of algo correct found widthofpreviewpane , heightofpreviewpane=0 because function in have written code initialized @ last these 2 not initialized time when debugged them , avoided thid problem putting them in in if condition let control go inside if value not 0 , worked nicely. see this-

 if(widthofpreviewpane!= 0 && heightofpreviewpane!=0 )             {                   conditions here......              } 

and thats solved.


Comments