質問編集履歴

2

文章を修正

2022/07/25 00:16

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -1,13 +1,46 @@
1
- 提示コードの`//ここで例外`部の行で以下のエラーが発生するのですがこれは何が原因なのでしょうか?
1
+ 提示コードの`//ここで例外`部の行で以下のエラーが発生するのですがこれは何が原因なのでしょうか?同じ状況を再現した実験コードを書きましたが問題なくコンパイルできます。
2
+
3
+
4
+
2
-
5
+ 参考サイト: https://ufcpp.net/study/csharp/sp_unsafe.html#abst
3
-
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
 
11
+
12
+
13
+
14
+ ##### 実験コード
15
+ ```cs
16
+ using System;
17
+
18
+ public class Program
19
+ {
20
+ enum Status
21
+ {
22
+ AAA,
23
+ BBB
24
+
25
+ }
26
+
9
- 参考サイト: https://ufcpp.net/study/csharp/sp_unsafe.html#abst
27
+ public static void Main()
10
-
28
+ {
29
+ unsafe
30
+ {
31
+ Status status;
32
+
33
+ Status* t;
34
+ t = &status;
35
+
36
+
37
+ }
38
+ }
39
+ }
40
+
41
+ ```
42
+
43
+ ##### 問題のソースコード
11
44
  ```cs
12
45
  using FFmpeg.AutoGen;
13
46
 
@@ -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

タイトルを修正

2022/07/25 00:05

投稿

退会済みユーザー
test CHANGED
@@ -1 +1 @@
1
- C# unsafe ['Attempted to read or write protected memory.]の解決方法が知りたい
1
+ C# *ポインタがのenumにアドレスのenumが設定できない原因が知りたい
test CHANGED
File without changes