Fix crash that may occur when handle_reshape in called before the window is fully created.

Not sure if this affects any renderer but the tinydisplay renderer.
This commit is contained in:
rdb 2015-01-05 22:38:09 +01:00
parent 8a5f07f9c3
commit b19ff5b10e
3 changed files with 148 additions and 143 deletions

View File

@ -251,8 +251,10 @@ open_window() {
void TinyWinGraphicsWindow:: void TinyWinGraphicsWindow::
handle_reshape() { handle_reshape() {
WinGraphicsWindow::handle_reshape(); WinGraphicsWindow::handle_reshape();
ZB_resize(_frame_buffer, NULL, _properties.get_x_size(), _properties.get_y_size()); if (_frame_buffer != NULL) {
setup_bitmap_info(); ZB_resize(_frame_buffer, NULL, _properties.get_x_size(), _properties.get_y_size());
setup_bitmap_info();
}
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////

View File

@ -107,6 +107,8 @@ void
ZB_resize(ZBuffer * zb, void *frame_buffer, int xsize, int ysize) { ZB_resize(ZBuffer * zb, void *frame_buffer, int xsize, int ysize) {
int size; int size;
nassertv(zb != NULL);
/* xsize must be a multiple of 4 */ /* xsize must be a multiple of 4 */
xsize = (xsize + 3) & ~3; xsize = (xsize + 3) & ~3;

View File

@ -26,8 +26,6 @@
#include <tchar.h> #include <tchar.h>
TypeHandle WinGraphicsWindow::_type_handle; TypeHandle WinGraphicsWindow::_type_handle;
TypeHandle WinGraphicsWindow::WinWindowHandle::_type_handle; TypeHandle WinGraphicsWindow::WinWindowHandle::_type_handle;
@ -1489,7 +1487,10 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
<< "WM_SIZE: " << hwnd << ", " << wparam << "\n"; << "WM_SIZE: " << hwnd << ", " << wparam << "\n";
} }
handle_reshape(); // Resist calling handle_reshape before the window has opened.
if (_hWnd == NULL) {
handle_reshape();
}
break; break;
case WM_EXITSIZEMOVE: case WM_EXITSIZEMOVE: