Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

error_check should clear Devil's error stack #11

Open
tobim opened this Issue Jul 28, 2010 · 3 comments

Comments

Projects
None yet
3 participants

tobim commented Jul 28, 2010

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.

Owner

banister commented Jul 28, 2010

thanks, i'll get onto it soon

tobim commented Jul 28, 2010

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 Jan 27, 2014

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment