[Xvid-devel] Division by Zero

Cédric OCHS kervala at gmail.com
Mon Jul 25 09:55:40 CEST 2011


Hi there,

I compiled the last revision of xvidcore from SVN in a x64 static library  
under Windows with MS VC++ 2010 Express.

I declared a 320x240 RGB24 format for image and initialized its buffer  
with :

size_t buffer_size = 320*240*3;

uint8_t *buffer = new uint8_t[buffer_size];

for(size_t i = 0; i < buffer_size; ++i)
{
	buffer[i] = i % 256;
}

And when I try to encode this RGB24 buffer to a XVid video (in fact, a  
still image), it generates a Division by Zero exception at the 4th frame  
(a B Frame apparently).

The exception occurs in SearchDirect_initial function of  
xvidcore/src/motion/estimation_bvop.c especially at the lines :

Data->directmvF[k].x = ((TRB * Data->referencemv[k].x) / TRD);
Data->directmvB[k].x = ((TRB - TRD) * Data->referencemv[k].x) / TRD;
Data->directmvF[k].y = ((TRB * Data->referencemv[k].y) / TRD);
Data->directmvB[k].y = ((TRB - TRD) * Data->referencemv[k].y) / TRD;

Because both TRD and TRB are set to 0.

I tried with a full white image (all bytes set to 255), it doesn't  
generate any exception and it works fine.

Please someone could check if it's reproducible ?

Currently, I fixed it replacing it by :

if (TRD)
{
	Data->directmvF[k].x = ((TRB * Data->referencemv[k].x) / TRD);
	Data->directmvB[k].x = ((TRB - TRD) * Data->referencemv[k].x) / TRD;
	Data->directmvF[k].y = ((TRB * Data->referencemv[k].y) / TRD);
	Data->directmvB[k].y = ((TRB - TRD) * Data->referencemv[k].y) / TRD;
}
else
{
	Data->directmvF[k].x = 0;
	Data->directmvB[k].x = 0;
	Data->directmvF[k].y = 0;
	Data->directmvB[k].y = 0;
}

Thanks a lot :)

Cédric


More information about the Xvid-devel mailing list