Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CoC Access Violation: Click PDA stats, then close PDA #1766

Open
TIHan opened this issue Jan 10, 2025 · 0 comments
Open

CoC Access Violation: Click PDA stats, then close PDA #1766

TIHan opened this issue Jan 10, 2025 · 0 comments
Labels
Bug The issue in the run-time.

Comments

@TIHan
Copy link

TIHan commented Jan 10, 2025

Describe the bug
This was tested with CoC 1.4.22.
Player opens the PDA, clicks "Statistics", then closes PDA. Crashes to desktop.

To Reproduce
Steps to reproduce the behavior:

  1. Open the PDA
  2. Click "Statistics"
  3. Close PDA
  4. Crashes to desktop for access violation

Expected behavior
Not crash

AV occurs here:

    for (auto it = m_ChildWndList.begin(); m_ChildWndList.end() != it; ++it)
    {
        if (!(*it)->IsShown()) // <-- AV here
            continue;
        (*it)->Update();
    }

I believe CUIRankingsCoC allowed this issue to be exposed considering CoP wouldn't use this. Its Update method does call into LUA:

void CUIRankingsCoC::Update()
{
    //if (ParentHasMe())
    //    return;

    luabind::functor<bool> functorCanShow;
    if (GEnv.ScriptEngine->functor("pda.coc_rankings_can_show", functorCanShow))
    {
        if (functorCanShow(m_index))
        {
            if (!ParentHasMe())
            {
                luabind::functor<pcstr> functorSetName;
                if (GEnv.ScriptEngine->functor("pda.coc_rankings_set_name", functorSetName))
                    SetName(functorSetName(m_index));

I'm not an expert in this codebase, but one possible fix could be changing:

void CUIPdaWnd::UpdateRankingWnd()
{
    if (pUIRankingWnd)
        pUIRankingWnd->Update();
}

to

void CUIPdaWnd::UpdateRankingWnd()
{
    if (m_pActiveDialog == pUIRankingWnd && pUIRankingWnd)
        pUIRankingWnd->Update();
}

It appears to fix the issue, and the rankings still display.

Another thing to note here is that this method:

void CUIRankingWnd::Update()
{
    inherited::Update();
    if (Device.dwTimeGlobal - m_previous_time > m_delay)
    {
        m_previous_time = Device.dwTimeGlobal;
        update_info();
    }
}

Used to not call inherited::Update();:

void CUIRankingWnd::Update()
{
    if (Device.dwTimeGlobal - m_previous_time > m_delay)
    {
        m_previous_time = Device.dwTimeGlobal;
        update_info();
    }
}

This also fixes the issue. Anomaly xray also does the same, but I understand why it was added in OpenXRay to prevent the scrollbar from freezing.

@TIHan TIHan added the Bug The issue in the run-time. label Jan 10, 2025
@TIHan TIHan changed the title CoC Crash: Click PDA stats, then close PDA CoC Access Violation: Click PDA stats, then close PDA Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug The issue in the run-time.
Projects
Status: No status
Development

No branches or pull requests

1 participant