banister / devil

ruby bindings for devil cross platform image loading library
http://openil.sourceforge.net
Other
60 stars 9 forks source link

error_check should clear Devil's error stack #11

Open tobim-zz opened 14 years ago

tobim-zz commented 14 years ago

I ran into the problem that when a call to load_image failed, subsequent calls (with images Devil normally loads without a problem) would also fail for no apparent reason.

The problem seems to be that load_image may push multiple errors codes onto Devil's error stack (in my case there where around seven), but the error_check function calls IL.GetError() only once and so only pops one code of the stack.

The next time error_check is run it will raise an exception even if the previous operation was successful as there are still errors remaining on the stack.

As a workaround I clear the stack manually, by simply calling IL.GetError() until IL::NO_ERROR is returned.

banister commented 14 years ago

thanks, i'll get onto it soon

tobim-zz commented 14 years ago

Thank you very much for the fast response, I really do appreciate the work you are doing on this library.

I have to correct myself: error_check() might not be the best place to clear the stack as it is not used everywhere and it might be possible that some failed call to the IL module (either direct or via Devil::Image in example) might push an error onto the stack which would lead to the same problem.

So it would be better when the functions using error_check clear the stack at the beginning and error_check remains the way it is. Maybe a "with_error_check" block wrapper would be nice for this.

curi commented 10 years ago

I was having a lot of trouble with this and was considering using a separate process for every image manipulation because i found that reading a bad file would glitch attempts to deal with good images afterwards, and restarting rails would fix it. But after reading this bug report I tried running the following method before each use and in initial testing it seems like this may fix my problem. this code can be put in rails, you don't have to edit the library. no promises but maybe this will help someone.

def clear_errors 9999.times do return if IL.GetError() == IL::NO_ERROR end logger.warn "More than 9999 IL errors. Really!? next one is #{IL.GetError().inspect}" end