Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 15.48 KB | None | 0 0
  1. Index: source/Irrlicht/Irrlicht.cpp
  2. ===================================================================
  3. --- source/Irrlicht/Irrlicht.cpp    (revision 3409)
  4. +++ source/Irrlicht/Irrlicht.cpp    (working copy)
  5. @@ -3,6 +3,7 @@
  6.  // For conditions of distribution and use, see copyright notice in irrlicht.h
  7.  
  8.  #include "IrrCompileConfig.h"
  9. +#include <stdexcept>
  10.  
  11.  static const char* const copyright = "Irrlicht Engine (c) 2002-2009 Nikolaus Gebhardt";
  12.  
  13. @@ -74,7 +75,16 @@
  14.  
  15.  #ifdef _IRR_COMPILE_WITH_OSX_DEVICE_
  16.         if (params.DeviceType == EIDT_OSX || (!dev && params.DeviceType == EIDT_BEST))
  17. -           dev = new CIrrDeviceMacOSX(params);
  18. +        {
  19. +            try
  20. +            {
  21. +                dev = new CIrrDeviceMacOSX(params);
  22. +            }
  23. +            catch (std::runtime_error& e)
  24. +            {
  25. +                return NULL;
  26. +            }
  27. +        }
  28.  #endif
  29.  
  30.  #ifdef _IRR_COMPILE_WITH_WINDOWS_CE_DEVICE_
  31. Index: source/Irrlicht/MacOSX/CIrrDeviceMacOSX.mm
  32. ===================================================================
  33. --- source/Irrlicht/MacOSX/CIrrDeviceMacOSX.mm  (revision 3409)
  34. +++ source/Irrlicht/MacOSX/CIrrDeviceMacOSX.mm  (working copy)
  35. @@ -9,6 +9,7 @@
  36.  #import <Cocoa/Cocoa.h>
  37.  #import <OpenGL/gl.h>
  38.  #import <Carbon/Carbon.h>
  39. +#include <stdexcept>
  40.  
  41.  #include "CIrrDeviceMacOSX.h"
  42.  #include "IEventReceiver.h"
  43. @@ -370,7 +371,13 @@
  44.  
  45.     initKeycodes();
  46.     if (CreationParams.DriverType != video::EDT_NULL)
  47. -       createWindow();
  48. +    {
  49. +       const bool success = createWindow();
  50. +        if (!success)
  51. +        {
  52. +            throw std::runtime_error("Cannot create video device");
  53. +        }
  54. +    }
  55.  
  56.     setResizable(false);
  57.  
  58. @@ -458,171 +465,180 @@
  59.  
  60.     VideoModeList.setDesktop(CreationParams.Bits, core::dimension2d<u32>(ScreenWidth, ScreenHeight));
  61.  
  62. -   if (!CreationParams.Fullscreen)
  63. -   {
  64. -       if(!CreationParams.WindowId) //create another window when WindowId is null
  65. -       {
  66. -           Window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0,0,CreationParams.WindowSize.Width,CreationParams.WindowSize.Height) styleMask:NSTitledWindowMask+NSClosableWindowMask+NSResizableWindowMask backing:NSBackingStoreBuffered defer:FALSE];
  67. -       }
  68. +    @try
  69. +    {
  70. +        if (!CreationParams.Fullscreen)
  71. +        {
  72. +            if(!CreationParams.WindowId) //create another window when WindowId is null
  73. +            {
  74. +                Window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0,0,CreationParams.WindowSize.Width,CreationParams.WindowSize.Height) styleMask:NSTitledWindowMask+NSClosableWindowMask+NSResizableWindowMask backing:NSBackingStoreBuffered defer:FALSE];
  75. +            }
  76.  
  77. -       if (Window != NULL || CreationParams.WindowId)
  78. -       {
  79. -           NSOpenGLPixelFormatAttribute windowattribs[] =
  80. -           {
  81. -                   NSOpenGLPFANoRecovery,
  82. -                   NSOpenGLPFAAccelerated,
  83. -                   NSOpenGLPFADepthSize,     (NSOpenGLPixelFormatAttribute)depthSize,
  84. -                   NSOpenGLPFAColorSize,     (NSOpenGLPixelFormatAttribute)CreationParams.Bits,
  85. -                   NSOpenGLPFAAlphaSize,     (NSOpenGLPixelFormatAttribute)alphaSize,
  86. -                   NSOpenGLPFASampleBuffers, (NSOpenGLPixelFormatAttribute)1,
  87. -                   NSOpenGLPFASamples,       (NSOpenGLPixelFormatAttribute)CreationParams.AntiAlias,
  88. -                   NSOpenGLPFAStencilSize,   (NSOpenGLPixelFormatAttribute)(CreationParams.Stencilbuffer?1:0),
  89. -                   NSOpenGLPFADoubleBuffer,
  90. -                   (NSOpenGLPixelFormatAttribute)nil
  91. -           };
  92. +            if (Window != NULL || CreationParams.WindowId)
  93. +            {
  94. +                NSOpenGLPixelFormatAttribute windowattribs[] =
  95. +                {
  96. +                        NSOpenGLPFANoRecovery,
  97. +                        NSOpenGLPFAAccelerated,
  98. +                        NSOpenGLPFADepthSize,     (NSOpenGLPixelFormatAttribute)depthSize,
  99. +                        NSOpenGLPFAColorSize,     (NSOpenGLPixelFormatAttribute)CreationParams.Bits,
  100. +                        NSOpenGLPFAAlphaSize,     (NSOpenGLPixelFormatAttribute)alphaSize,
  101. +                        NSOpenGLPFASampleBuffers, (NSOpenGLPixelFormatAttribute)1,
  102. +                        NSOpenGLPFASamples,       (NSOpenGLPixelFormatAttribute)CreationParams.AntiAlias,
  103. +                        NSOpenGLPFAStencilSize,   (NSOpenGLPixelFormatAttribute)(CreationParams.Stencilbuffer?1:0),
  104. +                        NSOpenGLPFADoubleBuffer,
  105. +                        (NSOpenGLPixelFormatAttribute)nil
  106. +                };
  107.  
  108. -           if (CreationParams.AntiAlias<2)
  109. -           {
  110. -               windowattribs[ 9] = (NSOpenGLPixelFormatAttribute)0;
  111. -               windowattribs[11] = (NSOpenGLPixelFormatAttribute)0;
  112. -           }
  113. +                if (CreationParams.AntiAlias<2)
  114. +                {
  115. +                    windowattribs[ 9] = (NSOpenGLPixelFormatAttribute)0;
  116. +                    windowattribs[11] = (NSOpenGLPixelFormatAttribute)0;
  117. +                }
  118.  
  119. -           NSOpenGLPixelFormat *format;
  120. -           for (int i=0; i<3; ++i)
  121. -           {
  122. -               if (1==i)
  123. -               {
  124. -                   // Second try without stencilbuffer
  125. -                   if (CreationParams.Stencilbuffer)
  126. -                   {
  127. -                       windowattribs[13]=(NSOpenGLPixelFormatAttribute)0;
  128. -                   }
  129. -                   else
  130. -                       continue;
  131. -               }
  132. -               else if (2==i)
  133. -               {
  134. -                   // Third try without Doublebuffer
  135. -                   os::Printer::log("No doublebuffering available.", ELL_WARNING);
  136. -                   windowattribs[14]=(NSOpenGLPixelFormatAttribute)nil;
  137. -               }
  138. +                NSOpenGLPixelFormat *format;
  139. +                for (int i=0; i<3; ++i)
  140. +                {
  141. +                    if (1==i)
  142. +                    {
  143. +                        // Second try without stencilbuffer
  144. +                        if (CreationParams.Stencilbuffer)
  145. +                        {
  146. +                            windowattribs[13]=(NSOpenGLPixelFormatAttribute)0;
  147. +                        }
  148. +                        else
  149. +                            continue;
  150. +                    }
  151. +                    else if (2==i)
  152. +                    {
  153. +                        // Third try without Doublebuffer
  154. +                        os::Printer::log("No doublebuffering available.", ELL_WARNING);
  155. +                        windowattribs[14]=(NSOpenGLPixelFormatAttribute)nil;
  156. +                    }
  157.  
  158. -               format = [[NSOpenGLPixelFormat alloc] initWithAttributes:windowattribs];
  159. -               if (format == NULL)
  160. -               {
  161. -                   if (CreationParams.AntiAlias>1)
  162. -                   {
  163. -                       while (!format && windowattribs[12]>1)
  164. -                       {
  165. -                           windowattribs[12] = (NSOpenGLPixelFormatAttribute)((int)windowattribs[12]-1);
  166. -                           format = [[NSOpenGLPixelFormat alloc] initWithAttributes:windowattribs];
  167. -                       }
  168. +                    format = [[NSOpenGLPixelFormat alloc] initWithAttributes:windowattribs];
  169. +                    if (format == NULL)
  170. +                    {
  171. +                        if (CreationParams.AntiAlias>1)
  172. +                        {
  173. +                            while (!format && windowattribs[12]>1)
  174. +                            {
  175. +                                windowattribs[12] = (NSOpenGLPixelFormatAttribute)((int)windowattribs[12]-1);
  176. +                                format = [[NSOpenGLPixelFormat alloc] initWithAttributes:windowattribs];
  177. +                            }
  178.  
  179. -                       if (!format)
  180. -                       {
  181. -                           windowattribs[9] = (NSOpenGLPixelFormatAttribute)0;
  182. -                           windowattribs[11] = (NSOpenGLPixelFormatAttribute)0;
  183. -                           format = [[NSOpenGLPixelFormat alloc] initWithAttributes:windowattribs];
  184. -                           if (!format)
  185. -                           {
  186. -                               // reset values for next try
  187. -                               windowattribs[9] = (NSOpenGLPixelFormatAttribute)1;
  188. -                               windowattribs[11] = (NSOpenGLPixelFormatAttribute)CreationParams.AntiAlias;
  189. -                           }
  190. -                           else
  191. -                           {
  192. -                               os::Printer::log("No FSAA available.", ELL_WARNING);
  193. -                           }
  194. +                            if (!format)
  195. +                            {
  196. +                                windowattribs[9] = (NSOpenGLPixelFormatAttribute)0;
  197. +                                windowattribs[11] = (NSOpenGLPixelFormatAttribute)0;
  198. +                                format = [[NSOpenGLPixelFormat alloc] initWithAttributes:windowattribs];
  199. +                                if (!format)
  200. +                                {
  201. +                                    // reset values for next try
  202. +                                    windowattribs[9] = (NSOpenGLPixelFormatAttribute)1;
  203. +                                    windowattribs[11] = (NSOpenGLPixelFormatAttribute)CreationParams.AntiAlias;
  204. +                                }
  205. +                                else
  206. +                                {
  207. +                                    os::Printer::log("No FSAA available.", ELL_WARNING);
  208. +                                }
  209.  
  210. -                       }
  211. -                   }
  212. -               }
  213. -               else
  214. -                   break;
  215. -           }
  216. -           CreationParams.AntiAlias = windowattribs[11];
  217. -           CreationParams.Stencilbuffer=(windowattribs[13]==1);
  218. +                            }
  219. +                        }
  220. +                    }
  221. +                    else
  222. +                        break;
  223. +                }
  224. +                CreationParams.AntiAlias = windowattribs[11];
  225. +                CreationParams.Stencilbuffer=(windowattribs[13]==1);
  226.  
  227. -           if (format != NULL)
  228. -           {
  229. -               OGLContext = [[NSOpenGLContext alloc] initWithFormat:format shareContext:NULL];
  230. -               [format release];
  231. -           }
  232. +                if (format != NULL)
  233. +                {
  234. +                    OGLContext = [[NSOpenGLContext alloc] initWithFormat:format shareContext:NULL];
  235. +                    [format release];
  236. +                }
  237.  
  238. -           if (OGLContext != NULL)
  239. -           {
  240. -               if (!CreationParams.WindowId)
  241. -               {
  242. -                   [Window center];
  243. -                   [Window setDelegate:[NSApp delegate]];
  244. -                   [OGLContext setView:[Window contentView]];
  245. -                   [Window setAcceptsMouseMovedEvents:TRUE];
  246. -                   [Window setIsVisible:TRUE];
  247. -                   [Window makeKeyAndOrderFront:nil];
  248. -               }
  249. -               else //use another window for drawing
  250. -                   [OGLContext setView:(NSView*)CreationParams.WindowId];
  251. +                if (OGLContext != NULL)
  252. +                {
  253. +                    if (!CreationParams.WindowId)
  254. +                    {
  255. +                        [Window center];
  256. +                        [Window setDelegate:[NSApp delegate]];
  257. +                        [OGLContext setView:[Window contentView]];
  258. +                        [Window setAcceptsMouseMovedEvents:TRUE];
  259. +                        [Window setIsVisible:TRUE];
  260. +                        [Window makeKeyAndOrderFront:nil];
  261. +                    }
  262. +                    else //use another window for drawing
  263. +                        [OGLContext setView:(NSView*)CreationParams.WindowId];
  264.  
  265. -               CGLContext = (CGLContextObj) [OGLContext CGLContextObj];
  266. -               DeviceWidth = CreationParams.WindowSize.Width;
  267. -               DeviceHeight = CreationParams.WindowSize.Height;
  268. -               result = true;
  269. -           }
  270. -       }
  271. -   }
  272. -   else
  273. -   {
  274. -       displaymode = CGDisplayBestModeForParameters(display,CreationParams.Bits,CreationParams.WindowSize.Width,CreationParams.WindowSize.Height,NULL);
  275. -       if (displaymode != NULL)
  276. -       {
  277. -           olddisplaymode = CGDisplayCurrentMode(display);
  278. -           error = CGCaptureAllDisplays();
  279. -           if (error == CGDisplayNoErr)
  280. -           {
  281. -               error = CGDisplaySwitchToMode(display,displaymode);
  282. -               if (error == CGDisplayNoErr)
  283. -               {
  284. -                   pixelFormat = NULL;
  285. -                   numPixelFormats = 0;
  286. +                    CGLContext = (CGLContextObj) [OGLContext CGLContextObj];
  287. +                    DeviceWidth = CreationParams.WindowSize.Width;
  288. +                    DeviceHeight = CreationParams.WindowSize.Height;
  289. +                    result = true;
  290. +                }
  291. +            }
  292. +        }
  293. +        else
  294. +        {
  295. +            displaymode = CGDisplayBestModeForParameters(display,CreationParams.Bits,CreationParams.WindowSize.Width,CreationParams.WindowSize.Height,NULL);
  296. +            if (displaymode != NULL)
  297. +            {
  298. +                olddisplaymode = CGDisplayCurrentMode(display);
  299. +                error = CGCaptureAllDisplays();
  300. +                if (error == CGDisplayNoErr)
  301. +                {
  302. +                    error = CGDisplaySwitchToMode(display,displaymode);
  303. +                    if (error == CGDisplayNoErr)
  304. +                    {
  305. +                        pixelFormat = NULL;
  306. +                        numPixelFormats = 0;
  307.  
  308. -                   int index = 0;
  309. -                   CGLPixelFormatAttribute fullattribs[] =
  310. -                   {
  311. -                       kCGLPFAFullScreen,
  312. -                       kCGLPFADisplayMask, (CGLPixelFormatAttribute)CGDisplayIDToOpenGLDisplayMask(display),
  313. -                       kCGLPFADoubleBuffer,
  314. -                       kCGLPFAAccelerated,
  315. -                       kCGLPFADepthSize, (CGLPixelFormatAttribute)depthSize,
  316. -                       kCGLPFAColorSize, (CGLPixelFormatAttribute)CreationParams.Bits,
  317. -                       kCGLPFAAlphaSize, (CGLPixelFormatAttribute)alphaSize,
  318. -                       kCGLPFASampleBuffers, (CGLPixelFormatAttribute)(CreationParams.AntiAlias?1:0),
  319. -                       kCGLPFASamples, (CGLPixelFormatAttribute)CreationParams.AntiAlias,
  320. -                       kCGLPFAStencilSize, (CGLPixelFormatAttribute)(CreationParams.Stencilbuffer?1:0),
  321. -                       (CGLPixelFormatAttribute)NULL
  322. -                   };
  323. +                        int index = 0;
  324. +                        CGLPixelFormatAttribute    fullattribs[] =
  325. +                        {
  326. +                            kCGLPFAFullScreen,
  327. +                            kCGLPFADisplayMask, (CGLPixelFormatAttribute)CGDisplayIDToOpenGLDisplayMask(display),
  328. +                            kCGLPFADoubleBuffer,
  329. +                            kCGLPFAAccelerated,
  330. +                            kCGLPFADepthSize, (CGLPixelFormatAttribute)depthSize,
  331. +                            kCGLPFAColorSize, (CGLPixelFormatAttribute)CreationParams.Bits,
  332. +                            kCGLPFAAlphaSize, (CGLPixelFormatAttribute)alphaSize,
  333. +                            kCGLPFASampleBuffers, (CGLPixelFormatAttribute)(CreationParams.AntiAlias?1:0),
  334. +                            kCGLPFASamples, (CGLPixelFormatAttribute)CreationParams.AntiAlias,
  335. +                            kCGLPFAStencilSize, (CGLPixelFormatAttribute)(CreationParams.Stencilbuffer?1:0),
  336. +                            (CGLPixelFormatAttribute)NULL
  337. +                        };
  338.  
  339. -                   CGLChoosePixelFormat(fullattribs,&pixelFormat,&numPixelFormats);
  340. +                        CGLChoosePixelFormat(fullattribs,&pixelFormat,&numPixelFormats);
  341.  
  342. -                   if (pixelFormat != NULL)
  343. -                   {
  344. -                       CGLCreateContext(pixelFormat,NULL,&CGLContext);
  345. -                       CGLDestroyPixelFormat(pixelFormat);
  346. -                   }
  347. +                        if (pixelFormat != NULL)
  348. +                        {
  349. +                            CGLCreateContext(pixelFormat,NULL,&CGLContext);
  350. +                            CGLDestroyPixelFormat(pixelFormat);
  351. +                        }
  352.  
  353. -                   if (CGLContext != NULL)
  354. -                   {
  355. -                       CGLSetFullScreen(CGLContext);
  356. -                       displayRect = CGDisplayBounds(display);
  357. -                       ScreenWidth = DeviceWidth = (int)displayRect.size.width;
  358. -                       ScreenHeight = DeviceHeight = (int)displayRect.size.height;
  359. -                       CreationParams.WindowSize.set(ScreenWidth, ScreenHeight);
  360. -                       result = true;
  361. -                   }
  362. -               }
  363. -           }
  364. -       }
  365. -   }
  366. +                        if (CGLContext != NULL)
  367. +                        {
  368. +                            CGLSetFullScreen(CGLContext);
  369. +                            displayRect = CGDisplayBounds(display);
  370. +                            ScreenWidth = DeviceWidth = (int)displayRect.size.width;
  371. +                            ScreenHeight = DeviceHeight = (int)displayRect.size.height;
  372. +                            CreationParams.WindowSize.set(ScreenWidth, ScreenHeight);
  373. +                            result = true;
  374. +                        }
  375. +                    }
  376. +                }
  377. +            }
  378. +        }
  379.  
  380. +    }
  381. +    @catch (NSException *exception)
  382. +    {
  383. +        // FIXME: cleanup may be needed here
  384. +        return false;
  385. +    }
  386. +    
  387.     if (result)
  388.     {
  389.         // fullscreen?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement