I have a sad tale and a suspicion or two. My plugin has a loop in which it loads a number of PNG files. Works on Mac–everywhere. Works on anything in WinXP (including Cubase 7–I figured how to install it there). Works on anything in Win7–except Cubase. Then it crashes without so much as a thank you. I have two virtual machines (32 and 64-bit). I have a laptop (64-bit). It crashes without fail on all of those machines. It’s not always the same file that kills it, but it’s almost always in the first 8-10 files.
Smells like a race condition, right? I made sure it was thread-safe (at least with my plugin) by protecting the image database with a mutex. I did it with external files and I did it by embedding the files within the plugin itself. Always crashes under Cubase7 on Win7 and never anywhere else (haven’t been on Win8 in a while, so let’s exclude it from the discussion). I’m not able to run Cubase under debug, so I had to revert to the time-honored tradition of dumping messages to a text file. I made sure to fflush after each write.
I found that the crash always occurred somewhere in [color=#0000FF]PNGImageFormat::decodeImage(InputStream&)[/color]. This function breaks down into two halves–in the first half, the file is read and some basic header data extracted. In the second half, the data are converted to the Image format. The crash is always in the first half–the file-reading/analysis half. I started to put more little debug prints into the function in that area. And it began to work…
I didn’t look real hard at the IO functions, but it sure looks to me like you’re using some sort of asynchronous IO. My speculation is that there’s some sort of global mode that Cubase sets in a way you don’t expect. The callbacks might be coming back before the IO is really complete and the logic dies because it’s operating on bad data. I’ve dealt with DMA controllers that interrupt before transfers are really complete and you have to be very careful. My sprintfs take long enough to allow file operations to complete.
I’ve been digging into this one for more than a week. I’ve rewritten the controlling logic enough different ways to change timing around in all sorts of ways. Yet it always happens right inside [color=#0000FF]PNGImageFormat::decodeImage[/color]. Jules, do you (or anyone else) remember that file IO well enough to comment?