Fix window showing garbage when resizing on 64 bit macOS (Thanks popdymc, fixes #957). Also change .vcxproj so that you show no longer need to change SDK version/platform toolset when compiling on a platform that isn't Windows 7 + VS 2015

The issue happened because
a) when resizing the window, cocoa runs in the blocking resizing window event loop (i.e. effectively pauses/suspends the launcher's event loop)
b) due to recent changes to the launcher content drawing until absolutely necessary, the contents would only get redrawn when LBackend_Tick was called

However because of a), this meant that although resize events were delivered to the game which hence reallocated the framebuffer, the framebuffer did not actually get drawn to because LBackend_Tick never got called - hence why garbage appeared on screen
This commit is contained in:
UnknownShadow200 2022-06-30 17:14:45 +10:00
parent d3d31a874c
commit 17740f8664
11 changed files with 33 additions and 22 deletions

View File

@ -22,32 +22,32 @@
<ProjectGuid>{8A7D82BD-178A-4785-B41B-70EDE998920A}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>ClassiCube</RootNamespace>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion>$(SDKVersion)</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
<PlatformToolset>$(DefaultPlatformToolset)</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
<PlatformToolset>$(DefaultPlatformToolset)</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<PlatformToolset>$(DefaultPlatformToolset)</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<PlatformToolset>$(DefaultPlatformToolset)</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>

View File

