s-u / Cairo

R graphics device using cairo graphics library for creating high-quality output
12 stars 10 forks source link

possible wrong xd->npages when closing the device #5

Closed yixuan closed 10 years ago

yixuan commented 10 years ago

Hi Simon, I detected a possible bug in the current version of Cairo. Descriptions and possible solutions are given below.

Description:

CairoPNG() creates wrong number of images. The problem can be reproduced by the following code:

library(Cairo)
CairoPNG()
for(i in 1:5) plot(1, main = i)
dev.off()

It turns out that only four images are created, and the last image but one (i.e., the 4th image in the loop) is missing.

Possible reason:

In cairotalk.c => CairoGD_Close(), xd->npages doesn't increase by one as it does in CairoGD_NewPage(). So when the device is closing, the last image overwrites the previous one.

Solution:

Add one line of xd->npages++ before xd->cb->save_page(xd->cb,xd->npages);. I already created a pull request.

s-u commented 10 years ago

duplicate of #4