@@ -343,6 +343,17 @@ def test_list_to_vector(self):
343343 dstFile .close ()
344344 try :
345345 nanovdb .io .writeGrids (dstFile .name , handles )
346+ # Verify that both grids actually made it into the file. Previously
347+ # writeGrids re-opened the file per handle with std::ios::trunc, so
348+ # only the final grid was retained on disk.
349+ metadata = nanovdb .io .readGridMetaData (dstFile .name )
350+ self .assertEqual (len (metadata ), len (handles ))
351+ readHandles = nanovdb .io .readGrids (dstFile .name )
352+ self .assertEqual (len (readHandles ), len (handles ))
353+ for readHandle in readHandles :
354+ self .assertEqual (readHandle .gridCount (), 1 )
355+ self .assertEqual (readHandle .gridType (0 ), nanovdb .GridType .Double )
356+ self .assertIsNotNone (readHandle .doubleGrid ())
346357 finally :
347358 os .unlink (dstFile .name )
348359
@@ -510,6 +521,22 @@ def test_read_write_grids(self):
510521 except RuntimeError :
511522 print ("ZIP compression codec not supported. Skipping..." )
512523
524+ def test_device_write_grids_multi (self ):
525+ # Regression test for deviceWriteGrids: all grids in the list must end
526+ # up in the output file, not just the last one.
527+ handle = nanovdb .tools .cuda .createLevelSetSphere (
528+ nanovdb .GridType .Float , name = self .gridName
529+ )
530+ handles = [handle , handle ]
531+ nanovdb .io .deviceWriteGrids (self .dstFile .name , handles )
532+ metadata = nanovdb .io .readGridMetaData (self .dstFile .name )
533+ self .assertEqual (len (metadata ), len (handles ))
534+ readHandles = nanovdb .io .deviceReadGrids (self .dstFile .name )
535+ self .assertEqual (len (readHandles ), len (handles ))
536+ for readHandle in readHandles :
537+ self .assertEqual (readHandle .gridCount (), 1 )
538+ self .assertEqual (readHandle .gridType (0 ), nanovdb .GridType .Float )
539+
513540
514541@unittest .skipIf (
515542 not nanovdb .isCudaAvailable (), "nanovdb module was compiled without CUDA support"
0 commit comments