@ -87,7 +87,7 @@ void Event_UnregisterAll(void) {
ChatEvents.ChatSending.Count = 0;
ChatEvents.ColCodeChanged.Count = 0;
WindowEvents.Redraw.Count = 0;
WindowEvents.RedrawNeeded.Count = 0;
WindowEvents.Resized.Count = 0;
WindowEvents.Closing.Count = 0;
WindowEvents.FocusChanged.Count = 0;

View File

@ -108,7 +108,8 @@ void Event_UnregisterAll(void);
/* NOTE: Event_UnregisterAll MUST be updated when events lists are changed */
/* Event API version supported by the client */
/* Version 1 - Added NetEvents.PluginMessageReceived, */
/* Version 1 - Added NetEvents.PluginMessageReceived */
/* Version 2 - Added WindowEvents.Redrawing */
/* You MUST CHECK the event API version before attempting to use the events listed above, */
/* as otherwise if the player is using an older client that lacks some of the above events, */
/* you will be calling Event_Register on random data instead of the expected EventsList struct */
@ -166,13 +167,14 @@ CC_VAR extern struct _ChatEventsList {
} ChatEvents;
CC_VAR extern struct _WindowEventsList {
struct Event_Void Redraw; /* Window contents invalidated, should be redrawn */
struct Event_Void RedrawNeeded; /* Window contents invalidated and will need to be redrawn */
struct Event_Void Resized; /* Window is resized */
struct Event_Void Closing; /* Window is about to close (should free resources/save state/etc here) */
struct Event_Void FocusChanged; /* Focus of the window changed */
struct Event_Void StateChanged; /* State of the window changed (e.g. minimised, fullscreen) */
struct Event_Void Created; /* Window has been created, Window_Handle is valid now. */
struct Event_Void InactiveChanged; /* Inactive/background state of the window changed */
struct Event_Void Redrawing; /* Window contents should be redrawn (as they are about to be displayed) */
} WindowEvents;
CC_VAR extern struct _InputEventsList {

View File

@ -245,13 +245,7 @@ static CC_NOINLINE void RedrawDirty(void) {
MarkAllDirty();
}
void LBackend_Redraw(void) {
pendingRedraw = REDRAW_ALL;
MarkAllDirty();
}
void LBackend_ThemeChanged(void) { LBackend_Redraw(); }
void LBackend_Tick(void) {
static CC_NOINLINE void DoRedraw(void) {
if (pendingRedraw & REDRAW_ALL) {
RedrawAll();
pendingRedraw = 0;
@ -259,8 +253,18 @@ void LBackend_Tick(void) {
RedrawDirty();
pendingRedraw = 0;
}
}
void LBackend_Redraw(void) {
pendingRedraw = REDRAW_ALL;
MarkAllDirty();
}
void LBackend_ThemeChanged(void) { LBackend_Redraw(); }
void LBackend_Tick(void) {
DoRedraw();
if (!dirty_rect.Width) return;
Window_DrawFramebuffer(dirty_rect);
dirty_rect.X = 0; dirty_rect.Width = 0;
dirty_rect.Y = 0; dirty_rect.Height = 0;
@ -270,7 +274,8 @@ void LBackend_Tick(void) {
/*########################################################################################################################*
*-----------------------------------------------------Event handling------------------------------------------------------*
*#########################################################################################################################*/
static void ReqeustRedraw(void* obj) { LBackend_Redraw(); }
static void ReqeustRedraw(void* obj) { LBackend_Redraw(); }
static void RedrawContents(void* obj) { DoRedraw(); }
CC_NOINLINE static struct LWidget* GetWidgetAt(struct LScreen* s, int idx) {
struct LWidget* w;
@ -361,13 +366,15 @@ static void OnTextChanged(void* obj, const cc_string* str) {
}
static void HookEvents(void) {
Event_Register_(&WindowEvents.Redraw, NULL, ReqeustRedraw);
Event_Register_(&PointerEvents.Down, NULL, OnPointerDown);
Event_Register_(&PointerEvents.Up, NULL, OnPointerUp);
Event_Register_(&PointerEvents.Moved, NULL, OnPointerMove);
Event_Register_(&InputEvents.Press, NULL, OnKeyPress);
Event_Register_(&InputEvents.TextChanged, NULL, OnTextChanged);
Event_Register_(&WindowEvents.RedrawNeeded, NULL, ReqeustRedraw);
Event_Register_(&WindowEvents.Redrawing, NULL, RedrawContents);
}

View File

@ -154,7 +154,7 @@ static void JNICALL java_processSurfaceResized(JNIEnv* env, jobject o, jobject s
static void JNICALL java_processSurfaceRedrawNeeded(JNIEnv* env, jobject o) {
Platform_LogConst("WIN - REDRAW");
Event_RaiseVoid(&WindowEvents.Redraw);
Event_RaiseVoid(&WindowEvents.RedrawNeeded);
}
static void JNICALL java_onStart(JNIEnv* env, jobject o) {

View File

@ -237,7 +237,7 @@ static OSStatus Window_ProcessWindowEvent(EventRef inEvent) {
return eventNotHandledErr;
case kEventWindowDrawContent:
Event_RaiseVoid(&WindowEvents.Redraw);
Event_RaiseVoid(&WindowEvents.RedrawNeeded);
return eventNotHandledErr;
}
return eventNotHandledErr;

View File

@ -197,7 +197,7 @@ static void OnTextEvent(const SDL_Event* e) {
static void OnWindowEvent(const SDL_Event* e) {
switch (e->window.event) {
case SDL_WINDOWEVENT_EXPOSED:
Event_RaiseVoid(&WindowEvents.Redraw);
Event_RaiseVoid(&WindowEvents.RedrawNeeded);
break;
case SDL_WINDOWEVENT_SIZE_CHANGED:
RefreshWindowBounds();

View File

@ -119,7 +119,7 @@ static LRESULT CALLBACK Window_Procedure(HWND handle, UINT message, WPARAM wPara
case WM_PAINT:
ValidateRect(win_handle, NULL);
Event_RaiseVoid(&WindowEvents.Redraw);
Event_RaiseVoid(&WindowEvents.RedrawNeeded);
return 0;
case WM_WINDOWPOSCHANGED:

View File

@ -541,7 +541,7 @@ void Window_ProcessEvents(void) {
break;
case Expose:
if (e.xexpose.count == 0) Event_RaiseVoid(&WindowEvents.Redraw);
if (e.xexpose.count == 0) Event_RaiseVoid(&WindowEvents.RedrawNeeded);
break;
case LeaveNotify:

View File

@ -552,6 +552,8 @@ static void DoDrawFramebuffer(CGRect dirty) {
NSGraphicsContext* nsContext;
CGImageRef image;
CGRect rect;
Event_RaiseVoid(&WindowEvents.Redrawing);
// Unfortunately CGImageRef is immutable, so changing the
// underlying data doesn't change what shows when drawing.