ilInit() and ilShutdown() should use an internal counter that controls the initialization/shutdown process.
ilInit() should check this counter for being zero and perform library initialization if so. In any case, ilInit() should increases this counter by one.
ilShutdown() should decrease this counter by one if it is not already zero. If it gets zero, ilShutdown() should perform library shutdown.
This would improve DevIL in that way that it can be used in component-orientated architectures.
Different parts that both use DevIL independently can rely on a clean startup/shutdown sequence since they both can safely call ilInit() or ilShutdown() without interfering with other parts.
Please, if there is another way to solve this problem, please enlighten me! :-)
now it works like this in cvs.
Whew, that was fast! :)
Yes, it's better than before because I can't crash the lib calling ilInit() or ilShutdown() twice anymore.
But this does not solve the component part yet.
Imagine you have not a stand-alone application but a framework that consists of several independant parts.
Imagine further that part A and part B both use DevIL independently for their respective purposes.
If part A is started, it will call ilInit() within its initialization. So does part B which is started some time later.
But if part B terminates before part A, it will of course call ilDestroy(). But that's a trap because that will intefere with part A that is still working with DevIL.
Since part B cannot (and should not) know if other parts still use DevIL, ilShutdown() must not shutdown the library if others (part A in this case) still need it.
OpenGL und OpenAL deal with this using the context design pattern. Each part of a framework can create, work with or destroy its own Open*L-context.
The first context ever created also initializes the lib. The last context ever destroyed shuts down the lib.
If you do not want to introduce the context pattern to DevIL (yet), you can still solve this issue with a counter as described in my first post.
Apart from my suggestion: Keep up the good work and thank you for this very useful library! :)
that's a huge work, it was planned, but there are a lot of problems to solve before.
Log in to post a comment.