@@ -185,6 +185,10 @@ bool ActivityMan::SaveCurrentGame(const std::string& fileName) {
185
185
zipWriteInFileInZip (zippedSaveFile, mainStreamView.data (), mainStreamView.size ());
186
186
zipCloseFileInZip (zippedSaveFile);
187
187
188
+ std::vector<SDL_IOStream*> pngStreams;
189
+ pngStreams.resize (sceneLayerInfos->size ());
190
+
191
+ // Generates PNGs (this is thread-safe)
188
192
std::for_each (std::execution::par_unseq,
189
193
sceneLayerInfos->begin (), sceneLayerInfos->end (),
190
194
[&](const SceneLayerInfo& layerInfo) {
@@ -206,20 +210,28 @@ bool ActivityMan::SaveCurrentGame(const std::string& fileName) {
206
210
return ;
207
211
}
208
212
209
- // Actually get the memory
210
- void * buffer = SDL_GetPointerProperty (SDL_GetIOProperties (stream), SDL_PROP_IOSTREAM_DYNAMIC_MEMORY_POINTER, nullptr );
211
- size_t size = static_cast <size_t >(SDL_GetIOSize (stream));
212
- if (!buffer || size < 0 ) {
213
- g_ConsoleMan.PrintString (" ERROR: Failed to save scenelayers to PNG!" );
214
- return ;
215
- }
213
+ size_t i = &layerInfo - &(*sceneLayerInfos->begin ());
214
+ pngStreams[i] = stream;
215
+ });
216
216
217
- zipOpenNewFileInZip (zippedSaveFile, (" Save " + layerInfo.name + " .png" ).c_str (), &zfi, nullptr , 0 , nullptr , 0 , nullptr , HACK_MZ_COMPRESS_METHOD_STORE, HACK_MZ_COMPRESS_LEVEL_FAST);
218
- zipWriteInFileInZip (zippedSaveFile, static_cast <const char *>(buffer), size);
219
- zipCloseFileInZip (zippedSaveFile);
217
+ // Actually save to the zip (this bit isn't thread-safe)
218
+ for (int i = 0 ; i < pngStreams.size (); ++i) {
219
+ SDL_IOStream* stream = pngStreams[i];
220
+
221
+ // Actually get the memory
222
+ void * buffer = SDL_GetPointerProperty (SDL_GetIOProperties (stream), SDL_PROP_IOSTREAM_DYNAMIC_MEMORY_POINTER, nullptr );
223
+ size_t size = static_cast <size_t >(SDL_GetIOSize (stream));
224
+ if (!stream || size < 0 ) {
225
+ g_ConsoleMan.PrintString (" ERROR: Failed to save scenelayers to PNG!" );
226
+ continue ;
227
+ }
220
228
221
- SDL_CloseIO (stream);
222
- });
229
+ zipOpenNewFileInZip (zippedSaveFile, (" Save " + (*sceneLayerInfos)[i].name + " .png" ).c_str (), &zfi, nullptr , 0 , nullptr , 0 , nullptr , HACK_MZ_COMPRESS_METHOD_STORE, HACK_MZ_COMPRESS_LEVEL_FAST);
230
+ zipWriteInFileInZip (zippedSaveFile, static_cast <const char *>(buffer), size);
231
+ zipCloseFileInZip (zippedSaveFile);
232
+
233
+ SDL_CloseIO (stream);
234
+ }
223
235
224
236
zipClose (zippedSaveFile, fileName.c_str ());
225
237
0 commit comments