diff --git a/base/logging.h b/base/logging.h index e21ccf7ae2..2e0dbd3992 100644 --- a/base/logging.h +++ b/base/logging.h @@ -11,6 +11,7 @@ #undef Crash +#include // Logging #ifdef _WIN32 @@ -61,7 +62,17 @@ inline void Crash() { #else +#ifdef _WIN32 + +void __ods__(const char *p); + +#define ILOG(...) {char temp[512]; char *p = temp; p += sprintf(p, "I: %s:%i: ", __FILE__, __LINE__); p += sprintf(p, "I: " __VA_ARGS__); p += sprintf(p, "\n"); __ods__(temp);} +#define WLOG(...) {char temp[512]; char *p = temp; p += sprintf(p, "W: %s:%i: ", __FILE__, __LINE__); p += sprintf(p, "W: " __VA_ARGS__); p += sprintf(p, "\n"); __ods__(temp);} +#define ELOG(...) {char temp[512]; char *p = temp; p += sprintf(p, "E: %s:%i: ", __FILE__, __LINE__); p += sprintf(p, "E: " __VA_ARGS__); p += sprintf(p, "\n"); __ods__(temp);} +#define FLOG(...) {char temp[512]; char *p = temp; p += sprintf(p, "F: %s:%i: ", __FILE__, __LINE__); p += sprintf(p, "F: " __VA_ARGS__); p += sprintf(p, "\n"); __ods__(temp); Crash();} + // TODO: Win32 version using OutputDebugString +#else #include @@ -70,6 +81,7 @@ inline void Crash() { #define ELOG(...) {printf("E: %s:%i: ", __FILE__, __LINE__); printf("E: " __VA_ARGS__); printf("\n");} #define FLOG(...) {printf("F: %s:%i: ", __FILE__, __LINE__); printf("F: " __VA_ARGS__); printf("\n"); Crash();} +#endif #endif #undef CHECK diff --git a/base/stringutil.cpp b/base/stringutil.cpp index 69a4844f29..f229569671 100644 --- a/base/stringutil.cpp +++ b/base/stringutil.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -15,6 +16,10 @@ #define strcasecmp _stricmp #endif +void __ods__(const char *p) { + OutputDebugString(p); +} + unsigned int parseHex(const char *_szValue) { int Value = 0; diff --git a/math/geom2d.h b/math/geom2d.h index 4e0749746d..d72dd0ae29 100644 --- a/math/geom2d.h +++ b/math/geom2d.h @@ -24,7 +24,7 @@ struct Point { // Resolved bounds on screen after layout. struct Bounds { - Bounds() {} + Bounds() : x(0), y(0), w(0), h(0) {} Bounds(float x_, float y_, float w_, float h_) : x(x_), y(y_), w(w_), h(h_) {} bool Contains(float px, float py) const { diff --git a/ui/screen.cpp b/ui/screen.cpp index db81e59155..63774199e6 100644 --- a/ui/screen.cpp +++ b/ui/screen.cpp @@ -46,19 +46,22 @@ void ScreenManager::switchToNext() { } Layer newLayer = {nextScreen_, 0}; stack_.push_back(newLayer); - delete temp.screen; + if (temp.screen) { + ELOG("Deleting screen"); + delete temp.screen; + } nextScreen_ = 0; } void ScreenManager::touch(const TouchInput &touch) { - if (stack_.size()) { + if (!stack_.empty()) { stack_.back().screen->touch(touch); return; } } void ScreenManager::render() { - if (stack_.size()) { + if (!stack_.empty()) { switch (stack_.back().flags) { case LAYER_SIDEMENU: if (stack_.size() == 1) { @@ -88,20 +91,20 @@ void ScreenManager::render() { } void ScreenManager::sendMessage(const char *msg, const char *value) { - if (stack_.size()) + if (!stack_.empty()) stack_.back().screen->sendMessage(msg, value); } void ScreenManager::deviceLost() { - if (stack_.size()) + if (!stack_.empty()) stack_.back().screen->deviceLost(); // Dialogs too? Nah, they should only use the standard UI texture anyway. // TODO: Change this when it becomes necessary. } Screen *ScreenManager::topScreen() { - if (stack_.size()) + if (!stack_.empty()) return stack_.back().screen; else return 0; @@ -109,9 +112,7 @@ Screen *ScreenManager::topScreen() { void ScreenManager::shutdown() { for (auto x = stack_.begin(); x != stack_.end(); x++) - { delete x->screen; - } stack_.clear(); delete nextScreen_; nextScreen_ = 0; diff --git a/ui/screen.h b/ui/screen.h index 54376b2227..ca2983dae2 100644 --- a/ui/screen.h +++ b/ui/screen.h @@ -13,9 +13,10 @@ #pragma once -#include +#include #include "base/basictypes.h" +#include "base/logging.h" #include "base/display.h" #include "base/NativeApp.h" @@ -33,8 +34,10 @@ class UIContext; class Screen { public: - Screen(bool isUiScreen = false) : screenManager_(0), isUiScreen_(isUiScreen) { } - virtual ~Screen() {} + Screen() : screenManager_(0) { } + virtual ~Screen() { + screenManager_ = 0; + } virtual void update(InputState &input) = 0; virtual void render() {} @@ -50,7 +53,6 @@ public: private: ScreenManager *screenManager_; - bool isUiScreen_; DISALLOW_COPY_AND_ASSIGN(Screen); }; @@ -110,5 +112,5 @@ private: // Dialog stack. These are shown "on top" of base screens and the Android back button works as expected. // Used for options, in-game menus and other things you expect to be able to back out from onto something. - std::list stack_; + std::vector stack_; }; diff --git a/ui/ui_screen.cpp b/ui/ui_screen.cpp index 5a0389ed3a..b55f590c85 100644 --- a/ui/ui_screen.cpp +++ b/ui/ui_screen.cpp @@ -4,19 +4,16 @@ #include "ui/screen.h" UIScreen::UIScreen() - : Screen(), root_(0), recreateViews_(false) { + : Screen(), root_(0), recreateViews_(true) { } void UIScreen::update(InputState &input) { - if (!root_) { - CreateViews(); - } - if (recreateViews_) { delete root_; root_ = 0; CreateViews(); + recreateViews_ = false; } UpdateViewHierarchy(input, root_); diff --git a/ui/view.h b/ui/view.h index eef7e3958e..c371122f4c 100644 --- a/ui/view.h +++ b/ui/view.h @@ -12,6 +12,7 @@ #include #include +#include "base/logging.h" #include "base/functional.h" #include "base/mutex.h" #include "base/basictypes.h" @@ -227,7 +228,7 @@ View *GetFocusedView(); class View { public: - View(LayoutParams *layoutParams = 0) : layoutParams_(layoutParams), enabled_(true), visibility_(V_VISIBLE) { + View(LayoutParams *layoutParams = 0) : layoutParams_(layoutParams), enabled_(true), visibility_(V_VISIBLE), measuredWidth_(0), measuredHeight_(0) { if (!layoutParams) layoutParams_.reset(new LayoutParams()); } diff --git a/ui/viewgroup.cpp b/ui/viewgroup.cpp index eda02f61d0..00f314043c 100644 --- a/ui/viewgroup.cpp +++ b/ui/viewgroup.cpp @@ -28,8 +28,11 @@ void ApplyGravity(const Bounds outer, const Margins &margins, float w, float h, ViewGroup::~ViewGroup() { // Tear down the contents recursively. - for (auto iter = views_.begin(); iter != views_.end(); ++iter) - delete *iter; + for (size_t i = 0; i < views_.size(); i++) { + delete views_[i]; + views_[i] = 0; + } + views_.clear(); } void ViewGroup::Touch(const TouchInput &input) { @@ -530,12 +533,12 @@ void AnchorLayout::Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec v if (params->left >= 0 && params->right >= 0) { width = measuredWidth_ - params->left - params->right; - specW = MeasureSpec(EXACTLY, width); } if (params->top >= 0 && params->bottom >= 0) { height = measuredHeight_ - params->top - params->bottom; - specH = MeasureSpec(EXACTLY, height); } + specW = MeasureSpec(EXACTLY, width); + specH = MeasureSpec(EXACTLY, height); } views_[i]->Measure(dc, specW, specH);