Commit 7f644d03 authored by hybrid's avatar hybrid

Window size fix by Auria. For now we simply check for any error during window...

Window size fix by Auria. For now we simply check for any error during window creation and bail out safely. This avoids uncontrolled crashes of the app and may be handled by the app logic somehow.
Reordered some of the device attributes and ensured initialization of all values.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@3966 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 9d3c6302
...@@ -71,10 +71,10 @@ namespace irr ...@@ -71,10 +71,10 @@ namespace irr
//! Minimizes the window if possible //! Minimizes the window if possible
virtual void minimizeWindow(); virtual void minimizeWindow();
//! Maximizes the window if possible. //! Maximizes the window if possible.
virtual void maximizeWindow(); virtual void maximizeWindow();
//! Restore the window to normal size if possible. //! Restore the window to normal size if possible.
virtual void restoreWindow(); virtual void restoreWindow();
...@@ -225,21 +225,21 @@ namespace irr ...@@ -225,21 +225,21 @@ namespace irr
void postKeyEvent(void *event, irr::SEvent &ievent, bool pressed); void postKeyEvent(void *event, irr::SEvent &ievent, bool pressed);
void pollJoysticks(); void pollJoysticks();
NSWindow *Window; NSWindow *Window;
CGLContextObj CGLContext; CGLContextObj CGLContext;
NSOpenGLContext *OGLContext; NSOpenGLContext *OGLContext;
int DeviceWidth, NSBitmapImageRep *SoftwareDriverTarget;
DeviceHeight; std::map<int,int> KeyCodes;
std::map<int,int> KeyCodes; int DeviceWidth;
int ScreenWidth, int DeviceHeight;
ScreenHeight; int ScreenWidth;
bool IsActive; int ScreenHeight;
NSBitmapImageRep *SoftwareDriverTarget; u32 MouseButtonStates;
bool IsSoftwareRenderer, bool IsActive;
IsShiftDown, bool IsSoftwareRenderer;
IsControlDown, bool IsShiftDown;
IsResizable; bool IsControlDown;
u32 MouseButtonStates; bool IsResizable;
}; };
......
...@@ -472,12 +472,14 @@ namespace irr ...@@ -472,12 +472,14 @@ namespace irr
{ {
//! constructor //! constructor
CIrrDeviceMacOSX::CIrrDeviceMacOSX(const SIrrlichtCreationParameters& param) CIrrDeviceMacOSX::CIrrDeviceMacOSX(const SIrrlichtCreationParameters& param)
: CIrrDeviceStub(param), Window(NULL), IsActive(true), OGLContext(NULL), CGLContext(NULL), : CIrrDeviceStub(param), Window(NULL), CGLContext(NULL), OGLContext(NULL),
SoftwareDriverTarget(0), IsSoftwareRenderer(false), IsResizable(false), SoftwareDriverTarget(0), DeviceWidth(0), DeviceHeight(0),
IsShiftDown(false), IsControlDown(false), MouseButtonStates(0) ScreenWidth(0), ScreenHeight(0), MouseButtonStates(0),
IsActive(true), IsSoftwareRenderer(false),
IsShiftDown(false), IsControlDown(false), IsResizable(false)
{ {
struct utsname name; struct utsname name;
NSString *path; NSString *path;
#ifdef _DEBUG #ifdef _DEBUG
setDebugName("CIrrDeviceMacOSX"); setDebugName("CIrrDeviceMacOSX");
...@@ -506,14 +508,16 @@ CIrrDeviceMacOSX::CIrrDeviceMacOSX(const SIrrlichtCreationParameters& param) ...@@ -506,14 +508,16 @@ CIrrDeviceMacOSX::CIrrDeviceMacOSX(const SIrrlichtCreationParameters& param)
os::Printer::log(name.version,ELL_INFORMATION); os::Printer::log(name.version,ELL_INFORMATION);
initKeycodes(); initKeycodes();
bool success = true;
if (CreationParams.DriverType != video::EDT_NULL) if (CreationParams.DriverType != video::EDT_NULL)
createWindow(); success = createWindow();
// in case of failure, one can check VideoDriver for initialization
if (!success)
return;
setResizable(false); setResizable(false);
CursorControl = new CCursorControl(CreationParams.WindowSize, this); CursorControl = new CCursorControl(CreationParams.WindowSize, this);
createDriver(); createDriver();
createGUIAndScene(); createGUIAndScene();
} }
...@@ -592,171 +596,181 @@ bool CIrrDeviceMacOSX::createWindow() ...@@ -592,171 +596,181 @@ bool CIrrDeviceMacOSX::createWindow()
VideoModeList.setDesktop(CreationParams.Bits, core::dimension2d<u32>(ScreenWidth, ScreenHeight)); VideoModeList.setDesktop(CreationParams.Bits, core::dimension2d<u32>(ScreenWidth, ScreenHeight));
if (!CreationParams.Fullscreen) // we need to check where the exceptions may happen and work at them
// for now we will just catch them to be able to avoid an app exit
@try
{ {
if(!CreationParams.WindowId) //create another window when WindowId is null if (!CreationParams.Fullscreen)
{ {
Window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0,0,CreationParams.WindowSize.Width,CreationParams.WindowSize.Height) styleMask:NSTitledWindowMask+NSClosableWindowMask+NSResizableWindowMask backing:NSBackingStoreBuffered defer:FALSE]; if(!CreationParams.WindowId) //create another window when WindowId is null
}
if (Window != NULL || CreationParams.WindowId)
{
NSOpenGLPixelFormatAttribute windowattribs[] =
{
NSOpenGLPFANoRecovery,
NSOpenGLPFAAccelerated,
NSOpenGLPFADepthSize, (NSOpenGLPixelFormatAttribute)depthSize,
NSOpenGLPFAColorSize, (NSOpenGLPixelFormatAttribute)CreationParams.Bits,
NSOpenGLPFAAlphaSize, (NSOpenGLPixelFormatAttribute)alphaSize,
NSOpenGLPFASampleBuffers, (NSOpenGLPixelFormatAttribute)1,
NSOpenGLPFASamples, (NSOpenGLPixelFormatAttribute)CreationParams.AntiAlias,
NSOpenGLPFAStencilSize, (NSOpenGLPixelFormatAttribute)(CreationParams.Stencilbuffer?1:0),
NSOpenGLPFADoubleBuffer,
(NSOpenGLPixelFormatAttribute)nil
};
if (CreationParams.AntiAlias<2)
{ {
windowattribs[ 9] = (NSOpenGLPixelFormatAttribute)0; Window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0,0,CreationParams.WindowSize.Width,CreationParams.WindowSize.Height) styleMask:NSTitledWindowMask+NSClosableWindowMask+NSResizableWindowMask backing:NSBackingStoreBuffered defer:FALSE];
windowattribs[11] = (NSOpenGLPixelFormatAttribute)0;
} }
NSOpenGLPixelFormat *format; if (Window != NULL || CreationParams.WindowId)
for (int i=0; i<3; ++i)
{ {
if (1==i) NSOpenGLPixelFormatAttribute windowattribs[] =
{ {
// Second try without stencilbuffer NSOpenGLPFANoRecovery,
if (CreationParams.Stencilbuffer) NSOpenGLPFAAccelerated,
{ NSOpenGLPFADepthSize, (NSOpenGLPixelFormatAttribute)depthSize,
windowattribs[13]=(NSOpenGLPixelFormatAttribute)0; NSOpenGLPFAColorSize, (NSOpenGLPixelFormatAttribute)CreationParams.Bits,
} NSOpenGLPFAAlphaSize, (NSOpenGLPixelFormatAttribute)alphaSize,
else NSOpenGLPFASampleBuffers, (NSOpenGLPixelFormatAttribute)1,
continue; NSOpenGLPFASamples, (NSOpenGLPixelFormatAttribute)CreationParams.AntiAlias,
} NSOpenGLPFAStencilSize, (NSOpenGLPixelFormatAttribute)(CreationParams.Stencilbuffer?1:0),
else if (2==i) NSOpenGLPFADoubleBuffer,
(NSOpenGLPixelFormatAttribute)nil
};
if (CreationParams.AntiAlias<2)
{ {
// Third try without Doublebuffer windowattribs[ 9] = (NSOpenGLPixelFormatAttribute)0;
os::Printer::log("No doublebuffering available.", ELL_WARNING); windowattribs[11] = (NSOpenGLPixelFormatAttribute)0;
windowattribs[14]=(NSOpenGLPixelFormatAttribute)nil;
} }
format = [[NSOpenGLPixelFormat alloc] initWithAttributes:windowattribs]; NSOpenGLPixelFormat *format;
if (format == NULL) for (int i=0; i<3; ++i)
{ {
if (CreationParams.AntiAlias>1) if (1==i)
{ {
while (!format && windowattribs[12]>1) // Second try without stencilbuffer
if (CreationParams.Stencilbuffer)
{ {
windowattribs[12] = (NSOpenGLPixelFormatAttribute)((int)windowattribs[12]-1); windowattribs[13]=(NSOpenGLPixelFormatAttribute)0;
format = [[NSOpenGLPixelFormat alloc] initWithAttributes:windowattribs];
} }
else
continue;
}
else if (2==i)
{
// Third try without Doublebuffer
os::Printer::log("No doublebuffering available.", ELL_WARNING);
windowattribs[14]=(NSOpenGLPixelFormatAttribute)nil;
}
if (!format) format = [[NSOpenGLPixelFormat alloc] initWithAttributes:windowattribs];
if (format == NULL)
{
if (CreationParams.AntiAlias>1)
{ {
windowattribs[9] = (NSOpenGLPixelFormatAttribute)0; while (!format && windowattribs[12]>1)
windowattribs[11] = (NSOpenGLPixelFormatAttribute)0;
format = [[NSOpenGLPixelFormat alloc] initWithAttributes:windowattribs];
if (!format)
{ {
// reset values for next try windowattribs[12] = (NSOpenGLPixelFormatAttribute)((int)windowattribs[12]-1);
windowattribs[9] = (NSOpenGLPixelFormatAttribute)1; format = [[NSOpenGLPixelFormat alloc] initWithAttributes:windowattribs];
windowattribs[11] = (NSOpenGLPixelFormatAttribute)CreationParams.AntiAlias;
} }
else
if (!format)
{ {
os::Printer::log("No FSAA available.", ELL_WARNING); windowattribs[9] = (NSOpenGLPixelFormatAttribute)0;
} windowattribs[11] = (NSOpenGLPixelFormatAttribute)0;
format = [[NSOpenGLPixelFormat alloc] initWithAttributes:windowattribs];
if (!format)
{
// reset values for next try
windowattribs[9] = (NSOpenGLPixelFormatAttribute)1;
windowattribs[11] = (NSOpenGLPixelFormatAttribute)CreationParams.AntiAlias;
}
else
{
os::Printer::log("No FSAA available.", ELL_WARNING);
}
}
} }
} }
else
break;
} }
else CreationParams.AntiAlias = windowattribs[11];
break; CreationParams.Stencilbuffer=(windowattribs[13]==1);
}
CreationParams.AntiAlias = windowattribs[11];
CreationParams.Stencilbuffer=(windowattribs[13]==1);
if (format != NULL) if (format != NULL)
{
OGLContext = [[NSOpenGLContext alloc] initWithFormat:format shareContext:NULL];
[format release];
}
if (OGLContext != NULL)
{
if (!CreationParams.WindowId)
{ {
[Window center]; OGLContext = [[NSOpenGLContext alloc] initWithFormat:format shareContext:NULL];
[Window setDelegate:[NSApp delegate]]; [format release];
[OGLContext setView:[Window contentView]];
[Window setAcceptsMouseMovedEvents:TRUE];
[Window setIsVisible:TRUE];
[Window makeKeyAndOrderFront:nil];
} }
else //use another window for drawing
[OGLContext setView:(NSView*)CreationParams.WindowId];
CGLContext = (CGLContextObj) [OGLContext CGLContextObj]; if (OGLContext != NULL)
DeviceWidth = CreationParams.WindowSize.Width; {
DeviceHeight = CreationParams.WindowSize.Height; if (!CreationParams.WindowId)
result = true; {
[Window center];
[Window setDelegate:[NSApp delegate]];
[OGLContext setView:[Window contentView]];
[Window setAcceptsMouseMovedEvents:TRUE];
[Window setIsVisible:TRUE];
[Window makeKeyAndOrderFront:nil];
}
else //use another window for drawing
[OGLContext setView:(NSView*)CreationParams.WindowId];
CGLContext = (CGLContextObj) [OGLContext CGLContextObj];
DeviceWidth = CreationParams.WindowSize.Width;
DeviceHeight = CreationParams.WindowSize.Height;
result = true;
}
} }
} }
} else
else
{
displaymode = CGDisplayBestModeForParameters(display,CreationParams.Bits,CreationParams.WindowSize.Width,CreationParams.WindowSize.Height,NULL);
if (displaymode != NULL)
{ {
olddisplaymode = CGDisplayCurrentMode(display); displaymode = CGDisplayBestModeForParameters(display,CreationParams.Bits,CreationParams.WindowSize.Width,CreationParams.WindowSize.Height,NULL);
error = CGCaptureAllDisplays(); if (displaymode != NULL)
if (error == CGDisplayNoErr)
{ {
error = CGDisplaySwitchToMode(display,displaymode); olddisplaymode = CGDisplayCurrentMode(display);
error = CGCaptureAllDisplays();
if (error == CGDisplayNoErr) if (error == CGDisplayNoErr)
{ {
CGLPixelFormatAttribute fullattribs[] = error = CGDisplaySwitchToMode(display,displaymode);
{ if (error == CGDisplayNoErr)
kCGLPFAFullScreen,
kCGLPFADisplayMask, (CGLPixelFormatAttribute)CGDisplayIDToOpenGLDisplayMask(display),
kCGLPFADoubleBuffer,
kCGLPFANoRecovery,
kCGLPFAAccelerated,
kCGLPFADepthSize, (CGLPixelFormatAttribute)depthSize,
kCGLPFAColorSize, (CGLPixelFormatAttribute)CreationParams.Bits,
kCGLPFAAlphaSize, (CGLPixelFormatAttribute)alphaSize,
kCGLPFASampleBuffers, (CGLPixelFormatAttribute)(CreationParams.AntiAlias?1:0),
kCGLPFASamples, (CGLPixelFormatAttribute)CreationParams.AntiAlias,
kCGLPFAStencilSize, (CGLPixelFormatAttribute)(CreationParams.Stencilbuffer?1:0),
(CGLPixelFormatAttribute)NULL
};
pixelFormat = NULL;
numPixelFormats = 0;
CGLChoosePixelFormat(fullattribs,&pixelFormat,&numPixelFormats);
if (pixelFormat != NULL)
{ {
CGLCreateContext(pixelFormat,NULL,&CGLContext); CGLPixelFormatAttribute fullattribs[] =
CGLDestroyPixelFormat(pixelFormat); {
} kCGLPFAFullScreen,
kCGLPFADisplayMask, (CGLPixelFormatAttribute)CGDisplayIDToOpenGLDisplayMask(display),
kCGLPFADoubleBuffer,
kCGLPFANoRecovery,
kCGLPFAAccelerated,
kCGLPFADepthSize, (CGLPixelFormatAttribute)depthSize,
kCGLPFAColorSize, (CGLPixelFormatAttribute)CreationParams.Bits,
kCGLPFAAlphaSize, (CGLPixelFormatAttribute)alphaSize,
kCGLPFASampleBuffers, (CGLPixelFormatAttribute)(CreationParams.AntiAlias?1:0),
kCGLPFASamples, (CGLPixelFormatAttribute)CreationParams.AntiAlias,
kCGLPFAStencilSize, (CGLPixelFormatAttribute)(CreationParams.Stencilbuffer?1:0),
(CGLPixelFormatAttribute)NULL
};
pixelFormat = NULL;
numPixelFormats = 0;
CGLChoosePixelFormat(fullattribs,&pixelFormat,&numPixelFormats);
if (pixelFormat != NULL)
{
CGLCreateContext(pixelFormat,NULL,&CGLContext);
CGLDestroyPixelFormat(pixelFormat);
}
if (CGLContext != NULL) if (CGLContext != NULL)
{ {
CGLSetFullScreen(CGLContext); CGLSetFullScreen(CGLContext);
displayRect = CGDisplayBounds(display); displayRect = CGDisplayBounds(display);
ScreenWidth = DeviceWidth = (int)displayRect.size.width; ScreenWidth = DeviceWidth = (int)displayRect.size.width;
ScreenHeight = DeviceHeight = (int)displayRect.size.height; ScreenHeight = DeviceHeight = (int)displayRect.size.height;
CreationParams.WindowSize.set(ScreenWidth, ScreenHeight); CreationParams.WindowSize.set(ScreenWidth, ScreenHeight);
result = true; result = true;
}
} }
if (!result)
CGReleaseAllDisplays();
} }
if (!result)
CGReleaseAllDisplays();
} }
} }
} }
@catch (NSException *exception)
{
// FIXME: cleanup may be needed here
result = false;
}
if (result) if (result)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment