The stream module seems strange to me. When I compile my avi demuxer with -d: 
release it throws IO errors, but not without: The same file is read in both 
release and debug mode.

This is the part in which the error occurs: 
    
    
    proc read_video_frame*(avi: Avi; vidbuf: ptr UncheckedArray[byte]; 
video_pos: int; isKeyframe: var bool): int  =
      var n: int
      if avi.video_index.isNil:
        throw Exception: "AVI_ERR_NO_IDX"
      if video_pos < 0 or video_pos >= avi.video_frames:
        return -1
      n = avi.video_index[video_pos].len
      isKeyframe = avi.video_index[video_pos].key == 0x00000010
      echo fmt" {video_pos} / {avi.video_frames} position"
      
      avi.stream.setPosition(avi.video_index[video_pos].pos)  ## <- this line 
produces the error in release mode
      if avi.stream.readData(vidbuf, n) != n:
        throw Exception: "AVI_ERR_READ"
      return n
    
    
    Run

In release it reads some of frames but after a time it throws errors. Output 
with -d:release: 
    
    
    ...
    ...
    159 / 424 position
    isKey: true readCount: 364446
    160 / 424 position
    isKey: true readCount: 363571
    161 / 424 position
    isKey: true readCount: 361489
    162 / 424 position
    io.nim(138)              raiseEIO
    Error: unhandled exception: cannot set file position [IOError]
    
    
    Run

Maybe I'm missing something? Is my code buggy or is it a problem with stream 
module?

Maybe someone can push me in the right direction

Reply via email to