質問編集履歴
2
文章を修正
    
        title	
    CHANGED
    
    | 
         
            File without changes
         
     | 
    
        body	
    CHANGED
    
    | 
         @@ -1,14 +1,47 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            提示コードの`//ここで例外`部の行で以下のエラーが発生するのですがこれは何が原因なのでしょうか?
         
     | 
| 
      
 1 
     | 
    
         
            +
            提示コードの`//ここで例外`部の行で以下のエラーが発生するのですがこれは何が原因なのでしょうか?同じ状況を再現した実験コードを書きましたが問題なくコンパイルできます。
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            参考サイト: https://ufcpp.net/study/csharp/sp_unsafe.html#abst
         
     | 
| 
       4 
6 
     | 
    
         
             
            ##### Error
         
     | 
| 
       5 
7 
     | 
    
         
             
            ```
         
     | 
| 
       6 
8 
     | 
    
         
             
            System.AccessViolationException: 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'
         
     | 
| 
       7 
9 
     | 
    
         
             
            ```
         
     | 
| 
       8 
10 
     | 
    
         | 
| 
       9 
     | 
    
         
            -
            参考サイト: https://ufcpp.net/study/csharp/sp_unsafe.html#abst
         
     | 
| 
       10 
11 
     | 
    
         | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
            ##### 実験コード
         
     | 
| 
       11 
15 
     | 
    
         
             
            ```cs
         
     | 
| 
      
 16 
     | 
    
         
            +
            using System;
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
            public class Program
         
     | 
| 
      
 19 
     | 
    
         
            +
            {
         
     | 
| 
      
 20 
     | 
    
         
            +
                enum Status
         
     | 
| 
      
 21 
     | 
    
         
            +
                {
         
     | 
| 
      
 22 
     | 
    
         
            +
                    AAA,
         
     | 
| 
      
 23 
     | 
    
         
            +
                    BBB
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                }
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
                public static void Main()
         
     | 
| 
      
 28 
     | 
    
         
            +
                {
         
     | 
| 
      
 29 
     | 
    
         
            +
                    unsafe
         
     | 
| 
      
 30 
     | 
    
         
            +
                    {
         
     | 
| 
      
 31 
     | 
    
         
            +
                        Status status;
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
                        Status* t;
         
     | 
| 
      
 34 
     | 
    
         
            +
                        t = &status;
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
                    }
         
     | 
| 
      
 38 
     | 
    
         
            +
                }
         
     | 
| 
      
 39 
     | 
    
         
            +
            }
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
            ```
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
            ##### 問題のソースコード
         
     | 
| 
      
 44 
     | 
    
         
            +
            ```cs
         
     | 
| 
       12 
45 
     | 
    
         
             
            using FFmpeg.AutoGen;
         
     | 
| 
       13 
46 
     | 
    
         | 
| 
       14 
47 
     | 
    
         
             
            internal unsafe class Program
         
     | 
| 
         @@ -50,12 +83,13 @@ 
     | 
|
| 
       50 
83 
     | 
    
         | 
| 
       51 
84 
     | 
    
         
             
                    /* check that the encoder supports s16 pcm input */
         
     | 
| 
       52 
85 
     | 
    
         
             
                    c->sample_fmt = AVSampleFormat.AV_SAMPLE_FMT_S16;
         
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
      
 86 
     | 
    
         
            +
            ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
         
     | 
| 
       54 
87 
     | 
    
         
             
                    AVSampleFormat av;//列挙型
         
     | 
| 
       55 
88 
     | 
    
         
             
                    av = AVSampleFormat.AV_SAMPLE_FMT_S16;
         
     | 
| 
       56 
89 
     | 
    
         | 
| 
      
 90 
     | 
    
         
            +
                     //codec->sample_fmtsはAVSampleFormat型
         
     | 
| 
       57 
91 
     | 
    
         
             
                    codec->sample_fmts =  &av;  //ここで例外
         
     | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
      
 92 
     | 
    
         
            +
            ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
         
     | 
| 
       59 
93 
     | 
    
         
             
                    *codec->sample_fmts = AVSampleFormat.AV_SAMPLE_FMT_S16;
         
     | 
| 
       60 
94 
     | 
    
         
             
                    if (!check_sample_fmt(codec, c->sample_fmt))
         
     | 
| 
       61 
95 
     | 
    
         
             
                    {
         
     | 
1
タイトルを修正
    
        title	
    CHANGED
    
    | 
         @@ -1,1 +1,1 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            C#  
     | 
| 
      
 1 
     | 
    
         
            +
            C# *ポインタがのenumにアドレスのenumが設定できない原因が知りたい。
         
     | 
    
        body	
    CHANGED
    
    | 
         
            File without changes
         
     |