Bug Summary

File:display.c
Location:line 75, column 10
Description:Called C++ object pointer is null

Annotated Source Code

1/*************************************************************** -*- c++ -*-
2 * *
3 * display.c - Actual implementation of OSD display variants and *
4 * Display:: namespace that encapsulates a single cDisplay. *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * Changelog: *
12 * 2005-03 initial version (c) Udo Richter *
13 * *
14 ***************************************************************************/
15
16#include <strings.h>
17#include <vdr/config.h>
18#include "setup.h"
19#include "display.h"
20#include "txtfont.h"
21
22// Static variables of Display:: namespace
23Display::Mode Display::mode=Display::Full;
24cDisplay *Display::display=NULL__null;
25
26
27void Display::SetMode(Display::Mode NewMode) {
28 // (re-)set display mode.
29
30 if (display!=NULL__null && NewMode==mode) return;
5
Assuming pointer value is null
31 // No change, nothing to do
32
33 // OSD origin, centered on VDR OSD
34 int x0=Setup.OSDLeft+(Setup.OSDWidth-ttSetup.OSDwidth)*ttSetup.OSDHAlign/100;
35 int y0=Setup.OSDTop +(Setup.OSDHeight-ttSetup.OSDheight)*ttSetup.OSDVAlign/100;
36
37 switch (NewMode) {
6
Control jumps to 'case HalfUpper:' at line 50
38 case Display::Full:
39 // Need to re-initialize *display:
40 Delete();
41 // Try 4BPP display first:
42 display=new cDisplay4BPP(x0,y0,ttSetup.OSDwidth,ttSetup.OSDheight);
43 if (!display->Valid()) {
44 // Failed, possibly out of memory
45 delete display;
46 // Try 2BPP display
47 display=new cDisplay2BPP(x0,y0,ttSetup.OSDwidth,ttSetup.OSDheight);
48 }
49 break;
50 case Display::HalfUpper:
51 // Shortcut to switch from HalfUpper to HalfLower:
52 if (mode==Display::HalfLower) {
7
Taking true branch
53 // keep instance.
54 ((cDisplay4BPPHalf*)display)->SetUpper(true);
55 break;
8
Execution continues on line 73
56 }
57 // Need to re-initialize *display:
58 Delete();
59 display=new cDisplay4BPPHalf(x0,y0,ttSetup.OSDwidth,ttSetup.OSDheight,true);
60 break;
61 case Display::HalfLower:
62 // Shortcut to switch from HalfUpper to HalfLower:
63 if (mode==Display::HalfUpper) {
64 // keep instance.
65 ((cDisplay4BPPHalf*)display)->SetUpper(false);
66 break;
67 }
68 // Need to re-initialize *display:
69 Delete();
70 display=new cDisplay4BPPHalf(x0,y0,ttSetup.OSDwidth,ttSetup.OSDheight,false);
71 break;
72 }
73 mode=NewMode;
74 // If display is invalid, clean up immediately:
75 if (!display->Valid()) Delete();
9
Called C++ object pointer is null
76 // Pass through OSD black transparency
77 SetBackgroundColor((tColor)ttSetup.configuredClrBackground);
78}
79
80void Display::ShowUpperHalf() {
81 // Enforce upper half of screen to be visible
82 if (GetZoom()==cDisplay::Zoom_Lower)
1
Taking false branch
83 SetZoom(cDisplay::Zoom_Upper);
84 if (mode==HalfLower)
2
Assuming 'mode' is equal to HalfLower
3
Taking true branch
85 SetMode(HalfUpper);
4
Calling 'SetMode'
86}
87
88
89
90
91
92
93cDisplay2BPP::cDisplay2BPP(int x0, int y0, int width, int height)
94 : cDisplay(width,height) {
95 // 2BPP display with color mapping
96
97 osd = cOsdProvider::NewOsd(x0, y0);
98 if (!osd) return;
99
100 width=(width+3)&~3;
101 // Width has to end on byte boundary, so round up
102
103 tArea Areas[] = { { 0, 0, width - 1, height - 1, 2 } };
104 if (osd->CanHandleAreas(Areas, sizeof(Areas) / sizeof(tArea)) != oeOk) {
105 DELETENULL(osd);
106 return;
107 }
108 osd->SetAreas(Areas, sizeof(Areas) / sizeof(tArea));
109
110 InitPalette();
111
112 InitScaler();
113
114 CleanDisplay();
115}
116
117tColor cDisplay2BPP::GetColorRGB(enumTeletextColor ttc, int Area) {
118 switch (ttc) {
119 case ttcBlack: return Background;
120 case ttcRed: return clrRed;
121 case ttcGreen: return clrYellow;
122 case ttcYellow: return clrYellow;
123 case ttcBlue: return Background;
124 case ttcMagenta: return clrRed;
125 case ttcCyan: return clrCyan;
126 case ttcWhite: return clrCyan;
127 case ttcTransparent: return Background;
128 default: return Background;
129 }
130}
131
132tColor cDisplay2BPP::GetColorRGBAlternate(enumTeletextColor ttc, int Area) {
133 switch (ttc) {
134 case ttcBlack: return clrCyan;
135 case ttcRed: return clrYellow;
136 case ttcGreen: return clrRed;
137 case ttcYellow: return clrRed;
138 case ttcBlue: return clrCyan;
139 case ttcMagenta: return clrYellow;
140 case ttcCyan: return Background;
141 case ttcWhite: return Background;
142 case ttcTransparent: return clrCyan;
143 default: return Background;
144 }
145}
146
147
148
149
150
151cDisplay4BPP::cDisplay4BPP(int x0, int y0, int width, int height)
152 : cDisplay(width,height) {
153 // 4BPP display for memory-modded DVB cards and other OSD providers
154
155 osd = cOsdProvider::NewOsd(x0, y0);
156 if (!osd) return;
157
158 width=(width+1)&~1;
159 // Width has to end on byte boundary, so round up
160
161 tArea Areas[] = { { 0, 0, width - 1, height - 1, 4 } };
162 if (osd->CanHandleAreas(Areas, sizeof(Areas) / sizeof(tArea)) != oeOk) {
163 DELETENULL(osd);
164 return;
165 }
166 osd->SetAreas(Areas, sizeof(Areas) / sizeof(tArea));
167
168 InitPalette();
169
170 InitScaler();
171
172 CleanDisplay();
173}
174
175
176cDisplay4BPPHalf::cDisplay4BPPHalf(int x0, int y0, int width, int height, bool upper)
177 : cDisplay(width,height), Upper(upper), OsdX0(x0), OsdY0(y0)
178{
179 osd=NULL__null;
180
181 // Redirect all real init work to method
182 InitOSD();
183}
184
185void cDisplay4BPPHalf::InitOSD() {
186 if (osd) delete osd;
187 osd = cOsdProvider::NewOsd(OsdX0, OsdY0);
188 if (!osd) return;
189
190 int width=(Width+1)&~1;
191 // Width has to end on byte boundary, so round up
192
193 tArea Areas[] = { { 0, 0, width - 1, Height - 1, 4 } };
194 // Try full-size area first
195
196 while (osd->CanHandleAreas(Areas, sizeof(Areas) / sizeof(tArea)) != oeOk) {
197 // Out of memory, so shrink
198 if (Upper) {
199 // Move up lower border
200 Areas[0].y2=Areas[0].y2-1;
201 } else {
202 // Move down upper border
203 Areas[0].y1=Areas[0].y1+1;
204 }
205 if (Areas[0].y1>Areas[0].y2) {
206 // Area is empty, fail miserably
207 DELETENULL(osd);
208 return;
209 }
210 }
211 // Add some backup
212 // CanHandleAreas is not accurate enough
213 if (Upper) {
214 Areas[0].y2=Areas[0].y2-10;
215 } else {
216 Areas[0].y1=Areas[0].y1+10;
217 }
218
219 osd->SetAreas(Areas, sizeof(Areas) / sizeof(tArea));
220
221 InitPalette();
222
223 InitScaler();
224
225 CleanDisplay();
226
227 // In case we switched on the fly, do a full redraw
228 Dirty=true;
229 DirtyAll=true;
230 Flush();
231}
232
233
234