Skip to content

Commit

Permalink
Fix crash when launching gamecube games with MIOS (from the Wii menu)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pokechu22 committed Jan 14, 2020
1 parent 9596fe7 commit d67c4f3
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions Source/Core/Core/IOS/DI/DI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,16 @@ std::optional<DI::DIResult> DI::StartImmediateTransfer(const IOCtlRequest& reque
return {};
}

static std::shared_ptr<DI> GetDevice()
{
auto ios = IOS::HLE::GetIOS();
if (!ios)
return nullptr;
auto di = ios->GetDeviceByName("/dev/di");
// di may be empty, but static_pointer_cast returns empty in that case
return std::static_pointer_cast<DI>(di);
}

void DI::InterruptFromDVDInterface(DVDInterface::DIInterruptType interrupt_type)
{
DIResult result;
Expand All @@ -544,10 +554,10 @@ void DI::InterruptFromDVDInterface(DVDInterface::DIInterruptType interrupt_type)
break;
}

auto di = IOS::HLE::GetIOS()->GetDeviceByName("/dev/di");
auto di = GetDevice();
if (di)
{
std::static_pointer_cast<DI>(di)->FinishDICommand(result);
di->FinishDICommand(result);
}
else
{
Expand All @@ -560,9 +570,9 @@ void DI::FinishDICommandCallback(u64 userdata, s64 ticksbehind)
{
const DIResult result = static_cast<DIResult>(userdata);

auto di = IOS::HLE::GetIOS()->GetDeviceByName("/dev/di");
auto di = GetDevice();
if (di)
std::static_pointer_cast<DI>(di)->FinishDICommand(result);
di->FinishDICommand(result);
else
PanicAlert("IOS::HLE::Device::DI: Received interrupt from DI when device wasn't registered!");
}
Expand Down Expand Up @@ -691,12 +701,12 @@ void DI::ChangePartition(const DiscIO::Partition partition)

DiscIO::Partition DI::GetCurrentPartition()
{
auto di = IOS::HLE::GetIOS()->GetDeviceByName("/dev/di");
auto di = GetDevice();
// Note that this function is called in Gamecube mode for UpdateRunningGameMetadata,
// so both cases are hit in normal circumstances.
if (!di)
return DiscIO::PARTITION_NONE;
return std::static_pointer_cast<DI>(di)->m_current_partition;
return di->m_current_partition;
}

void DI::InitializeIfFirstTime()
Expand Down

0 comments on commit d67c4f3

Please sign in to comment.