Skip to content

Commit d843f7b

Browse files
committed
#235: Fix for crash on stream start
1 parent 2f1e3cb commit d843f7b

File tree

5 files changed

+16
-20
lines changed

5 files changed

+16
-20
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${EXTERN_PATH}/cmake")
4141
project(Moonlight)
4242
set(VERSION_MAJOR "1")
4343
set(VERSION_MINOR "3")
44-
set(VERSION_ALTER "1")
44+
set(VERSION_ALTER "2")
4545
set(VERSION_BUILD "1")
4646
set(PACKAGE_NAME "ru.xitrix.Moonlight")
4747
set(PSN_TITLE_ID "MNTL00000")

app/include/streaming_view.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class StreamingView : public brls::Box {
3939
private:
4040
Host host;
4141
AppInfo app;
42-
MoonlightSession* session;
42+
MoonlightSession* session = nullptr;
4343
LoadingOverlay* loader = nullptr;
4444
Box* keyboardHolder = nullptr;
4545
KeyboardView* keyboard = nullptr;

app/src/streaming/MoonlightSession.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@ void MoonlightSession::set_provider(
1717
m_provider = provider;
1818
}
1919

20-
MoonlightSession::MoonlightSession(const std::string& address, int app_id, bool is_sunshine) {
20+
MoonlightSession::MoonlightSession(const std::string& address, int app_id) {
2121
m_address = address;
2222
m_app_id = app_id;
23-
m_is_sunshine = is_sunshine;
2423
m_active_session = this;
2524

2625
m_video_decoder = m_provider->video_decoder();
@@ -95,7 +94,7 @@ void MoonlightSession::connection_terminated(int error_code) {
9594
m_active_session->m_is_terminated = true;
9695
}
9796
}
98-
});
97+
}, m_active_session->m_is_sunshine);
9998
return;
10099
}
101100

@@ -224,7 +223,9 @@ void MoonlightSession::audio_renderer_decode_and_play_sample(
224223

225224
// MARK: MoonlightSession
226225

227-
void MoonlightSession::start(ServerCallback<bool> callback) {
226+
void MoonlightSession::start(ServerCallback<bool> callback, bool is_sunshine) {
227+
m_is_sunshine = is_sunshine;
228+
228229
LiInitializeStreamConfiguration(&m_config);
229230

230231
int h = Settings::instance().resolution();

app/src/streaming/MoonlightSession.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ class MoonlightSession {
1414
static void
1515
set_provider(MoonlightSessionDecoderAndRenderProvider* provider);
1616

17-
MoonlightSession(const std::string& address, int app_id, bool is_sunshine);
17+
MoonlightSession(const std::string& address, int app_id);
1818
~MoonlightSession();
1919

20-
void start(ServerCallback<bool> callback);
20+
void start(ServerCallback<bool> callback, bool is_sunshine);
2121
void stop(int terminate_app);
2222

2323
void draw(NVGcontext* vg, int width, int height);
@@ -66,7 +66,7 @@ class MoonlightSession {
6666

6767
std::string m_address;
6868
int m_app_id;
69-
bool m_is_sunshine;
69+
bool m_is_sunshine = false;
7070
STREAM_CONFIGURATION m_config;
7171
CONNECTION_LISTENER_CALLBACKS m_connection_callbacks;
7272
DECODER_RENDERER_CALLBACKS m_video_callbacks;

app/src/streaming_view.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,21 +78,21 @@ StreamingView::StreamingView(const Host& host, const AppInfo& app) : host(host),
7878
keyboardHolder->setAlignItems(AlignItems::STRETCH);
7979
addView(keyboardHolder);
8080

81+
session = new MoonlightSession(host.address, app.app_id);
82+
8183
#ifdef PLATFORM_TVOS
8284
updatePreferredDisplayMode(true);
8385
#endif
8486

8587
ASYNC_RETAIN
8688
GameStreamClient::instance().connect(
87-
host.address, [ASYNC_TOKEN, host, app](GSResult<SERVER_DATA> result) {
89+
host.address, [ASYNC_TOKEN](GSResult<SERVER_DATA> result) {
8890
ASYNC_RELEASE
8991
if (!result.isSuccess()) {
9092
showError(result.error(), [this]() { terminate(false); });
9193
return;
9294
}
9395

94-
session = new MoonlightSession(host.address, app.app_id, result.value().isSunshine());
95-
9696
ASYNC_RETAIN
9797
session->start([ASYNC_TOKEN](GSResult<bool> result) {
9898
ASYNC_RELEASE
@@ -101,7 +101,7 @@ StreamingView::StreamingView(const Host& host, const AppInfo& app) : host(host),
101101
if (!result.isSuccess()) {
102102
showError(result.error(), [this]() { terminate(false); });
103103
}
104-
});
104+
}, result.value().isSunshine());
105105
});
106106

107107
MoonlightInputManager::instance().reloadButtonMappingLayout();
@@ -281,8 +281,6 @@ void StreamingView::onFocusLost() {
281281

282282
void StreamingView::draw(NVGcontext* vg, float x, float y, float width,
283283
float height, Style style, FrameContext* ctx) {
284-
if (!session) return;
285-
286284
if (session->is_terminated()) {
287285
terminate(false);
288286
return;
@@ -555,9 +553,6 @@ StreamingView::~StreamingView() {
555553
->getInputManager()
556554
->getKeyboardKeyStateChanged()
557555
->unsubscribe(keysSubscription);
558-
559-
if (session) {
560-
session->stop(false);
561-
delete session;
562-
}
556+
session->stop(false);
557+
delete session;
563558
}

0 commit comments

Comments
 (0)