#How to diagnose a ObjectDisposedException?
1 messages · Page 1 of 1 (latest)
Is there a using statement somewhere in your code?
Aside from the references at the top I mean
Like a FileStream or something
yeah, heres what i got for those
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using ICSharpCode.SharpZipLib.Zip;
using uSource.Formats.Source.VTF;
using uSource.MathLib;
using UnityEngine;
should i check in all of those for anything calling dispose?
Yeah I'm talking about within the class itself. It's usually used in writing to a file stream or sometimes UI
static void LoadStaticProps()
{
Debug.Log("File Reader Obj: " + BSPFileReader);
Debug.Log("Base Stream: " + BSPFileReader.BaseStream);
Debug.Log("Lumps: " + BSP_Header.Lumps[35]);
BSPFileReader.BaseStream.Seek(BSP_Header.Lumps[35].FileOfs, SeekOrigin.Begin);
Int32 GameLumpCount = BSPFileReader.ReadInt32();
dgamelump_t[] BSP_GameLump = new dgamelump_t[GameLumpCount];
BSPFileReader.ReadArray(ref BSP_GameLump);
for (Int32 i = 0; i < GameLumpCount; i++)
{``` heres part of it, i dont wanna clog the chat up lol
So like if you create an object like FileStream or otherwise, call .Close() on it, then try to access it again
BSP? I'm not familiar. Can't find docs on it either.
In any case BSPFileReader or BSPFileReader.BaseStream must implement IDisposable - so it automatically disposes itself when it thinks you're done with it.
bsp is a map format for valve games, its a pita
You can try to put any code that uses it inside a using statement.
You can read through the example here for FileStream that shows how it's implemented - maybe try that for BaseStream? Just a guess. https://docs.microsoft.com/en-us/dotnet/api/system.io.filestream?view=net-5.0
In any case if you have docs for that code I'd suggest referencing the page for BaseStream to see if any examples are included
what confuses me even more is the stacktrace, it wont even give me the object name, only this:
ObjectDisposedException: Cannot access a disposed object.
Object name: 'Stream has been closed'.
i found the docs for basestream and read thru it but i still dont get why its not workin lol
Try calling BSPFileReader.BaseStream.Open(); before you use it for anything else. Shot in the dark.
Then .Close() when you're done with it
theres no .Open :(
i can send the github repo i got it from if u want
Might help.
Do you have something like uReader BSPFileReader = new uReader(new MemoryStream())?
Looks like that codebase uses a uReader class that extends the C# class BinaryReader which is where the BaseStream is coming from. But it requires a BinaryReader(MemoryStream) to access. Here's the docs on that: https://docs.microsoft.com/en-us/dotnet/api/system.io.binaryreader.basestream?view=net-5.0#System_IO_BinaryReader_BaseStream