Commit 7d89f09f74e257d161acf710254f8ee194fd7c66

Ivan Epifanov 2020-12-18T14:28:09

ISO C90 fixes

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
diff --git a/src/audio/vita/SDL_vitaaudio.c b/src/audio/vita/SDL_vitaaudio.c
index 24aa0f5..810b5f4 100644
--- a/src/audio/vita/SDL_vitaaudio.c
+++ b/src/audio/vita/SDL_vitaaudio.c
@@ -87,8 +87,8 @@ VITAAUD_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
     }
 
     if(this->spec.freq < 48000) {
-		port = SCE_AUDIO_OUT_PORT_TYPE_BGM;
-	}
+        port = SCE_AUDIO_OUT_PORT_TYPE_BGM;
+    }
 
     this->hidden->channel = sceAudioOutOpenPort(port, this->spec.samples, this->spec.freq, format);
     if (this->hidden->channel < 0) {
diff --git a/src/file/SDL_rwops.c b/src/file/SDL_rwops.c
index 2d5bcc9..d2a7831 100644
--- a/src/file/SDL_rwops.c
+++ b/src/file/SDL_rwops.c
@@ -590,20 +590,22 @@ SDL_RWFromFile(const char *file, const char *mode)
     rwops->close = windows_file_close;
     rwops->type = SDL_RWOPS_WINFILE;
 #elif defined(__VITA__)
-    /* Try to open the file on the filesystem first */
-    FILE *fp = fopen(file, mode);
-    if (fp) {
-        return SDL_RWFromFP(fp, 1);
-    } else {
-        /* Try opening it from app0:/ container if it's a relative path */
-        char path[4096];
-        SDL_snprintf(path, 4096, "app0:/%s", file);
-        fp = fopen(path, mode);
-        if (fp) {
-            return SDL_RWFromFP(fp, 1);
-        }
+    {
+      /* Try to open the file on the filesystem first */
+      FILE *fp = fopen(file, mode);
+      if (fp) {
+          return SDL_RWFromFP(fp, 1);
+      } else {
+          /* Try opening it from app0:/ container if it's a relative path */
+          char path[4096];
+          SDL_snprintf(path, 4096, "app0:/%s", file);
+          fp = fopen(path, mode);
+          if (fp) {
+              return SDL_RWFromFP(fp, 1);
+          }
+      }
+      SDL_SetError("Couldn't open %s", file);
     }
-    SDL_SetError("Couldn't open %s", file);
 #elif HAVE_STDIO_H
     {
         #ifdef __APPLE__
diff --git a/src/joystick/vita/SDL_sysjoystick.c b/src/joystick/vita/SDL_sysjoystick.c
index 2ce1090..ccd217b 100644
--- a/src/joystick/vita/SDL_sysjoystick.c
+++ b/src/joystick/vita/SDL_sysjoystick.c
@@ -67,10 +67,10 @@ static point c = { 128, 32767 };
 static point d = { 128, 32767 };
 
 /* simple linear interpolation between two points */
-static SDL_INLINE void lerp (point *dest, point *a, point *b, float t)
+static SDL_INLINE void lerp (point *dest, point *first, point *second, float t)
 {
-    dest->x = a->x + (b->x - a->x)*t;
-    dest->y = a->y + (b->y - a->y)*t;
+    dest->x = first->x + (second->x - first->x) * t;
+    dest->y = first->y + (second->y - first->y) * t;
 }
 
 /* evaluate a point on a bezier-curve. t goes from 0 to 1.0 */
@@ -93,6 +93,7 @@ static int calc_bezier_y(float t)
 int VITA_JoystickInit(void)
 {
     int i;
+    SceCtrlPortInfo myPortInfo;
 
     /* Setup input */
     sceCtrlSetSamplingMode(SCE_CTRL_MODE_ANALOG_WIDE);
@@ -106,27 +107,26 @@ int VITA_JoystickInit(void)
         analog_map[127-i] = -1 * analog_map[i+128];
     }
 
-	SceCtrlPortInfo myPortInfo;
-
-	// Assume we have at least one controller, even when nothing is paired
-	// This way the user can jump in, pair a controller
-	// and control things immediately even if it is paired
-	// after the app has already started.
-
-	SDL_numjoysticks = 1;
-
-	//How many additional paired controllers are there?
-	sceCtrlGetControllerPortInfo(&myPortInfo);
-	//On Vita TV, port 0 and 1 are the same controller
-	//and that is the first one, so start at port 2
-	for (i=2; i<=4; i++)
-	{
-		if (myPortInfo.port[i]!=SCE_CTRL_TYPE_UNPAIRED)
-		{
-			SDL_numjoysticks++;
-		}
-	}
-  return SDL_numjoysticks;
+    // Assume we have at least one controller, even when nothing is paired
+    // This way the user can jump in, pair a controller
+    // and control things immediately even if it is paired
+    // after the app has already started.
+
+    SDL_numjoysticks = 1;
+
+    // How many additional paired controllers are there?
+    sceCtrlGetControllerPortInfo(&myPortInfo);
+
+    // On Vita TV, port 0 and 1 are the same controller
+    // and that is the first one, so start at port 2
+    for (i=2; i<=4; i++)
+    {
+        if (myPortInfo.port[i]!=SCE_CTRL_TYPE_UNPAIRED)
+        {
+            SDL_numjoysticks++;
+        }
+    }
+    return SDL_numjoysticks;
 }
 
 int VITA_JoystickGetCount()
diff --git a/src/render/vitagxm/SDL_render_vita_gxm.c b/src/render/vitagxm/SDL_render_vita_gxm.c
index 4ffe51d..d3c2f9d 100644
--- a/src/render/vitagxm/SDL_render_vita_gxm.c
+++ b/src/render/vitagxm/SDL_render_vita_gxm.c
@@ -470,12 +470,14 @@ VITA_GXM_QueueDrawLines(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const S
 static int
 VITA_GXM_QueueFillRects(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FRect * rects, int count)
 {
+    int color;
+    color_vertex *vertices;
     VITA_GXM_RenderData *data = (VITA_GXM_RenderData *) renderer->driverdata;
 
     cmd->data.draw.count = count;
-    int color = data->drawstate.color;
+    color = data->drawstate.color;
 
-    color_vertex *vertices = (color_vertex *)pool_memalign(
+    vertices = (color_vertex *)pool_memalign(
             data,
             4 * count * sizeof(color_vertex), // 4 vertices * count
             sizeof(color_vertex));
@@ -532,12 +534,13 @@ static int
 VITA_GXM_QueueCopy(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * texture,
     const SDL_Rect * srcrect, const SDL_FRect * dstrect)
 {
-
+    texture_vertex *vertices;
+    float u0, v0, u1, v1;
     VITA_GXM_RenderData *data = (VITA_GXM_RenderData *) renderer->driverdata;
 
     cmd->data.draw.count = 1;
 
-    texture_vertex *vertices = (texture_vertex *)pool_memalign(
+    vertices = (texture_vertex *)pool_memalign(
             data,
             4 * sizeof(texture_vertex), // 4 vertices
             sizeof(texture_vertex));
@@ -545,10 +548,10 @@ VITA_GXM_QueueCopy(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture 
     cmd->data.draw.first = (size_t)vertices;
     cmd->data.draw.texture = texture;
 
-    const float u0 = (float)srcrect->x / (float)texture->w;
-    const float v0 = (float)srcrect->y / (float)texture->h;
-    const float u1 = (float)(srcrect->x + srcrect->w) / (float)texture->w;
-    const float v1 = (float)(srcrect->y + srcrect->h) / (float)texture->h;
+    u0 = (float)srcrect->x / (float)texture->w;
+    v0 = (float)srcrect->y / (float)texture->h;
+    u1 = (float)(srcrect->x + srcrect->w) / (float)texture->w;
+    v1 = (float)(srcrect->y + srcrect->h) / (float)texture->h;
 
     vertices[0].x = dstrect->x;
     vertices[0].y = dstrect->y;
@@ -582,11 +585,23 @@ VITA_GXM_QueueCopyEx(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Textur
     const SDL_Rect * srcrect, const SDL_FRect * dstrect,
     const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip)
 {
+    texture_vertex *vertices;
+    float u0, v0, u1, v1;
+    float s, c;
+    float cw, sw, ch, sh;
+
     VITA_GXM_RenderData *data = (VITA_GXM_RenderData *) renderer->driverdata;
 
+    const float centerx = center->x;
+    const float centery = center->y;
+    const float x = dstrect->x + centerx;
+    const float y = dstrect->y + centery;
+    const float width = dstrect->w - centerx;
+    const float height = dstrect->h - centery;
+
     cmd->data.draw.count = 1;
 
-    texture_vertex *vertices = (texture_vertex *)pool_memalign(
+    vertices = (texture_vertex *)pool_memalign(
             data,
             4 * sizeof(texture_vertex), // 4 vertices
             sizeof(texture_vertex));
@@ -594,10 +609,10 @@ VITA_GXM_QueueCopyEx(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Textur
     cmd->data.draw.first = (size_t)vertices;
     cmd->data.draw.texture = texture;
 
-    float u0 = (float)srcrect->x / (float)texture->w;
-    float v0 = (float)srcrect->y / (float)texture->h;
-    float u1 = (float)(srcrect->x + srcrect->w) / (float)texture->w;
-    float v1 = (float)(srcrect->y + srcrect->h) / (float)texture->h;
+    u0 = (float)srcrect->x / (float)texture->w;
+    v0 = (float)srcrect->y / (float)texture->h;
+    u1 = (float)(srcrect->x + srcrect->w) / (float)texture->w;
+    v1 = (float)(srcrect->y + srcrect->h) / (float)texture->h;
 
     if (flip & SDL_FLIP_VERTICAL) {
         Swap(&v0, &v1);
@@ -607,20 +622,13 @@ VITA_GXM_QueueCopyEx(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Textur
         Swap(&u0, &u1);
     }
 
-    const float centerx = center->x;
-    const float centery = center->y;
-    const float x = dstrect->x + centerx;
-    const float y = dstrect->y + centery;
-    const float width = dstrect->w - centerx;
-    const float height = dstrect->h - centery;
-    float s, c;
 
     MathSincos(degToRad(angle), &s, &c);
 
-    const float cw = c * width;
-    const float sw = s * width;
-    const float ch = c * height;
-    const float sh = s * height;
+    cw = c * width;
+    sw = s * width;
+    ch = c * height;
+    sh = s * height;
 
     vertices[0].x = x - cw + sh;
     vertices[0].y = y - sw - ch;
@@ -654,9 +662,11 @@ VITA_GXM_QueueCopyEx(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Textur
 static int
 VITA_GXM_RenderClear(SDL_Renderer *renderer, SDL_RenderCommand *cmd)
 {
+    void *color_buffer;
+    float clear_color[4];
+
     VITA_GXM_RenderData *data = (VITA_GXM_RenderData *) renderer->driverdata;
 
-    float clear_color[4];
     clear_color[0] = (cmd->data.color.r)/255.0f;
     clear_color[1] = (cmd->data.color.g)/255.0f;
     clear_color[2] = (cmd->data.color.b)/255.0f;
@@ -669,7 +679,6 @@ VITA_GXM_RenderClear(SDL_Renderer *renderer, SDL_RenderCommand *cmd)
     sceGxmSetFragmentProgram(data->gxm_context, data->clearFragmentProgram);
 
     // set the clear color
-    void *color_buffer;
     sceGxmReserveFragmentDefaultUniformBuffer(data->gxm_context, &color_buffer);
     sceGxmSetUniformDataF(color_buffer, data->clearClearColorParam, 0, 4, clear_color);
 
@@ -726,6 +735,7 @@ SetDrawState(VITA_GXM_RenderData *data, const SDL_RenderCommand *cmd, SDL_bool s
     SceGxmVertexProgram *vertex_program;
     SDL_bool matrix_updated = SDL_FALSE;
     SDL_bool program_updated = SDL_FALSE;
+    Uint32 texture_color;
 
     Uint8 r, g, b, a;
     r = cmd->data.draw.r;
@@ -802,7 +812,7 @@ SetDrawState(VITA_GXM_RenderData *data, const SDL_RenderCommand *cmd, SDL_bool s
         program_updated = SDL_TRUE;
     }
 
-    Uint32 texture_color = ((a << 24) | (b << 16) | (g << 8) | r);
+    texture_color = ((a << 24) | (b << 16) | (g << 8) | r);
 
     if (program_updated || matrix_updated) {
         if (data->drawstate.fragment_program == data->textureFragmentProgram) {
@@ -811,13 +821,14 @@ SetDrawState(VITA_GXM_RenderData *data, const SDL_RenderCommand *cmd, SDL_bool s
             sceGxmSetUniformDataF(vertex_wvp_buffer, data->textureWvpParam, 0, 16, data->ortho_matrix);
         } else if (data->drawstate.fragment_program == data->textureTintFragmentProgram) {
             void *vertex_wvp_buffer;
+            void *texture_tint_color_buffer;
+            float *tint_color;
             sceGxmReserveVertexDefaultUniformBuffer(data->gxm_context, &vertex_wvp_buffer);
             sceGxmSetUniformDataF(vertex_wvp_buffer, data->textureWvpParam, 0, 16, data->ortho_matrix);
 
-            void *texture_tint_color_buffer;
             sceGxmReserveFragmentDefaultUniformBuffer(data->gxm_context, &texture_tint_color_buffer);
 
-            float *tint_color = pool_memalign(
+            tint_color = pool_memalign(
                 data,
                 4 * sizeof(float), // RGBA
                 sizeof(float)
@@ -837,9 +848,10 @@ SetDrawState(VITA_GXM_RenderData *data, const SDL_RenderCommand *cmd, SDL_bool s
     } else {
         if (data->drawstate.fragment_program == data->textureTintFragmentProgram && data->drawstate.texture_color != texture_color) {
             void *texture_tint_color_buffer;
+            float *tint_color;
             sceGxmReserveFragmentDefaultUniformBuffer(data->gxm_context, &texture_tint_color_buffer);
 
-            float *tint_color = pool_memalign(
+            tint_color = pool_memalign(
                 data,
                 4 * sizeof(float), // RGBA
                 sizeof(float)
@@ -879,8 +891,8 @@ SetCopyState(SDL_Renderer *renderer, const SDL_RenderCommand *cmd)
 static int
 VITA_GXM_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize)
 {
-    StartDrawing(renderer);
     VITA_GXM_RenderData *data = (VITA_GXM_RenderData *) renderer->driverdata;
+    StartDrawing(renderer);
 
     data->drawstate.target = renderer->target;
     if (!data->drawstate.target) {
@@ -963,13 +975,16 @@ VITA_GXM_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *
 
 void read_pixels(int x, int y, size_t width, size_t height, void *data) {
     SceDisplayFrameBuf pParam;
+    int i, j;
+    Uint32 *out32;
+    Uint32 *in32;
+
     pParam.size = sizeof(SceDisplayFrameBuf);
 
     sceDisplayGetFrameBuf(&pParam, SCE_DISPLAY_SETBUF_NEXTFRAME);
 
-    int i, j;
-    Uint32 *out32 = (Uint32 *)data;
-    Uint32 *in32 = (Uint32 *)pParam.base;
+    out32 = (Uint32 *)data;
+    in32 = (Uint32 *)pParam.base;
 
     in32 += (x + y * pParam.pitch);
 
@@ -986,11 +1001,6 @@ static int
 VITA_GXM_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect,
     Uint32 pixel_format, void *pixels, int pitch)
 {
-    // TODO: read from texture rendertarget. Although no-one sane should do it.
-    if (renderer->target) {
-        return SDL_Unsupported();
-    }
-
     Uint32 temp_format = renderer->target ? renderer->target->format : SDL_PIXELFORMAT_ABGR8888;
     size_t buflen;
     void *temp_pixels;
@@ -999,6 +1009,12 @@ VITA_GXM_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect,
     int w, h, length, rows;
     int status;
 
+    // TODO: read from texture rendertarget. Although no-one sane should do it.
+    if (renderer->target) {
+        return SDL_Unsupported();
+    }
+
+
     temp_pitch = rect->w * SDL_BYTESPERPIXEL(temp_format);
     buflen = rect->h * temp_pitch;
     if (buflen == 0) {
@@ -1047,14 +1063,10 @@ static void
 VITA_GXM_RenderPresent(SDL_Renderer *renderer)
 {
     VITA_GXM_RenderData *data = (VITA_GXM_RenderData *) renderer->driverdata;
-
-//    sceGxmFinish(data->gxm_context);
+    SceCommonDialogUpdateParam updateParam;
 
     data->displayData.address = data->displayBufferData[data->backBufferIndex];
 
-
-    SceCommonDialogUpdateParam updateParam;
-
     SDL_memset(&updateParam, 0, sizeof(updateParam));
 
     updateParam.renderTarget.colorFormat    = VITA_GXM_COLOR_FORMAT;
diff --git a/src/render/vitagxm/SDL_render_vita_gxm_tools.c b/src/render/vitagxm/SDL_render_vita_gxm_tools.c
index 12065ce..411c70c 100644
--- a/src/render/vitagxm/SDL_render_vita_gxm_tools.c
+++ b/src/render/vitagxm/SDL_render_vita_gxm_tools.c
@@ -71,8 +71,8 @@ init_orthographic_matrix(float *m, float left, float right, float bottom, float 
 static void *
 patcher_host_alloc(void *user_data, unsigned int size)
 {
-    (void)user_data;
     void *mem = SDL_malloc(size);
+    (void)user_data;
     return mem;
 }
 
@@ -222,6 +222,7 @@ make_fragment_programs(VITA_GXM_RenderData *data, fragment_programs *out,
 static void
 set_stencil_mask(VITA_GXM_RenderData *data, float x, float y, float w, float h)
 {
+    void *vertexDefaultBuffer;
     color_vertex *vertices = (color_vertex *)pool_memalign(
         data,
         4 * sizeof(color_vertex), // 4 vertices
@@ -253,7 +254,6 @@ set_stencil_mask(VITA_GXM_RenderData *data, float x, float y, float w, float h)
     sceGxmSetVertexProgram(data->gxm_context, data->colorVertexProgram);
     sceGxmSetFragmentProgram(data->gxm_context, data->colorFragmentProgram);
 
-    void *vertexDefaultBuffer;
     sceGxmReserveVertexDefaultUniformBuffer(data->gxm_context, &vertexDefaultBuffer);
     sceGxmSetUniformDataF(vertexDefaultBuffer, data->colorWvpParam, 0, 16, data->ortho_matrix);
 
@@ -324,6 +324,84 @@ gxm_init(SDL_Renderer *renderer)
 {
     unsigned int i, x, y;
     int err;
+    void *vdmRingBuffer;
+    void *vertexRingBuffer;
+    void *fragmentRingBuffer;
+    unsigned int fragmentUsseRingBufferOffset;
+    void *fragmentUsseRingBuffer;
+    unsigned int patcherVertexUsseOffset;
+    unsigned int patcherFragmentUsseOffset;
+    void *patcherBuffer;
+    void *patcherVertexUsse;
+    void *patcherFragmentUsse;
+
+    SceGxmRenderTargetParams renderTargetParams;
+    SceGxmShaderPatcherParams patcherParams;
+
+    // compute the memory footprint of the depth buffer
+    const unsigned int alignedWidth = ALIGN(VITA_GXM_SCREEN_WIDTH, SCE_GXM_TILE_SIZEX);
+    const unsigned int alignedHeight = ALIGN(VITA_GXM_SCREEN_HEIGHT, SCE_GXM_TILE_SIZEY);
+
+    unsigned int sampleCount = alignedWidth * alignedHeight;
+    unsigned int depthStrideInSamples = alignedWidth;
+
+    // set buffer sizes for this sample
+    const unsigned int patcherBufferSize        = 64*1024;
+    const unsigned int patcherVertexUsseSize    = 64*1024;
+    const unsigned int patcherFragmentUsseSize  = 64*1024;
+
+    // Fill SceGxmBlendInfo
+    static const SceGxmBlendInfo blend_info_none = {
+        .colorFunc = SCE_GXM_BLEND_FUNC_NONE,
+        .alphaFunc = SCE_GXM_BLEND_FUNC_NONE,
+        .colorSrc  = SCE_GXM_BLEND_FACTOR_ZERO,
+        .colorDst  = SCE_GXM_BLEND_FACTOR_ZERO,
+        .alphaSrc  = SCE_GXM_BLEND_FACTOR_ZERO,
+        .alphaDst  = SCE_GXM_BLEND_FACTOR_ZERO,
+        .colorMask = SCE_GXM_COLOR_MASK_ALL
+    };
+
+    static const SceGxmBlendInfo blend_info_blend = {
+        .colorFunc = SCE_GXM_BLEND_FUNC_ADD,
+        .alphaFunc = SCE_GXM_BLEND_FUNC_ADD,
+        .colorSrc  = SCE_GXM_BLEND_FACTOR_SRC_ALPHA,
+        .colorDst  = SCE_GXM_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
+        .alphaSrc  = SCE_GXM_BLEND_FACTOR_ONE,
+        .alphaDst  = SCE_GXM_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
+        .colorMask = SCE_GXM_COLOR_MASK_ALL
+    };
+
+    static const SceGxmBlendInfo blend_info_add = {
+        .colorFunc = SCE_GXM_BLEND_FUNC_ADD,
+        .alphaFunc = SCE_GXM_BLEND_FUNC_ADD,
+        .colorSrc  = SCE_GXM_BLEND_FACTOR_SRC_ALPHA,
+        .colorDst  = SCE_GXM_BLEND_FACTOR_ONE,
+        .alphaSrc  = SCE_GXM_BLEND_FACTOR_ZERO,
+        .alphaDst  = SCE_GXM_BLEND_FACTOR_ONE,
+        .colorMask = SCE_GXM_COLOR_MASK_ALL
+    };
+
+    static const SceGxmBlendInfo blend_info_mod = {
+        .colorFunc = SCE_GXM_BLEND_FUNC_ADD,
+        .alphaFunc = SCE_GXM_BLEND_FUNC_ADD,
+
+        .colorSrc  = SCE_GXM_BLEND_FACTOR_ZERO,
+        .colorDst  = SCE_GXM_BLEND_FACTOR_SRC_COLOR,
+
+        .alphaSrc  = SCE_GXM_BLEND_FACTOR_ZERO,
+        .alphaDst  = SCE_GXM_BLEND_FACTOR_ONE,
+        .colorMask = SCE_GXM_COLOR_MASK_ALL
+    };
+
+    static const SceGxmBlendInfo blend_info_mul = {
+        .colorFunc = SCE_GXM_BLEND_FUNC_ADD,
+        .alphaFunc = SCE_GXM_BLEND_FUNC_ADD,
+        .colorSrc  = SCE_GXM_BLEND_FACTOR_DST_COLOR,
+        .colorDst  = SCE_GXM_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
+        .alphaSrc  = SCE_GXM_BLEND_FACTOR_DST_ALPHA,
+        .alphaDst  = SCE_GXM_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
+        .colorMask = SCE_GXM_COLOR_MASK_ALL
+    };
 
     VITA_GXM_RenderData *data = (VITA_GXM_RenderData *) renderer->driverdata;
 
@@ -343,29 +421,28 @@ gxm_init(SDL_Renderer *renderer)
     }
 
     // allocate ring buffer memory using default sizes
-    void *vdmRingBuffer = mem_gpu_alloc(
+    vdmRingBuffer = mem_gpu_alloc(
         SCE_KERNEL_MEMBLOCK_TYPE_USER_RW_UNCACHE,
         SCE_GXM_DEFAULT_VDM_RING_BUFFER_SIZE,
         4,
         SCE_GXM_MEMORY_ATTRIB_READ,
         &data->vdmRingBufferUid);
 
-    void *vertexRingBuffer = mem_gpu_alloc(
+    vertexRingBuffer = mem_gpu_alloc(
         SCE_KERNEL_MEMBLOCK_TYPE_USER_RW_UNCACHE,
         SCE_GXM_DEFAULT_VERTEX_RING_BUFFER_SIZE,
         4,
         SCE_GXM_MEMORY_ATTRIB_READ,
         &data->vertexRingBufferUid);
 
-    void *fragmentRingBuffer = mem_gpu_alloc(
+    fragmentRingBuffer = mem_gpu_alloc(
         SCE_KERNEL_MEMBLOCK_TYPE_USER_RW_UNCACHE,
         SCE_GXM_DEFAULT_FRAGMENT_RING_BUFFER_SIZE,
         4,
         SCE_GXM_MEMORY_ATTRIB_READ,
         &data->fragmentRingBufferUid);
 
-    unsigned int fragmentUsseRingBufferOffset;
-    void *fragmentUsseRingBuffer = mem_fragment_usse_alloc(
+    fragmentUsseRingBuffer = mem_fragment_usse_alloc(
         SCE_GXM_DEFAULT_FRAGMENT_USSE_RING_BUFFER_SIZE,
         &data->fragmentUsseRingBufferUid,
         &fragmentUsseRingBufferOffset);
@@ -390,7 +467,6 @@ gxm_init(SDL_Renderer *renderer)
     }
 
     // set up parameters
-    SceGxmRenderTargetParams renderTargetParams;
     SDL_memset(&renderTargetParams, 0, sizeof(SceGxmRenderTargetParams));
     renderTargetParams.flags                = 0;
     renderTargetParams.width                = VITA_GXM_SCREEN_WIDTH;
@@ -454,12 +530,6 @@ gxm_init(SDL_Renderer *renderer)
 
     }
 
-    // compute the memory footprint of the depth buffer
-    const unsigned int alignedWidth = ALIGN(VITA_GXM_SCREEN_WIDTH, SCE_GXM_TILE_SIZEX);
-    const unsigned int alignedHeight = ALIGN(VITA_GXM_SCREEN_HEIGHT, SCE_GXM_TILE_SIZEY);
-
-    unsigned int sampleCount = alignedWidth * alignedHeight;
-    unsigned int depthStrideInSamples = alignedWidth;
 
     // allocate the depth buffer
     data->depthBufferData = mem_gpu_alloc(
@@ -500,33 +570,26 @@ gxm_init(SDL_Renderer *renderer)
         0xFF,
         0xFF);
 
-    // set buffer sizes for this sample
-    const unsigned int patcherBufferSize        = 64*1024;
-    const unsigned int patcherVertexUsseSize    = 64*1024;
-    const unsigned int patcherFragmentUsseSize  = 64*1024;
 
     // allocate memory for buffers and USSE code
-    void *patcherBuffer = mem_gpu_alloc(
+    patcherBuffer = mem_gpu_alloc(
         SCE_KERNEL_MEMBLOCK_TYPE_USER_RW_UNCACHE,
         patcherBufferSize,
         4,
         SCE_GXM_MEMORY_ATTRIB_READ | SCE_GXM_MEMORY_ATTRIB_WRITE,
         &data->patcherBufferUid);
 
-    unsigned int patcherVertexUsseOffset;
-    void *patcherVertexUsse = mem_vertex_usse_alloc(
+    patcherVertexUsse = mem_vertex_usse_alloc(
         patcherVertexUsseSize,
         &data->patcherVertexUsseUid,
         &patcherVertexUsseOffset);
 
-    unsigned int patcherFragmentUsseOffset;
-    void *patcherFragmentUsse = mem_fragment_usse_alloc(
+    patcherFragmentUsse = mem_fragment_usse_alloc(
         patcherFragmentUsseSize,
         &data->patcherFragmentUsseUid,
         &patcherFragmentUsseOffset);
 
     // create a shader patcher
-    SceGxmShaderPatcherParams patcherParams;
     SDL_memset(&patcherParams, 0, sizeof(SceGxmShaderPatcherParams));
     patcherParams.userData                  = NULL;
     patcherParams.hostAllocCallback         = &patcher_host_alloc;
@@ -639,111 +702,61 @@ gxm_init(SDL_Renderer *renderer)
         return err;
     }
 
-    // Fill SceGxmBlendInfo
-    static const SceGxmBlendInfo blend_info_none = {
-        .colorFunc = SCE_GXM_BLEND_FUNC_NONE,
-        .alphaFunc = SCE_GXM_BLEND_FUNC_NONE,
-        .colorSrc  = SCE_GXM_BLEND_FACTOR_ZERO,
-        .colorDst  = SCE_GXM_BLEND_FACTOR_ZERO,
-        .alphaSrc  = SCE_GXM_BLEND_FACTOR_ZERO,
-        .alphaDst  = SCE_GXM_BLEND_FACTOR_ZERO,
-        .colorMask = SCE_GXM_COLOR_MASK_ALL
-    };
 
-    static const SceGxmBlendInfo blend_info_blend = {
-        .colorFunc = SCE_GXM_BLEND_FUNC_ADD,
-        .alphaFunc = SCE_GXM_BLEND_FUNC_ADD,
-        .colorSrc  = SCE_GXM_BLEND_FACTOR_SRC_ALPHA,
-        .colorDst  = SCE_GXM_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
-        .alphaSrc  = SCE_GXM_BLEND_FACTOR_ONE,
-        .alphaDst  = SCE_GXM_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
-        .colorMask = SCE_GXM_COLOR_MASK_ALL
-    };
-
-    static const SceGxmBlendInfo blend_info_add = {
-        .colorFunc = SCE_GXM_BLEND_FUNC_ADD,
-        .alphaFunc = SCE_GXM_BLEND_FUNC_ADD,
-        .colorSrc  = SCE_GXM_BLEND_FACTOR_SRC_ALPHA,
-        .colorDst  = SCE_GXM_BLEND_FACTOR_ONE,
-        .alphaSrc  = SCE_GXM_BLEND_FACTOR_ZERO,
-        .alphaDst  = SCE_GXM_BLEND_FACTOR_ONE,
-        .colorMask = SCE_GXM_COLOR_MASK_ALL
-    };
-
-    static const SceGxmBlendInfo blend_info_mod = {
-        .colorFunc = SCE_GXM_BLEND_FUNC_ADD,
-        .alphaFunc = SCE_GXM_BLEND_FUNC_ADD,
-
-        .colorSrc  = SCE_GXM_BLEND_FACTOR_ZERO,
-        .colorDst  = SCE_GXM_BLEND_FACTOR_SRC_COLOR,
-
-        .alphaSrc  = SCE_GXM_BLEND_FACTOR_ZERO,
-        .alphaDst  = SCE_GXM_BLEND_FACTOR_ONE,
-        .colorMask = SCE_GXM_COLOR_MASK_ALL
-    };
-
-    static const SceGxmBlendInfo blend_info_mul = {
-        .colorFunc = SCE_GXM_BLEND_FUNC_ADD,
-        .alphaFunc = SCE_GXM_BLEND_FUNC_ADD,
-        .colorSrc  = SCE_GXM_BLEND_FACTOR_DST_COLOR,
-        .colorDst  = SCE_GXM_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
-        .alphaSrc  = SCE_GXM_BLEND_FACTOR_DST_ALPHA,
-        .alphaDst  = SCE_GXM_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
-        .colorMask = SCE_GXM_COLOR_MASK_ALL
-    };
+    {
+        // get attributes by name to create vertex format bindings
+        const SceGxmProgramParameter *paramClearPositionAttribute = sceGxmProgramFindParameterByName(clearVertexProgramGxp, "aPosition");
+
+        // create clear vertex format
+        SceGxmVertexAttribute clearVertexAttributes[1];
+        SceGxmVertexStream clearVertexStreams[1];
+        clearVertexAttributes[0].streamIndex    = 0;
+        clearVertexAttributes[0].offset         = 0;
+        clearVertexAttributes[0].format         = SCE_GXM_ATTRIBUTE_FORMAT_F32;
+        clearVertexAttributes[0].componentCount = 2;
+        clearVertexAttributes[0].regIndex       = sceGxmProgramParameterGetResourceIndex(paramClearPositionAttribute);
+        clearVertexStreams[0].stride            = sizeof(clear_vertex);
+        clearVertexStreams[0].indexSource       = SCE_GXM_INDEX_SOURCE_INDEX_16BIT;
+
+        // create clear programs
+        err = sceGxmShaderPatcherCreateVertexProgram(
+            data->shaderPatcher,
+            data->clearVertexProgramId,
+            clearVertexAttributes,
+            1,
+            clearVertexStreams,
+            1,
+            &data->clearVertexProgram
+        );
+        if (err != SCE_OK) {
+            SDL_LogError(SDL_LOG_CATEGORY_RENDER, "create program (clear vertex) failed: %d\n", err);
+            return err;
+        }
 
-    // get attributes by name to create vertex format bindings
-    const SceGxmProgramParameter *paramClearPositionAttribute = sceGxmProgramFindParameterByName(clearVertexProgramGxp, "aPosition");
-
-    // create clear vertex format
-    SceGxmVertexAttribute clearVertexAttributes[1];
-    SceGxmVertexStream clearVertexStreams[1];
-    clearVertexAttributes[0].streamIndex    = 0;
-    clearVertexAttributes[0].offset         = 0;
-    clearVertexAttributes[0].format         = SCE_GXM_ATTRIBUTE_FORMAT_F32;
-    clearVertexAttributes[0].componentCount = 2;
-    clearVertexAttributes[0].regIndex       = sceGxmProgramParameterGetResourceIndex(paramClearPositionAttribute);
-    clearVertexStreams[0].stride            = sizeof(clear_vertex);
-    clearVertexStreams[0].indexSource       = SCE_GXM_INDEX_SOURCE_INDEX_16BIT;
-
-    // create clear programs
-    err = sceGxmShaderPatcherCreateVertexProgram(
-        data->shaderPatcher,
-        data->clearVertexProgramId,
-        clearVertexAttributes,
-        1,
-        clearVertexStreams,
-        1,
-        &data->clearVertexProgram
-    );
-    if (err != SCE_OK) {
-        SDL_LogError(SDL_LOG_CATEGORY_RENDER, "create program (clear vertex) failed: %d\n", err);
-        return err;
-    }
+        err = sceGxmShaderPatcherCreateFragmentProgram(
+            data->shaderPatcher,
+            data->clearFragmentProgramId,
+            SCE_GXM_OUTPUT_REGISTER_FORMAT_UCHAR4,
+            0,
+            NULL,
+            clearVertexProgramGxp,
+            &data->clearFragmentProgram
+        );
+        if (err != SCE_OK) {
+            SDL_LogError(SDL_LOG_CATEGORY_RENDER, "create program (clear fragment) failed: %d\n", err);
+            return err;
+        }
 
-    err = sceGxmShaderPatcherCreateFragmentProgram(
-        data->shaderPatcher,
-        data->clearFragmentProgramId,
-        SCE_GXM_OUTPUT_REGISTER_FORMAT_UCHAR4,
-        0,
-        NULL,
-        clearVertexProgramGxp,
-        &data->clearFragmentProgram
-    );
-    if (err != SCE_OK) {
-        SDL_LogError(SDL_LOG_CATEGORY_RENDER, "create program (clear fragment) failed: %d\n", err);
-        return err;
+        // create the clear triangle vertex/index data
+        data->clearVertices = (clear_vertex *)mem_gpu_alloc(
+            SCE_KERNEL_MEMBLOCK_TYPE_USER_RW_UNCACHE,
+            3*sizeof(clear_vertex),
+            4,
+            SCE_GXM_MEMORY_ATTRIB_READ,
+            &data->clearVerticesUid
+        );
     }
 
-    // create the clear triangle vertex/index data
-    data->clearVertices = (clear_vertex *)mem_gpu_alloc(
-        SCE_KERNEL_MEMBLOCK_TYPE_USER_RW_UNCACHE,
-        3*sizeof(clear_vertex),
-        4,
-        SCE_GXM_MEMORY_ATTRIB_READ,
-        &data->clearVerticesUid
-    );
-
     // Allocate a 64k * 2 bytes = 128 KiB buffer and store all possible
     // 16-bit indices in linear ascending order, so we can use this for
     // all drawing operations where we don't want to use indexing.
@@ -755,7 +768,7 @@ gxm_init(SDL_Renderer *renderer)
         &data->linearIndicesUid
     );
 
-    for (uint32_t i=0; i<=UINT16_MAX; ++i)
+    for (i = 0; i <= UINT16_MAX; ++i)
     {
         data->linearIndices[i] = i;
     }
@@ -767,79 +780,86 @@ gxm_init(SDL_Renderer *renderer)
     data->clearVertices[2].x = -1.0f;
     data->clearVertices[2].y =  3.0f;
 
-    const SceGxmProgramParameter *paramColorPositionAttribute = sceGxmProgramFindParameterByName(colorVertexProgramGxp, "aPosition");
-
-    const SceGxmProgramParameter *paramColorColorAttribute = sceGxmProgramFindParameterByName(colorVertexProgramGxp, "aColor");
-
-    // create color vertex format
-    SceGxmVertexAttribute colorVertexAttributes[2];
-    SceGxmVertexStream colorVertexStreams[1];
-    /* x,y,z: 3 float 32 bits */
-    colorVertexAttributes[0].streamIndex = 0;
-    colorVertexAttributes[0].offset = 0;
-    colorVertexAttributes[0].format = SCE_GXM_ATTRIBUTE_FORMAT_F32;
-    colorVertexAttributes[0].componentCount = 3; // (x, y, z)
-    colorVertexAttributes[0].regIndex = sceGxmProgramParameterGetResourceIndex(paramColorPositionAttribute);
-    /* color: 4 unsigned char  = 32 bits */
-    colorVertexAttributes[1].streamIndex = 0;
-    colorVertexAttributes[1].offset = 12; // (x, y, z) * 4 = 12 bytes
-    colorVertexAttributes[1].format = SCE_GXM_ATTRIBUTE_FORMAT_U8N;
-    colorVertexAttributes[1].componentCount = 4; // (color)
-    colorVertexAttributes[1].regIndex = sceGxmProgramParameterGetResourceIndex(paramColorColorAttribute);
-    // 16 bit (short) indices
-    colorVertexStreams[0].stride = sizeof(color_vertex);
-    colorVertexStreams[0].indexSource = SCE_GXM_INDEX_SOURCE_INDEX_16BIT;
-
-    // create color shaders
-    err = sceGxmShaderPatcherCreateVertexProgram(
-        data->shaderPatcher,
-        data->colorVertexProgramId,
-        colorVertexAttributes,
-        2,
-        colorVertexStreams,
-        1,
-        &data->colorVertexProgram
-    );
-    if (err != SCE_OK) {
-        SDL_LogError(SDL_LOG_CATEGORY_RENDER, "create program (color vertex) failed: %d\n", err);
-        return err;
+    {
+        const SceGxmProgramParameter *paramColorPositionAttribute = sceGxmProgramFindParameterByName(colorVertexProgramGxp, "aPosition");
+
+        const SceGxmProgramParameter *paramColorColorAttribute = sceGxmProgramFindParameterByName(colorVertexProgramGxp, "aColor");
+
+        // create color vertex format
+        SceGxmVertexAttribute colorVertexAttributes[2];
+        SceGxmVertexStream colorVertexStreams[1];
+        /* x,y,z: 3 float 32 bits */
+        colorVertexAttributes[0].streamIndex = 0;
+        colorVertexAttributes[0].offset = 0;
+        colorVertexAttributes[0].format = SCE_GXM_ATTRIBUTE_FORMAT_F32;
+        colorVertexAttributes[0].componentCount = 3; // (x, y, z)
+        colorVertexAttributes[0].regIndex = sceGxmProgramParameterGetResourceIndex(paramColorPositionAttribute);
+        /* color: 4 unsigned char  = 32 bits */
+        colorVertexAttributes[1].streamIndex = 0;
+        colorVertexAttributes[1].offset = 12; // (x, y, z) * 4 = 12 bytes
+        colorVertexAttributes[1].format = SCE_GXM_ATTRIBUTE_FORMAT_U8N;
+        colorVertexAttributes[1].componentCount = 4; // (color)
+        colorVertexAttributes[1].regIndex = sceGxmProgramParameterGetResourceIndex(paramColorColorAttribute);
+        // 16 bit (short) indices
+        colorVertexStreams[0].stride = sizeof(color_vertex);
+        colorVertexStreams[0].indexSource = SCE_GXM_INDEX_SOURCE_INDEX_16BIT;
+
+        // create color shaders
+        err = sceGxmShaderPatcherCreateVertexProgram(
+            data->shaderPatcher,
+            data->colorVertexProgramId,
+            colorVertexAttributes,
+            2,
+            colorVertexStreams,
+            1,
+            &data->colorVertexProgram
+        );
+        if (err != SCE_OK) {
+            SDL_LogError(SDL_LOG_CATEGORY_RENDER, "create program (color vertex) failed: %d\n", err);
+            return err;
+        }
+
     }
 
-    const SceGxmProgramParameter *paramTexturePositionAttribute = sceGxmProgramFindParameterByName(textureVertexProgramGxp, "aPosition");
-    const SceGxmProgramParameter *paramTextureTexcoordAttribute = sceGxmProgramFindParameterByName(textureVertexProgramGxp, "aTexcoord");
-
-    // create texture vertex format
-    SceGxmVertexAttribute textureVertexAttributes[2];
-    SceGxmVertexStream textureVertexStreams[1];
-    /* x,y,z: 3 float 32 bits */
-    textureVertexAttributes[0].streamIndex = 0;
-    textureVertexAttributes[0].offset = 0;
-    textureVertexAttributes[0].format = SCE_GXM_ATTRIBUTE_FORMAT_F32;
-    textureVertexAttributes[0].componentCount = 3; // (x, y, z)
-    textureVertexAttributes[0].regIndex = sceGxmProgramParameterGetResourceIndex(paramTexturePositionAttribute);
-    /* u,v: 2 floats 32 bits */
-    textureVertexAttributes[1].streamIndex = 0;
-    textureVertexAttributes[1].offset = 12; // (x, y, z) * 4 = 12 bytes
-    textureVertexAttributes[1].format = SCE_GXM_ATTRIBUTE_FORMAT_F32;
-    textureVertexAttributes[1].componentCount = 2; // (u, v)
-    textureVertexAttributes[1].regIndex = sceGxmProgramParameterGetResourceIndex(paramTextureTexcoordAttribute);
-    // 16 bit (short) indices
-    textureVertexStreams[0].stride = sizeof(texture_vertex);
-    textureVertexStreams[0].indexSource = SCE_GXM_INDEX_SOURCE_INDEX_16BIT;
-
-    // create texture shaders
-    err = sceGxmShaderPatcherCreateVertexProgram(
-        data->shaderPatcher,
-        data->textureVertexProgramId,
-        textureVertexAttributes,
-        2,
-        textureVertexStreams,
-        1,
-        &data->textureVertexProgram
-    );
-    if (err != SCE_OK) {
-        SDL_LogError(SDL_LOG_CATEGORY_RENDER, "create program (texture vertex) failed: %d\n", err);
-        return err;
+
+    {
+        const SceGxmProgramParameter *paramTexturePositionAttribute = sceGxmProgramFindParameterByName(textureVertexProgramGxp, "aPosition");
+        const SceGxmProgramParameter *paramTextureTexcoordAttribute = sceGxmProgramFindParameterByName(textureVertexProgramGxp, "aTexcoord");
+
+        // create texture vertex format
+        SceGxmVertexAttribute textureVertexAttributes[2];
+        SceGxmVertexStream textureVertexStreams[1];
+        /* x,y,z: 3 float 32 bits */
+        textureVertexAttributes[0].streamIndex = 0;
+        textureVertexAttributes[0].offset = 0;
+        textureVertexAttributes[0].format = SCE_GXM_ATTRIBUTE_FORMAT_F32;
+        textureVertexAttributes[0].componentCount = 3; // (x, y, z)
+        textureVertexAttributes[0].regIndex = sceGxmProgramParameterGetResourceIndex(paramTexturePositionAttribute);
+        /* u,v: 2 floats 32 bits */
+        textureVertexAttributes[1].streamIndex = 0;
+        textureVertexAttributes[1].offset = 12; // (x, y, z) * 4 = 12 bytes
+        textureVertexAttributes[1].format = SCE_GXM_ATTRIBUTE_FORMAT_F32;
+        textureVertexAttributes[1].componentCount = 2; // (u, v)
+        textureVertexAttributes[1].regIndex = sceGxmProgramParameterGetResourceIndex(paramTextureTexcoordAttribute);
+        // 16 bit (short) indices
+        textureVertexStreams[0].stride = sizeof(texture_vertex);
+        textureVertexStreams[0].indexSource = SCE_GXM_INDEX_SOURCE_INDEX_16BIT;
+
+        // create texture shaders
+        err = sceGxmShaderPatcherCreateVertexProgram(
+            data->shaderPatcher,
+            data->textureVertexProgramId,
+            textureVertexAttributes,
+            2,
+            textureVertexStreams,
+            1,
+            &data->textureVertexProgram
+        );
+        if (err != SCE_OK) {
+            SDL_LogError(SDL_LOG_CATEGORY_RENDER, "create program (texture vertex) failed: %d\n", err);
+            return err;
+        }
+
     }
 
     // Create variations of the fragment program based on blending mode
@@ -849,12 +869,15 @@ gxm_init(SDL_Renderer *renderer)
     make_fragment_programs(data, &data->blendFragmentPrograms.blend_mode_mod, &blend_info_mod);
     make_fragment_programs(data, &data->blendFragmentPrograms.blend_mode_mul, &blend_info_mul);
 
-    // Default to blend blending mode
-    fragment_programs *in = &data->blendFragmentPrograms.blend_mode_blend;
+    {
+        // Default to blend blending mode
+        fragment_programs *in = &data->blendFragmentPrograms.blend_mode_blend;
+
+        data->colorFragmentProgram = in->color;
+        data->textureFragmentProgram = in->texture;
+        data->textureTintFragmentProgram = in->textureTint;
 
-    data->colorFragmentProgram = in->color;
-    data->textureFragmentProgram = in->texture;
-    data->textureTintFragmentProgram = in->textureTint;
+    }
 
     // find vertex uniforms by name and cache parameter information
     data->clearClearColorParam = (SceGxmProgramParameter *)sceGxmProgramFindParameterByName(clearFragmentProgramGxp, "uClearColor");
@@ -1019,15 +1042,18 @@ gxm_texture_get_datap(const gxm_texture *texture)
 gxm_texture *
 create_gxm_texture(VITA_GXM_RenderData *data, unsigned int w, unsigned int h, SceGxmTextureFormat format, unsigned int isRenderTarget)
 {
-    format = SCE_GXM_TEXTURE_FORMAT_A8B8G8R8;
     gxm_texture *texture = SDL_malloc(sizeof(gxm_texture));
+    const int tex_size =  ((w + 7) & ~ 7) * h * tex_format_to_bytespp(format);
+    void *texture_data;
+
+    format = SCE_GXM_TEXTURE_FORMAT_A8B8G8R8;
+
     if (!texture)
         return NULL;
 
-    const int tex_size =  ((w + 7) & ~ 7) * h * tex_format_to_bytespp(format);
 
     /* Allocate a GPU buffer for the texture */
-    void *texture_data = mem_gpu_alloc(
+    texture_data = mem_gpu_alloc(
         SCE_KERNEL_MEMBLOCK_TYPE_USER_CDRAM_RW,
         tex_size,
         SCE_GXM_TEXTURE_ALIGNMENT,
@@ -1070,6 +1096,11 @@ create_gxm_texture(VITA_GXM_RenderData *data, unsigned int w, unsigned int h, Sc
     }
 
     if (isRenderTarget) {
+        void *depthBufferData;
+        const uint32_t alignedWidth = ALIGN(w, SCE_GXM_TILE_SIZEX);
+        const uint32_t alignedHeight = ALIGN(h, SCE_GXM_TILE_SIZEY);
+        uint32_t sampleCount = alignedWidth*alignedHeight;
+        uint32_t depthStrideInSamples = alignedWidth;
 
         int err = sceGxmColorSurfaceInit(
             &texture->gxm_colorsurface,
@@ -1089,14 +1120,8 @@ create_gxm_texture(VITA_GXM_RenderData *data, unsigned int w, unsigned int h, Sc
             return NULL;
         }
 
-        // create the depth/stencil surface
-        const uint32_t alignedWidth = ALIGN(w, SCE_GXM_TILE_SIZEX);
-        const uint32_t alignedHeight = ALIGN(h, SCE_GXM_TILE_SIZEY);
-        uint32_t sampleCount = alignedWidth*alignedHeight;
-        uint32_t depthStrideInSamples = alignedWidth;
-
         // allocate it
-        void *depthBufferData = mem_gpu_alloc(
+        depthBufferData = mem_gpu_alloc(
             SCE_KERNEL_MEMBLOCK_TYPE_USER_RW_UNCACHE,
             4*sampleCount,
             SCE_GXM_DEPTHSTENCIL_SURFACE_ALIGNMENT,
@@ -1118,28 +1143,30 @@ create_gxm_texture(VITA_GXM_RenderData *data, unsigned int w, unsigned int h, Sc
             return NULL;
         }
 
-        SceGxmRenderTarget *tgt = NULL;
-
-        // set up parameters
-        SceGxmRenderTargetParams renderTargetParams;
-        memset(&renderTargetParams, 0, sizeof(SceGxmRenderTargetParams));
-        renderTargetParams.flags = 0;
-        renderTargetParams.width = w;
-        renderTargetParams.height = h;
-        renderTargetParams.scenesPerFrame = 1;
-        renderTargetParams.multisampleMode = SCE_GXM_MULTISAMPLE_NONE;
-        renderTargetParams.multisampleLocations = 0;
-        renderTargetParams.driverMemBlock = -1;
-
-        // create the render target
-        err = sceGxmCreateRenderTarget(&renderTargetParams, &tgt);
-
-        texture->gxm_rendertarget = tgt;
-
-        if (err < 0) {
-            free_gxm_texture(texture);
-            SDL_LogError(SDL_LOG_CATEGORY_RENDER, "create render target failed: %d\n", err);
-            return NULL;
+        {
+            SceGxmRenderTarget *tgt = NULL;
+
+            // set up parameters
+            SceGxmRenderTargetParams renderTargetParams;
+            memset(&renderTargetParams, 0, sizeof(SceGxmRenderTargetParams));
+            renderTargetParams.flags = 0;
+            renderTargetParams.width = w;
+            renderTargetParams.height = h;
+            renderTargetParams.scenesPerFrame = 1;
+            renderTargetParams.multisampleMode = SCE_GXM_MULTISAMPLE_NONE;
+            renderTargetParams.multisampleLocations = 0;
+            renderTargetParams.driverMemBlock = -1;
+
+            // create the render target
+            err = sceGxmCreateRenderTarget(&renderTargetParams, &tgt);
+
+            texture->gxm_rendertarget = tgt;
+
+            if (err < 0) {
+                free_gxm_texture(texture);
+                SDL_LogError(SDL_LOG_CATEGORY_RENDER, "create render target failed: %d\n", err);
+                return NULL;
+            }
         }
 
     }
diff --git a/src/sensor/vita/SDL_vitasensor.c b/src/sensor/vita/SDL_vitasensor.c
index e54d279..85f941d 100644
--- a/src/sensor/vita/SDL_vitasensor.c
+++ b/src/sensor/vita/SDL_vitasensor.c
@@ -137,10 +137,10 @@ SDL_VITA_SensorOpen(SDL_Sensor *sensor, int device_index)
 static void
 SDL_VITA_SensorUpdate(SDL_Sensor *sensor)
 {
+    int err = SCE_OK;
     SceMotionSensorState motionState[SCE_MOTION_MAX_NUM_STATES];
     SDL_memset(motionState, 0, sizeof(motionState));
 
-    int err = SCE_OK;
     err = sceMotionGetSensorState(motionState, SCE_MOTION_MAX_NUM_STATES);
     if (err != SCE_OK)
     {
diff --git a/src/timer/vita/SDL_systimer.c b/src/timer/vita/SDL_systimer.c
index 91902d9..a9009f7 100644
--- a/src/timer/vita/SDL_systimer.c
+++ b/src/timer/vita/SDL_systimer.c
@@ -20,7 +20,7 @@
 */
 #include "../../SDL_internal.h"
 
-#ifdef SDL_TIMERS_VITA
+#ifdef SDL_TIMER_VITA
 
 #include "SDL_thread.h"
 #include "SDL_timer.h"
@@ -53,13 +53,13 @@ SDL_TicksQuit(void)
 
 Uint32 SDL_GetTicks(void)
 {
+    uint64_t now;
+    Uint32 ticks;
+
     if (!ticks_started) {
         SDL_TicksInit();
     }
 
-    uint64_t now;
-    Uint32 ticks;
-
     now = sceKernelGetProcessTimeWide();
     ticks = (now - start)/1000;
     return (ticks);
@@ -85,7 +85,7 @@ void SDL_Delay(Uint32 ms)
     sceKernelDelayThreadCB(ms * 1000);
 }
 
-#endif /* SDL_TIMERS_VITA */
+#endif /* SDL_TIMER_VITA */
 
 /* vim: ts=4 sw=4
  */
diff --git a/src/video/vita/SDL_vitagl.c b/src/video/vita/SDL_vitagl.c
index c457e0f..d8ee86f 100644
--- a/src/video/vita/SDL_vitagl.c
+++ b/src/video/vita/SDL_vitagl.c
@@ -81,6 +81,11 @@ VITA_GL_CreateContext(_THIS, SDL_Window * window)
     EGLint num_configs;
     int i;
 
+    const EGLint contextAttribs[] = {
+        EGL_CONTEXT_CLIENT_VERSION, 2,
+        EGL_NONE
+    };
+
     EGLCHK(display = eglGetDisplay(0));
 
     EGLCHK(eglInitialize(display, NULL, NULL));
@@ -122,10 +127,6 @@ VITA_GL_CreateContext(_THIS, SDL_Window * window)
         return 0;
     }
 
-    const EGLint contextAttribs[] = {
-        EGL_CONTEXT_CLIENT_VERSION, 2,
-        EGL_NONE
-    };
 
     EGLCHK(surface = eglCreateWindowSurface(display, config, VITA_WINDOW_960X544, NULL));
 
diff --git a/src/video/vita/SDL_vitakeyboard.c b/src/video/vita/SDL_vitakeyboard.c
index efa407f..f196e33 100644
--- a/src/video/vita/SDL_vitakeyboard.c
+++ b/src/video/vita/SDL_vitakeyboard.c
@@ -105,70 +105,72 @@ VITA_PollKeyboard(void)
 				}
 			}
 
-			Uint8 changed_modifiers = k_reports[numReports - 1].modifiers[0] ^ prev_modifiers;
+			{
+				Uint8 changed_modifiers = k_reports[numReports - 1].modifiers[0] ^ prev_modifiers;
 
-			if (changed_modifiers & 0x01) {
-				if (prev_modifiers & 0x01) {
-					SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_LCTRL);
-				}
-				else {
-					SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_LCTRL);
-				}
-			}
-			if (changed_modifiers & 0x02) {
-				if (prev_modifiers & 0x02) {
-					SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_LSHIFT);
-				}
-				else {
-					SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_LSHIFT);
-				}
-			}
-			if (changed_modifiers & 0x04) {
-				if (prev_modifiers & 0x04) {
-					SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_LALT);
-				}
-				else {
-					SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_LALT);
-				}
-			}
-			if (changed_modifiers & 0x08) {
-				if (prev_modifiers & 0x08) {
-					SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_LGUI);
-				}
-				else {
-					SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_LGUI);
-				}
-			}
-			if (changed_modifiers & 0x10) {
-				if (prev_modifiers & 0x10) {
-					SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_RCTRL);
+				if (changed_modifiers & 0x01) {
+					if (prev_modifiers & 0x01) {
+						SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_LCTRL);
+					}
+					else {
+						SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_LCTRL);
+					}
 				}
+				if (changed_modifiers & 0x02) {
+					if (prev_modifiers & 0x02) {
+						SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_LSHIFT);
+					}
 				else {
-					SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_RCTRL);
+						SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_LSHIFT);
+					}
 				}
-			}
-			if (changed_modifiers & 0x20) {
-				if (prev_modifiers & 0x20) {
-					SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_RSHIFT);
+				if (changed_modifiers & 0x04) {
+					if (prev_modifiers & 0x04) {
+						SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_LALT);
+					}
+					else {
+						SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_LALT);
+					}
 				}
-				else {
-					SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_RSHIFT);
+				if (changed_modifiers & 0x08) {
+					if (prev_modifiers & 0x08) {
+						SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_LGUI);
+					}
+					else {
+						SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_LGUI);
+					}
 				}
+				if (changed_modifiers & 0x10) {
+					if (prev_modifiers & 0x10) {
+						SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_RCTRL);
+					}
+					else {
+						SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_RCTRL);
+					}
 			}
-			if (changed_modifiers & 0x40) {
-				if (prev_modifiers & 0x40) {
-					SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_RALT);
-				}
-				else {
-					SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_RALT);
+				if (changed_modifiers & 0x20) {
+					if (prev_modifiers & 0x20) {
+						SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_RSHIFT);
+					}
+					else {
+						SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_RSHIFT);
+					}
 				}
-			}
-			if (changed_modifiers & 0x80) {
-				if (prev_modifiers & 0x80) {
-					SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_RGUI);
+				if (changed_modifiers & 0x40) {
+					if (prev_modifiers & 0x40) {
+						SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_RALT);
+					}
+					else {
+						SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_RALT);
+					}
 				}
-				else {
-					SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_RGUI);
+				if (changed_modifiers & 0x80) {
+					if (prev_modifiers & 0x80) {
+						SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_RGUI);
+					}
+					else {
+						SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_RGUI);
+					}
 				}
 			}
 
diff --git a/src/video/vita/SDL_vitatouch.c b/src/video/vita/SDL_vitatouch.c
index 5913db5..7399618 100644
--- a/src/video/vita/SDL_vitatouch.c
+++ b/src/video/vita/SDL_vitatouch.c
@@ -77,13 +77,13 @@ VITA_QuitTouch(void){
 void 
 VITA_PollTouch(void)
 {
+	SDL_FingerID finger_id = 0;
+	int port;
+
 	// We skip polling touch if no window is created
 	if (Vita_Window == NULL)
 		return;
 
-	SDL_FingerID finger_id = 0;
-	int port;
-
 	memcpy(touch_old, touch, sizeof(touch_old));
 
 	for(port = 0; port < SCE_TOUCH_PORT_MAX_NUM; port++) {
@@ -97,8 +97,8 @@ VITA_PollTouch(void)
 				// for the back panel, the active touch area is used as reference
 				float x = 0;
 				float y = 0;
-				VITA_ConvertTouchXYToSDLXY(&x, &y, touch[port].report[i].x, touch[port].report[i].y, port);
 				float force = (touch[port].report[i].force - force_info[port].min) / force_info[port].range;
+				VITA_ConvertTouchXYToSDLXY(&x, &y, touch[port].report[i].x, touch[port].report[i].y, port);
 				finger_id = (SDL_FingerID) touch[port].report[i].id;
 
 				// Send an initial touch
@@ -134,8 +134,8 @@ VITA_PollTouch(void)
 				if (finger_up == 1) {
 					float x = 0;
 					float y = 0;
-					VITA_ConvertTouchXYToSDLXY(&x, &y, touch_old[port].report[i].x, touch_old[port].report[i].y, port);
 					float force = (touch_old[port].report[i].force - force_info[port].min) / force_info[port].range;
+					VITA_ConvertTouchXYToSDLXY(&x, &y, touch_old[port].report[i].x, touch_old[port].report[i].y, port);
 					finger_id = (SDL_FingerID) touch_old[port].report[i].id;
 					// Finger released from screen
 					SDL_SendTouch((SDL_TouchID)port,
diff --git a/src/video/vita/SDL_vitavideo.c b/src/video/vita/SDL_vitavideo.c
index e639305..8bc1ee7 100644
--- a/src/video/vita/SDL_vitavideo.c
+++ b/src/video/vita/SDL_vitavideo.c
@@ -327,6 +327,7 @@ void VITA_ShowScreenKeyboard(_THIS, SDL_Window *window)
 
     wchar_t *title = L"";
     wchar_t *text = L"";
+    SceInt32 res;
 
     SceImeDialogParam param;
     sceImeDialogParamInit(&param);
@@ -342,7 +343,7 @@ void VITA_ShowScreenKeyboard(_THIS, SDL_Window *window)
     param.initialText = text;
     param.inputTextBuffer = videodata->ime_buffer;
 
-    SceInt32 res = sceImeDialogInit(&param);
+    res = sceImeDialogInit(&param);
     if (res < 0) {
         SDL_SetError("Failed to init IME dialog");
         return;
@@ -413,14 +414,15 @@ void VITA_PumpEvents(_THIS)
         // update IME status. Terminate, if finished
         SceCommonDialogStatus dialogStatus = sceImeDialogGetStatus();
          if (dialogStatus == SCE_COMMON_DIALOG_STATUS_FINISHED) {
+            uint8_t utf8_buffer[SCE_IME_DIALOG_MAX_TEXT_LENGTH];
 
             SceImeDialogResult result;
             SDL_memset(&result, 0, sizeof(SceImeDialogResult));
             sceImeDialogGetResult(&result);
 
             // Convert UTF16 to UTF8
-            uint8_t utf8_buffer[SCE_IME_DIALOG_MAX_TEXT_LENGTH];
             utf16_to_utf8(videodata->ime_buffer, utf8_buffer);
+
             // send sdl event
             SDL_SendKeyboardText((const char*)utf8_buffer);